main 5041353

pagescroll.go RawHistoryFolder

1package webutil
2
3import "fmt"
4
5// BuildPageScrollByJS returns one immediate JavaScript scroll step for the given
6// CSS-pixel delta. It resolves the initial target under the viewport center,
7// walks toward scrollable ancestors that can move in the requested direction,
8// and hands off to the document when a nested scroller reaches its boundary.
9// Cross-origin frame contents remain best-effort because elementFromPoint can
10// only return the accessible frame element from the top-level document.
11//
12// The app-level Vim Mode repeater owns held-key cadence; this helper performs
13// no requestAnimationFrame loop of its own.
14func BuildPageScrollByJS(dx, dy int) string {
15	return fmt.Sprintf(`(function(){
16var dx=%d,dy=%d,doc=document;
17function hasScrollableOverflow(value){
18  return value==='auto'||value==='scroll'||value==='overlay';
19}
20function canScroll(el){
21  if(!el)return false;
22  var style=window.getComputedStyle(el);
23  if(dy!==0){
24    var overflowY=style.overflowY||style.overflow;
25    var maxTop=el.scrollHeight-el.clientHeight;
26    if(hasScrollableOverflow(overflowY)){
27      if((dy<0&&el.scrollTop>0)||(dy>0&&el.scrollTop<maxTop))return true;
28    }
29  }
30  if(dx!==0){
31    var overflowX=style.overflowX||style.overflow;
32    var maxLeft=el.scrollWidth-el.clientWidth;
33    if(hasScrollableOverflow(overflowX)){
34      if((dx<0&&el.scrollLeft>0)||(dx>0&&el.scrollLeft<maxLeft))return true;
35    }
36  }
37  return false;
38}
39function scrollElement(el){
40  if(!el)return false;
41  var beforeLeft=el.scrollLeft,beforeTop=el.scrollTop;
42  try{
43    if(dx!==0)el.scrollLeft=beforeLeft+dx;
44    if(dy!==0)el.scrollTop=beforeTop+dy;
45  }catch(_){
46    return false;
47  }
48  return el.scrollLeft!==beforeLeft||el.scrollTop!==beforeTop;
49}
50try{
51  var node=typeof doc.elementFromPoint==='function'?
52    doc.elementFromPoint(window.innerWidth/2,window.innerHeight/2):null;
53  while(node&&node!==doc.body&&node!==doc.documentElement){
54    if(canScroll(node)&&scrollElement(node))return;
55    node=node.parentElement;
56  }
57  var scroller=doc.scrollingElement||doc.documentElement;
58  if(scroller&&canScroll(scroller)&&scrollElement(scroller))return;
59  if(typeof window.scrollBy==='function'){
60    window.scrollBy(dx,dy);
61    return;
62  }
63  if(typeof window.scrollTo==='function'){
64    window.scrollTo(window.scrollX+dx,window.scrollY+dy);
65  }
66}catch(e){}
67})()`, dx, dy)
68}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close