v0.36.0 1fb2421

keyboard.test.mjs RawHistoryFolder

1// Exercise the production key handler without a browser or dependencies.
2import assert from 'node:assert/strict';
3import { readFileSync } from 'node:fs';
4import { test } from 'node:test';
5import { runInNewContext } from 'node:vm';
6const source = readFileSync(new URL('../static/js/ermite.js', import.meta.url), 'utf8');
7function keyboard({ owner = true, off = false, typing = false, dialog = false } = {}) {
8  let handler;
9  const fired = [];
10  const timers = new Map();
11  let timerID = 0;
12  runInNewContext(source.slice(source.indexOf('  const single ='), source.indexOf('  // 2. A [data-fire]')), {
13    addEventListener: (_, fn) => { handler = fn; },
14    window: { ermiteKeys: { blocks: () => off } },
15    ermite: { fire: name => fired.push(name) },
16    $: selector => (owner && selector === '[data-inbox]') || (dialog && selector === 'dialog[open]'),
17    closeMenus: () => false,
18    clearTimeout: id => timers.delete(id),
19    setTimeout: fn => { timers.set(++timerID, fn); return timerID; },
20  });
21  return { fired, expireTimers() {
22    const callbacks = [...timers.values()];
23    timers.clear();
24    for (const callback of callbacks) callback();
25  }, press(key, shiftKey = false) {
26    handler({ key, shiftKey, target: { closest: selector => typing && selector.startsWith('input'), blur() {} }, preventDefault() {} });
27  } };
28}
29test('sections require g and have no old t alias', () => {
30  const k = keyboard();
31  for (const key of ['s', 't', 'c', 'r', 'm', 'i']) k.press(key);
32  assert.deepEqual(k.fired, []);
33  for (const key of ['s', 'f', 'c', 'b', 'm', 'i', 'r', 'a', 'h', 'g', 't']) { k.press('g'); k.press(key); }
34  assert.deepEqual(k.fired, ['s', 'f', 'c', 'b', 'm', 'i', 'r', 'a', 'gh', 'top']);
35});
36test('uppercase actions work with either reported casing and interrupt prefixes', () => {
37  for (const [key, action] of Object.entries({ G: 'bottom', M: 'merge', R: 'read', E: 'expandAll', I: 'inbox' })) {
38    for (const reported of [key, key.toLowerCase()]) {
39      const k = keyboard();
40      k.press('g'); k.press(reported, true); k.press(reported, true);
41      assert.deepEqual(k.fired, [action, action]);
42    }
43  }
44});
45test('uppercase actions respect preference, fields and dialogs', () => {
46  for (const options of [{ off: true }, { typing: true }, { dialog: true }]) {
47    const k = keyboard(options); k.press('g', true);
48    assert.deepEqual(k.fired, []);
49  }
50});
51
52test('Shift+I opens inbox while issues need the g i sequence', () => {
53  const k = keyboard();
54  k.press('I', true); k.press('i');
55  assert.deepEqual(k.fired, ['inbox']);
56  k.press('g'); k.press('i');
57  assert.deepEqual(k.fired, ['inbox', 'i']);
58});
59test('inbox shortcut respects preference, fields, dialogs, and owner target', () => {
60  for (const options of [{ off: true }, { typing: true }, { dialog: true }, { owner: false }]) {
61    const k = keyboard(options); k.press('I', true);
62    assert.deepEqual(k.fired, [], JSON.stringify(options));
63  }
64});
65test('shifted punctuation still opens help and the command palette', () => {
66  const k = keyboard();
67  k.press('?', true); k.press(':', true);
68  assert.deepEqual(k.fired, ['help', 'cmd']);
69});
70test('g prefix expires without scheduling real timers', () => {
71  const k = keyboard();
72  k.press('g'); k.expireTimers(); k.press('s');
73  assert.deepEqual(k.fired, []);
74  k.press('g'); k.press('s');
75  assert.deepEqual(k.fired, ['s']);
76});

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 4

Tags 45

↑↓ moveenter openesc close