1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package web
4
5import (
6 "strconv"
7 "strings"
8)
9
10// OverlayHelp is the keyboard map panel; the keys of the merge request page
11// show on that page only.
12templ OverlayHelp(mr bool) {
13 <dialog id="panel-help" class="panel modal" aria-label="Keyboard shortcuts" hx-on:keydown="event.key === 'Escape' && (event.preventDefault(), this.close())" hx-on:click="event.target === this && this.close()">
14 <div class="panel-head"><h2>Keyboard shortcuts</h2><button type="button" class="panel-x" aria-label="Close" hx-on:click="closest('dialog').close()"><kbd>esc</kbd> close</button></div>
15 <div class="keys-pref">
16 <label><input type="checkbox" id="keys-off" aria-describedby="keys-note" hx-on:change="ermite.setKeysOff(this.checked)"/> Turn off single-key shortcuts</label>
17 <p id="keys-note" class="dim">Single-key shortcuts are on. ctrl k and esc work whatever this says.</p>
18 </div>
19 <dl class="keys">
20 <div><dt><kbd>ctrl k</kbd> <kbd>:</kbd></dt><dd>go to a section, branch, tag, file or repository</dd></div>
21 <div><dt><kbd>?</kbd></dt><dd>this list</dd></div>
22 <div><dt><kbd>j</kbd> <kbd>k</kbd></dt><dd>move the row cursor down / up</dd></div>
23 <div><dt><kbd>enter</kbd></dt><dd>open the row under the cursor; on Files, a directory opens or closes in place</dd></div>
24 <div><dt><kbd>↑</kbd> <kbd>↓</kbd> <kbd>←</kbd> <kbd>→</kbd> <kbd>home</kbd> <kbd>end</kbd></dt><dd>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</dd></div>
25 <div><dt><kbd>l</kbd> <kbd>h</kbd></dt><dd>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</dd></div>
26 <div><dt><kbd>g g</kbd> <kbd>G</kbd></dt><dd>first / last row</dd></div>
27 <div><dt><kbd>/</kbd></dt><dd>filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)</dd></div>
28 <div><dt><kbd>b</kbd></dt><dd>{ "switch" } branch or tag</dd></div>
29 <div><dt><kbd>s</kbd> <kbd>t</kbd> <kbd>c</kbd> <kbd>r</kbd> <kbd>m</kbd> <kbd>i</kbd></dt><dd>tabs: summary, files, commits, branches & tags, merge requests, issues</dd></div>
30 <div><dt><kbd>g h</kbd></dt><dd>home</dd></div>
31 <div><dt><kbd>w</kbd></dt><dd>wide mode: use the whole width of the screen, or not (remembered)</dd></div>
32 <div><dt><kbd>y</kbd></dt><dd>copy a permalink pinned to the commit</dd></div>
33 <div><dt><kbd>d</kbd> <kbd>u</kbd> <kbd>x</kbd></dt><dd>diff: split / unified / collapse or expand all</dd></div>
34 <div><dt><kbd>e</kbd> <kbd>E</kbd></dt><dd>diff: the whole file in view / every file, with the lines the hunks hide</dd></div>
35 <div><dt><kbd>n</kbd></dt><dd>merge request: next note in the diff</dd></div>
36 if mr {
37 <div><dt><kbd>g f</kbd></dt><dd>merge request: the list of files (j k move, enter opens, esc back)</dd></div>
38 <div><dt><kbd>M</kbd></dt><dd>merge request: the merge menu; there 1–3 pick the mode, D deletes the branch, enter merges</dd></div>
39 <div><dt><kbd>R</kbd></dt><dd>merge request: mark the head read</dd></div>
40 }
41 <div><dt><kbd>esc</kbd></dt><dd>close a dialog, leave a field</dd></div>
42 </dl>
43 </dialog>
44}
45
46// OverlayRefs is the ref switcher. It exists only inside a repository.
47templ OverlayRefs(l Layout) {
48 if l.Ref != "" {
49 <dialog id="panel-refs" class="panel modal" aria-label="Switch ref" hx-on:keydown="event.key === 'Escape' && (event.preventDefault(), this.close())" hx-on:click="event.target === this && this.close()">
50 <div class="panel-head">
51 <label for="refs-filter" class="sr">filter branches and tags</label>
52 <input
53 id="refs-filter"
54 type="search"
55 placeholder="Switch branch or tag…"
56 autocomplete="off"
57 data-pick="#panel-refs li"
58 hx-on:input="ermite.filter(this)"
59 />
60 <button type="button" class="panel-x" aria-label="Close" hx-on:click="closest('dialog').close()"><kbd>esc</kbd></button>
61 </div>
62 <div class="panel-cols" data-picklist>
63 <section aria-label="Branches">
64 <h2>Branches <span class="count">{ itoa(len(l.Heads)) }</span></h2>
65 <ul>
66 for _, r := range l.Heads {
67 @refItem(r)
68 }
69 </ul>
70 </section>
71 <section aria-label="Tags">
72 <h2>Tags <span class="count">{ itoa(len(l.Tags)) }</span></h2>
73 <ul>
74 for _, r := range l.Tags {
75 @refItem(r)
76 }
77 </ul>
78 </section>
79 </div>
80 </dialog>
81 }
82}
83
84templ refItem(r RefItem) {
85 <li>
86 <a
87 href={ templ.SafeURL(r.Href) }
88 if r.Current {
89 aria-current="true"
90 }
91 >
92 <span class="mark" aria-hidden="true">
93 if r.Current {
94 ●
95 } else {
96
97 }
98 </span>{ r.Name }
99 </a>
100 </li>
101}
102
103// OverlayCmd is the ":" command line: one filterable list mixing sections,
104// refs and repos.
105templ OverlayCmd(items []CmdItem) {
106 <dialog id="panel-cmd" class="panel modal" aria-label="Go to" hx-on:close="ermiteFinder.paletteClose()" hx-on:keydown="event.key === 'Escape' && (event.preventDefault(), this.close())" hx-on:click="event.target === this && this.close()">
107 <div class="panel-head">
108 <label for="cmd-q" class="sr">go to</label>
109 <input
110 id="cmd-q"
111 type="search"
112 placeholder="Go to a section, branch, tag, file or repository…"
113 autocomplete="off"
114 spellcheck="false"
115 role="combobox"
116 aria-autocomplete="list"
117 aria-expanded="true"
118 aria-controls="cmd-list"
119 aria-activedescendant="cmd-o0"
120 hx-on:input="ermite.cmdFilter(this); ermiteFinder.palette(this)"
121 hx-on:keydown="ermite.cmdKey(event)"
122 />
123 <button type="button" class="panel-x" aria-label="Close" hx-on:click="closest('dialog').close()"><kbd>esc</kbd></button>
124 </div>
125 <ul id="cmd-list" class="cmd-list" role="listbox" aria-label="Targets">
126 for i, c := range items {
127 <li id={ "cmd-o" + itoa(i) } role="option" aria-selected={ strconv.FormatBool(i == 0) } data-k={ strings.ToLower(c.Kind + " " + c.Label) } data-cursor?={ i == 0 }><a href={ templ.SafeURL(c.Href) } tabindex="-1"><span class="lbl">{ c.Label }</span><span class="k">{ c.Kind }</span></a></li>
128 }
129 <li id={ "cmd-o" + itoa(len(items)) } role="option" aria-selected="false" data-k="action turn single-key shortcuts on off keyboard"><a href="#" data-fire="keys" tabindex="-1"><span class="lbl">turn single-key shortcuts off</span><span class="k">action</span></a></li>
130 </ul>
131 <p class="panel-foot"><span><kbd>↑</kbd><kbd>↓</kbd> move</span><span><kbd>enter</kbd> open</span><span><kbd>esc</kbd> close</span></p>
132 </dialog>
133}