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

Autoscroll sidebar

Summary:
If the ToC in sidebar is long then the active file can be under the fold when we highlight it.

This also saves some CPU cycles because it highlights only after scrolling of the main window and not in the elements.

Test Plan:
Scrolled on a long diff.
Scrolled the ToC.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3473
This commit is contained in:
vrana 2012-09-11 15:15:35 -07:00
parent 0e097a5867
commit 3df0cfa641

View file

@ -28,8 +28,11 @@ JX.behavior('phabricator-active-nav', function(config) {
link, link,
'phabricator-active-nav-focus', 'phabricator-active-nav-focus',
selected); selected);
if (selected && link.scrollIntoView) {
link.scrollIntoView(false);
}
} }
} };
/** /**
@ -72,15 +75,24 @@ JX.behavior('phabricator-active-nav', function(config) {
// If we get above the first marker, select it. // If we get above the first marker, select it.
selectnav(active && JX.Stratcom.getData(active).anchor); selectnav(active && JX.Stratcom.getData(active).anchor);
} };
var pending = null; var pending = null;
var onviewportchange = function(e) { var onviewportchange = function(e) {
pending && clearTimeout(pending); pending && clearTimeout(pending);
pending = setTimeout(updateposition, 100); pending = setTimeout(updateposition, 100);
} };
JX.Stratcom.listen('scroll', null, onviewportchange); var onscroll = function(e) {
if (e.getNode('tag:body')) {
// If we are inside <body> then it means we just scrolled some <textarea>
// or <div style="overflow: scroll;">. We are interested only in window.
return;
}
onviewportchange(e);
};
JX.Stratcom.listen('scroll', null, onscroll);
JX.Stratcom.listen('resize', null, onviewportchange); JX.Stratcom.listen('resize', null, onviewportchange);
JX.Stratcom.listen('hashchange', null, onviewportchange); JX.Stratcom.listen('hashchange', null, onviewportchange);
}); });