1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 00:32:42 +01:00

When stabilizing document scroll position for diffs, stick to anchors harder

Summary: Ref T12779. Try a little harder to get the autoscroll heuristic right, but also just stick to anchors if the URL has an anchor and the scroll position is near that anchor.

Test Plan:
  - Loaded an anchored diff at a bunch of window sizes, seemed pretty sticky.
  - Added `usleep(100000 * mt_rand(1, 15))` to `ChangesetViewController` to make changesets load slowly and in random order, reloaded a bunch of times while scrolling around, things appeared reasonable.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12779

Differential Revision: https://secure.phabricator.com/D18060
This commit is contained in:
epriestley 2017-06-01 10:41:57 -07:00
parent b9a4988df3
commit b66bf6af92
2 changed files with 38 additions and 17 deletions

View file

@ -13,7 +13,7 @@ return array(
'core.pkg.js' => '1475bd91',
'darkconsole.pkg.js' => '1f9a31bc',
'differential.pkg.css' => 'a2755617',
'differential.pkg.js' => '5bf658f0',
'differential.pkg.js' => '9cab3335',
'diffusion.pkg.css' => 'b93d9b8c',
'diffusion.pkg.js' => '84c8f8fd',
'favicon.ico' => '30672e08',
@ -391,7 +391,7 @@ return array(
'rsrc/js/application/dashboard/behavior-dashboard-move-panels.js' => '408bf173',
'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '453c5375',
'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => 'd4eecc63',
'rsrc/js/application/diff/DiffChangeset.js' => '1f6748ae',
'rsrc/js/application/diff/DiffChangeset.js' => 'aaaf4cb5',
'rsrc/js/application/diff/DiffChangesetList.js' => '85abc805',
'rsrc/js/application/diff/DiffInline.js' => '1d17130f',
'rsrc/js/application/diff/behavior-preview-link.js' => '051c7832',
@ -770,7 +770,7 @@ return array(
'phabricator-darklog' => 'c8e1ffe3',
'phabricator-darkmessage' => 'c48cccdd',
'phabricator-dashboard-css' => 'fe5b1869',
'phabricator-diff-changeset' => '1f6748ae',
'phabricator-diff-changeset' => 'aaaf4cb5',
'phabricator-diff-changeset-list' => '85abc805',
'phabricator-diff-inline' => '1d17130f',
'phabricator-drag-and-drop-file-upload' => '58dea2fa',
@ -1024,17 +1024,6 @@ return array(
'javelin-uri',
'javelin-routable',
),
'1f6748ae' => array(
'javelin-dom',
'javelin-util',
'javelin-stratcom',
'javelin-install',
'javelin-workflow',
'javelin-router',
'javelin-behavior-device',
'javelin-vector',
'phabricator-diff-inline',
),
'1f6794f6' => array(
'javelin-behavior',
'javelin-stratcom',
@ -1716,6 +1705,17 @@ return array(
'javelin-util',
'phabricator-prefab',
),
'aaaf4cb5' => array(
'javelin-dom',
'javelin-util',
'javelin-stratcom',
'javelin-install',
'javelin-workflow',
'javelin-router',
'javelin-behavior-device',
'javelin-vector',
'phabricator-diff-inline',
),
'ab2f381b' => array(
'javelin-request',
'javelin-behavior',

View file

@ -516,14 +516,35 @@ JX.install('DiffChangeset', {
var target_bot = (target_pos.y + target_dim.y);
// Detect if the changeset is entirely (or, at least, almost entirely)
// above us.
var above_screen = (target_bot < old_pos.y + 128);
// above us. The height here is roughly the height of the persistent
// banner.
var above_screen = (target_bot < old_pos.y + 64);
// If we have a URL anchor and are currently nearby, stick to it
// no matter what.
var on_target = null;
if (window.location.hash) {
try {
var anchor = JX.$(window.location.hash.replace('#', ''));
if (anchor) {
var anchor_pos = JX.$V(anchor);
if ((anchor_pos.y > old_pos.y) &&
(anchor_pos.y < old_pos.y + 96)) {
on_target = anchor;
}
}
} catch (ignored) {
// If we have a bogus anchor, just ignore it.
}
}
var frame = this._getContentFrame();
JX.DOM.setContent(frame, JX.$H(response.changeset));
if (this._stabilize) {
if (!near_top) {
if (on_target) {
JX.DOM.scrollToPosition(old_pos.x, JX.$V(on_target).y - 60);
} else if (!near_top) {
if (near_bot || above_screen) {
// Figure out how much taller the document got.
var delta = (JX.Vector.getDocument().y - old_dim.y);