Skip to content

Commit 3df0cfa

Browse files
author
vrana
committedSep 20, 2012
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
1 parent 0e097a5 commit 3df0cfa

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed
 

‎webroot/rsrc/js/application/core/behavior-active-nav.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ JX.behavior('phabricator-active-nav', function(config) {
2828
link,
2929
'phabricator-active-nav-focus',
3030
selected);
31+
if (selected && link.scrollIntoView) {
32+
link.scrollIntoView(false);
33+
}
3134
}
32-
}
35+
};
3336

3437

3538
/**
@@ -72,15 +75,24 @@ JX.behavior('phabricator-active-nav', function(config) {
7275

7376
// If we get above the first marker, select it.
7477
selectnav(active && JX.Stratcom.getData(active).anchor);
75-
}
78+
};
7679

7780
var pending = null;
7881
var onviewportchange = function(e) {
7982
pending && clearTimeout(pending);
8083
pending = setTimeout(updateposition, 100);
81-
}
84+
};
85+
86+
var onscroll = function(e) {
87+
if (e.getNode('tag:body')) {
88+
// If we are inside <body> then it means we just scrolled some <textarea>
89+
// or <div style="overflow: scroll;">. We are interested only in window.
90+
return;
91+
}
92+
onviewportchange(e);
93+
};
8294

83-
JX.Stratcom.listen('scroll', null, onviewportchange);
95+
JX.Stratcom.listen('scroll', null, onscroll);
8496
JX.Stratcom.listen('resize', null, onviewportchange);
8597
JX.Stratcom.listen('hashchange', null, onviewportchange);
8698
});

0 commit comments

Comments
 (0)
Failed to load comments.