pi-odd-worktree 2.1.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -319
- package/extensions/odd-worktree-tools.ts +4182 -2539
- package/lib/bash-activity.js +1166 -0
- package/lib/bash-design.js +684 -0
- package/lib/bash-destructive.js +559 -0
- package/lib/bash-frame.js +205 -0
- package/lib/card-content.js +23 -0
- package/lib/card-style.js +175 -0
- package/lib/checkout-facts.js +30 -70
- package/lib/codegraph-card-preview.js +628 -0
- package/lib/codegraph-card.js +515 -0
- package/lib/codegraph-compaction.js +76 -0
- package/lib/codegraph-daemon.js +246 -0
- package/lib/codegraph-edit-sync.js +182 -0
- package/lib/codegraph-guard-target.js +337 -0
- package/lib/codegraph-guard.js +211 -0
- package/lib/codegraph-index.js +1020 -0
- package/lib/codegraph-lock.js +607 -0
- package/lib/codegraph-mcp-config.js +134 -0
- package/lib/codegraph-mcp.js +123 -0
- package/lib/codegraph-paths.js +69 -0
- package/lib/codegraph-prompt/explore.md +11 -0
- package/lib/codegraph-prompt/fix.md +6 -0
- package/lib/codegraph-prompt/generic.md +8 -0
- package/lib/codegraph-prompt/judge.md +9 -0
- package/lib/codegraph-prompt/orchestrator.md +17 -0
- package/lib/codegraph-prompt/verify.md +10 -0
- package/lib/codegraph-prompt/worker.md +7 -0
- package/lib/codegraph-role.js +55 -0
- package/lib/codegraph-rules.js +146 -0
- package/lib/codegraph-session.js +303 -383
- package/lib/codegraph-warmup.js +139 -0
- package/lib/file-card-markdown.js +141 -0
- package/lib/file-card-resolver.js +245 -0
- package/lib/file-card.js +659 -0
- package/lib/files-index.js +387 -0
- package/lib/files-insert.js +81 -0
- package/lib/files-orders.js +326 -0
- package/lib/files-picker-view.js +1421 -0
- package/lib/files-preview.js +338 -0
- package/lib/files-scope-detail.js +171 -0
- package/lib/files-scope-view.js +507 -0
- package/lib/gh-issues.js +323 -15
- package/lib/issue-preview.js +26 -7
- package/lib/issues-bash-mutation.js +206 -0
- package/lib/issues-cache-store.js +261 -0
- package/lib/issues-section.js +710 -0
- package/lib/issues-view.js +649 -52
- package/lib/odd-prompt/odd-worktrees.md +21 -0
- package/lib/odd-worktrees-prompt.js +10 -28
- package/lib/related-issues-cache.js +210 -0
- package/lib/shell-card.js +825 -0
- package/lib/skill-odd-card.js +183 -0
- package/lib/tui-paint.js +4 -5
- package/lib/warp-create-panel.js +538 -250
- package/lib/warp-create-picker.js +56 -9
- package/lib/warp-delete-confirm.js +19 -28
- package/lib/warp-selector-view.js +160 -82
- package/lib/which-command.js +90 -0
- package/lib/worktree-card.js +267 -897
- package/lib/worktree-cards.js +383 -0
- package/lib/worktree-create.js +287 -0
- package/lib/worktree-git.js +3 -3
- package/lib/worktree-guard.js +548 -0
- package/lib/worktree-hooks.js +421 -712
- package/lib/worktree-list.js +120 -0
- package/lib/worktree-registry.js +162 -879
- package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
- package/lib/worktree-setup-runner.js +376 -0
- package/lib/worktree-setup.js +140 -0
- package/lib/worktree-warp-busy.js +462 -85
- package/lib/worktree-warp-sessions.js +1 -2
- package/package.json +2 -2
- package/tools/bash-activity.test.js +1420 -0
- package/tools/bash-design.test.js +1093 -0
- package/tools/bash-destructive.test.js +139 -0
- package/tools/card-content.test.js +44 -0
- package/tools/card-style.test.js +298 -0
- package/tools/codegraph-card-preview.test.js +254 -0
- package/tools/codegraph-card.test.js +1080 -0
- package/tools/codegraph-compaction.test.js +378 -0
- package/tools/codegraph-daemon.test.js +248 -0
- package/tools/codegraph-edit-sync.test.js +295 -0
- package/tools/codegraph-guard-target.test.js +174 -0
- package/tools/codegraph-guard.test.js +238 -0
- package/tools/codegraph-index.test.js +1948 -0
- package/tools/codegraph-lock.test.js +932 -0
- package/tools/codegraph-mcp-config.test.js +181 -0
- package/tools/codegraph-mcp.test.js +194 -0
- package/tools/codegraph-paths.test.js +44 -0
- package/tools/codegraph-role.test.js +30 -0
- package/tools/codegraph-rules.test.js +250 -0
- package/tools/codegraph-session.test.js +660 -391
- package/tools/codegraph-warmup.test.js +316 -0
- package/tools/commands.test.js +510 -31
- package/tools/file-card-markdown.test.js +188 -0
- package/tools/file-card.test.js +1289 -0
- package/tools/files-bridge.test.js +575 -0
- package/tools/files-command.test.js +613 -0
- package/tools/files-index.test.js +473 -0
- package/tools/files-insert.test.js +139 -0
- package/tools/files-orders.test.js +597 -0
- package/tools/files-picker-view.test.js +1889 -0
- package/tools/files-preview.test.js +452 -0
- package/tools/files-scope-detail.test.js +264 -0
- package/tools/files-scope-view.test.js +614 -0
- package/tools/fixtures/card-codegraph-outputs.js +110 -0
- package/tools/fixtures/codegraph-cli-stub.js +16 -0
- package/tools/fixtures/codegraph-init-process.js +28 -0
- package/tools/fixtures/codegraph-lock-worker.js +117 -0
- package/tools/fixtures/daemon-fake.js +98 -0
- package/tools/fixtures/daemon-mcp-server.js +39 -0
- package/tools/fixtures/daemon-warmup-worker.js +12 -0
- package/tools/fixtures/load-extension.js +136 -3
- package/tools/gh-issues-feedback.test.js +31 -7
- package/tools/gh-issues.test.js +417 -1
- package/tools/issue-preview.test.js +44 -7
- package/tools/issues-bash-mutation.test.js +101 -0
- package/tools/issues-cache-store.test.js +222 -0
- package/tools/issues-command.test.js +1517 -67
- package/tools/issues-open-guard.test.js +1096 -0
- package/tools/issues-section.test.js +4235 -0
- package/tools/issues-seed-query-regression.test.js +67 -0
- package/tools/issues-view.test.js +1489 -60
- package/tools/odd-worktrees-prompt.test.js +98 -65
- package/tools/package-surface.test.js +431 -36
- package/tools/related-issues-cache.test.js +324 -0
- package/tools/shell-card.test.js +834 -0
- package/tools/skill-odd-card.test.js +200 -0
- package/tools/t5-session-identity.test.js +44 -22
- package/tools/warp-busy-guard.test.js +2565 -309
- package/tools/warp-create-panel.test.js +499 -74
- package/tools/warp-create-picker.test.js +101 -5
- package/tools/warp-delete-confirm.test.js +49 -15
- package/tools/warp-empty-session.test.js +0 -1
- package/tools/warp-fallback-regression.test.js +533 -0
- package/tools/warp-selector-view.test.js +460 -196
- package/tools/which-command.test.js +126 -0
- package/tools/worktree-card.test.js +551 -0
- package/tools/worktree-cards.test.js +845 -0
- package/tools/worktree-changes.test.js +4 -5
- package/tools/worktree-create.test.js +489 -0
- package/tools/worktree-guard.test.js +823 -0
- package/tools/worktree-hooks.test.js +905 -0
- package/tools/worktree-list.test.js +170 -0
- package/tools/worktree-registry.test.js +89 -230
- package/tools/worktree-remove-async.test.js +318 -0
- package/tools/worktree-setup-runner.test.js +276 -0
- package/tools/worktree-setup.test.js +140 -0
- package/tools/worktree-tools.test.js +419 -199
- package/lib/codegraph-commands.js +0 -165
- package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
- package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
- package/lib/worktree-model-result.js +0 -291
- package/tools/codegraph-commands.test.js +0 -371
- package/tools/herdr-free-create.test.js +0 -161
- package/tools/worktree-close-herdr-async.test.js +0 -204
- package/tools/worktree-odd-migration.test.js +0 -224
- package/tools/worktree-registry-cache.test.js +0 -163
- package/tools/worktree-registry-odd.test.js +0 -231
|
@@ -0,0 +1,1889 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// T6 (files-picker S1-S6, S14, S15): `lib/files-picker-view.js` — the `/files`
|
|
3
|
+
// panel, as a composition of T1's listing, T4's rows and T5's preview.
|
|
4
|
+
//
|
|
5
|
+
// Contract under test, as observable output only: the card frame, the `›` search
|
|
6
|
+
// row, the two panes and their widths, the rows and their badges/ages/tones, the
|
|
7
|
+
// footer's one option per key with the active order, the keys of S4, the mouse
|
|
8
|
+
// routes of S5, and the four ways the panel settles (insert, editor, close, and
|
|
9
|
+
// the listing that never arrives). The listing and the preview are injected, so
|
|
10
|
+
// the whole suite runs without a repository, a theme or a highlighter.
|
|
11
|
+
//
|
|
12
|
+
// T9 adds the round L9 rules to the same surface: the info row with the counts
|
|
13
|
+
// and the order at the list's edge (S22), the folder order named `tree` (S23), the
|
|
14
|
+
// full-height preview geometry with the rule under the body (S25) and the Tab mark
|
|
15
|
+
// bar in a theme role (S26). Its "a cursor only rests on file rows" rule (S24) is
|
|
16
|
+
// superseded by S38's every-row cursor, and the tree round's "shift+space folds the
|
|
17
|
+
// other groups" (S34) by S39's one toggle over every group. Whatever a rule change
|
|
18
|
+
// retargeted says so where it is asserted.
|
|
19
|
+
|
|
20
|
+
const { test, describe } = require('node:test');
|
|
21
|
+
const assert = require('node:assert/strict');
|
|
22
|
+
|
|
23
|
+
const { createFilesPickerView } = require('../lib/files-picker-view.js');
|
|
24
|
+
|
|
25
|
+
// Optional real dependency: the host's pi-tui package, which owns the ONE matcher
|
|
26
|
+
// this view's keys are written against. CI installs no dependencies, so resolve it
|
|
27
|
+
// once here and SKIP only the test that genuinely needs it; every other case runs
|
|
28
|
+
// through the fake helpers above or the view's own spelled fallback.
|
|
29
|
+
let TUI_AVAILABLE = false;
|
|
30
|
+
try {
|
|
31
|
+
require.resolve('@earendil-works/pi-tui');
|
|
32
|
+
TUI_AVAILABLE = true;
|
|
33
|
+
} catch {
|
|
34
|
+
TUI_AVAILABLE = false;
|
|
35
|
+
}
|
|
36
|
+
if (!TUI_AVAILABLE) {
|
|
37
|
+
console.error(
|
|
38
|
+
'files-picker-view: SKIPPING the real-matcher shift+space test (no @earendil-works/pi-tui found)',
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const NOW = 1_700_000_000_000;
|
|
43
|
+
const MINUTE = 60_000;
|
|
44
|
+
const HOUR = 3_600_000;
|
|
45
|
+
const WIDTH = 120;
|
|
46
|
+
// The terminal rows the view is offered; the card takes its share of them (S15).
|
|
47
|
+
const ROWS_AVAILABLE = 20;
|
|
48
|
+
const CARD_HEIGHT = 17;
|
|
49
|
+
// 0-based row of the first body row: the top rule, the search row, the info row.
|
|
50
|
+
const BODY_TOP = 3;
|
|
51
|
+
// S25: the row the blank separator row used to be is the INFO row — the counts,
|
|
52
|
+
// the fill and the order — and the preview's box top border rides it. A
|
|
53
|
+
// full-width rule then closes the body under both columns on its own row, so the
|
|
54
|
+
// chrome is the top rule, the search row, the info row, that rule, the footer and
|
|
55
|
+
// the bottom rule: six rows, and the body keeps CARD_HEIGHT - 6.
|
|
56
|
+
const INFO_ROW = 2;
|
|
57
|
+
const SEARCH_ROW = 1;
|
|
58
|
+
const BODY_ROWS = CARD_HEIGHT - 6;
|
|
59
|
+
const RULE_ROW = BODY_TOP + BODY_ROWS;
|
|
60
|
+
const CURSOR_MARK = '\u25b8';
|
|
61
|
+
const SELECTION_MARK = '\u258f';
|
|
62
|
+
const LIST_MAX_WIDTH = 64;
|
|
63
|
+
|
|
64
|
+
const strip = (value) => String(value).replace(/\x1b\[[0-9;]*m/g, '');
|
|
65
|
+
|
|
66
|
+
// ANSI-aware stand-ins for the host TUI helpers, injected exactly as the view
|
|
67
|
+
// takes them: nothing here is imported statically.
|
|
68
|
+
const helpers = {
|
|
69
|
+
visibleWidth: (text) => [...strip(text)].length,
|
|
70
|
+
truncateToWidth: (text, width, ellipsis = '\u2026') => {
|
|
71
|
+
const chars = [...String(text)];
|
|
72
|
+
return chars.length > width
|
|
73
|
+
? `${chars.slice(0, Math.max(0, width - 1)).join('')}${ellipsis}`
|
|
74
|
+
: String(text);
|
|
75
|
+
},
|
|
76
|
+
wrapTextWithAnsi: (text, width) => {
|
|
77
|
+
const chars = [...String(text)];
|
|
78
|
+
const rows = [];
|
|
79
|
+
for (let at = 0; at < chars.length; at += Math.max(1, width)) {
|
|
80
|
+
rows.push(chars.slice(at, at + Math.max(1, width)).join(''));
|
|
81
|
+
}
|
|
82
|
+
return rows.length > 0 ? rows : [''];
|
|
83
|
+
},
|
|
84
|
+
matchesKey: (data, name) => data === name,
|
|
85
|
+
isKeyRelease: (data) => data === 'release',
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const plainTheme = {
|
|
89
|
+
fg: (_role, text) => String(text),
|
|
90
|
+
bold: (text) => String(text),
|
|
91
|
+
bg: (_role, text) => String(text),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// A theme that records which role painted each string and paints every role with
|
|
95
|
+
// its own SGR code, so a rendered line can be read for the ROLE behind a token.
|
|
96
|
+
const ROLE_SGR = { accent: 96, customMessageLabel: 33, muted: 90, dim: 2, border: 34, text: 39, error: 91 };
|
|
97
|
+
|
|
98
|
+
function recordingTheme() {
|
|
99
|
+
const calls = [];
|
|
100
|
+
const code = (role) => ROLE_SGR[role] ?? 95;
|
|
101
|
+
return {
|
|
102
|
+
calls,
|
|
103
|
+
fg(role, text) {
|
|
104
|
+
calls.push({ role, text: String(text) });
|
|
105
|
+
return `\x1b[${code(role)}m${text}\x1b[0m`;
|
|
106
|
+
},
|
|
107
|
+
bold(text) {
|
|
108
|
+
calls.push({ role: 'bold', text: String(text) });
|
|
109
|
+
return `\x1b[1m${text}\x1b[22m`;
|
|
110
|
+
},
|
|
111
|
+
bg(role, text) {
|
|
112
|
+
calls.push({ role: `bg:${role}`, text: String(text) });
|
|
113
|
+
return `\x1b[48;5;${code(role)}m${text}\x1b[0m`;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const SCOPE = { root: '/home/dev/repo-worktrees/files-picker', kind: 'worktree', label: 'files-picker' };
|
|
119
|
+
|
|
120
|
+
// The listing T1 answers: changed first and newest first, then clean by path.
|
|
121
|
+
const FILES = [
|
|
122
|
+
{ path: 'brand-new.ts', state: 'new', mtimeMs: NOW - 5_000, age: '5s' },
|
|
123
|
+
{ path: 'src/cursor.ts', state: 'updated', mtimeMs: NOW - 2 * HOUR, age: '2h' },
|
|
124
|
+
{ path: 'README.md', state: 'clean' },
|
|
125
|
+
{ path: 'src/lib/util.ts', state: 'clean' },
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
// A listing with two top-level folders, one nested folder and a root file, so the
|
|
129
|
+
// S30/S39 fold rules have something to open and something to leave closed.
|
|
130
|
+
const NESTED = [
|
|
131
|
+
{ path: 'src/web/test.ts', state: 'clean' },
|
|
132
|
+
{ path: 'src/index.ts', state: 'clean' },
|
|
133
|
+
{ path: 'web/app.ts', state: 'clean' },
|
|
134
|
+
{ path: 'README.md', state: 'clean' },
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
function preview(lines, truncated = false) {
|
|
138
|
+
return { kind: 'text', lines, truncated };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
142
|
+
|
|
143
|
+
function mount(options = {}) {
|
|
144
|
+
const calls = { insert: [], open: [], close: 0, render: 0 };
|
|
145
|
+
let renders = 0;
|
|
146
|
+
const view = createFilesPickerView({
|
|
147
|
+
theme: options.theme === undefined ? plainTheme : options.theme,
|
|
148
|
+
helpers: options.helpers === undefined ? helpers : options.helpers,
|
|
149
|
+
rowsAvailable: options.rowsAvailable === undefined ? ROWS_AVAILABLE : options.rowsAvailable,
|
|
150
|
+
scope: options.scope === undefined ? SCOPE : options.scope,
|
|
151
|
+
cwd: '/home/dev/repo/files-picker',
|
|
152
|
+
loadEntries: options.loadEntries === undefined
|
|
153
|
+
? async () => ({ ok: true, entries: options.entries === undefined ? FILES : options.entries })
|
|
154
|
+
: options.loadEntries,
|
|
155
|
+
loadPreview: options.loadPreview === undefined
|
|
156
|
+
? async (path) => preview([`preview of ${path}`, 'second line'])
|
|
157
|
+
: options.loadPreview,
|
|
158
|
+
highlight: options.highlight,
|
|
159
|
+
languageForPath: options.languageForPath,
|
|
160
|
+
now: options.now === undefined ? NOW : options.now,
|
|
161
|
+
onInsert: (paths) => {
|
|
162
|
+
calls.insert.push(paths);
|
|
163
|
+
if (typeof options.onInsert === 'function') options.onInsert(paths);
|
|
164
|
+
},
|
|
165
|
+
onOpen: (path) => {
|
|
166
|
+
calls.open.push(path);
|
|
167
|
+
if (typeof options.onOpen === 'function') options.onOpen(path);
|
|
168
|
+
},
|
|
169
|
+
onClose: () => {
|
|
170
|
+
calls.close += 1;
|
|
171
|
+
if (typeof options.onClose === 'function') options.onClose();
|
|
172
|
+
},
|
|
173
|
+
requestRender: () => {
|
|
174
|
+
renders += 1;
|
|
175
|
+
calls.render = renders;
|
|
176
|
+
if (typeof options.requestRender === 'function') options.requestRender();
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
return { view, calls, renderCount: () => renders };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// A mounted panel that already paints its listing and its first preview.
|
|
183
|
+
async function open(options = {}) {
|
|
184
|
+
const mounted = mount(options);
|
|
185
|
+
const width = options.width === undefined ? WIDTH : options.width;
|
|
186
|
+
mounted.view.render(width);
|
|
187
|
+
await tick();
|
|
188
|
+
mounted.view.render(width);
|
|
189
|
+
await tick();
|
|
190
|
+
mounted.view.render(width);
|
|
191
|
+
return mounted;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function rowsOf(view, width = WIDTH) {
|
|
195
|
+
return view.render(width).map(strip);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function rowOf(rows, text) {
|
|
199
|
+
const index = rows.findIndex((row) => row.includes(text));
|
|
200
|
+
assert.ok(index >= 0, `missing ${JSON.stringify(text)} in the frame:\n${rows.join('\n')}`);
|
|
201
|
+
return index;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// The left pane cell of the row painting `text`, without the card border.
|
|
205
|
+
function listCell(rows, text) {
|
|
206
|
+
return (rows[rowOf(rows, text)].split(' │ ')[0] || '').replace(/^│ /, '');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function footerOf(rows) {
|
|
210
|
+
return rows[rows.length - 2].replace(/^│ /, '').replace(/ +│$/, '');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function bodyText(rows) {
|
|
214
|
+
return rows.slice(BODY_TOP, rows.length - 2).join('\n');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Every body row's list cell, trailing blanks trimmed: the marker column, the
|
|
218
|
+
// indent and the label, as the reader sees them (S29's chevrons read from here).
|
|
219
|
+
function bodyCells(rows, width = WIDTH) {
|
|
220
|
+
return rows.slice(BODY_TOP, RULE_ROW).map((row) => listLine(row, width).trimEnd());
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// The group rows only: the cursor mark or a blank, then the chevron (S29).
|
|
224
|
+
function groupCells(rows, width = WIDTH) {
|
|
225
|
+
return bodyCells(rows, width).filter((cell) => /^[\u25b8 ][\u25be\u25b8] /.test(cell));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function selectedRow(rows) {
|
|
229
|
+
// The cursor mark owns the FIRST cell of the marker column; a collapsed group's
|
|
230
|
+
// chevron paints the second one, so the glyph alone no longer identifies the
|
|
231
|
+
// focused row (S29).
|
|
232
|
+
const line = rows.find((row) => row.slice(2).startsWith(CURSOR_MARK));
|
|
233
|
+
assert.ok(line, 'a selected row must be painted');
|
|
234
|
+
return line;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// The list pane's painted width, measured from the frame a click is routed through.
|
|
238
|
+
function listWidth(rows) {
|
|
239
|
+
return rows[BODY_TOP].indexOf(' │ ') - 2;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function previewStart(rows) {
|
|
243
|
+
return rows[BODY_TOP].indexOf(' │ ') + 3;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// The two pane widths the card computes for one width (S15, S25), read here so a
|
|
247
|
+
// cell can be sliced even on a row that carries no painted pane rule.
|
|
248
|
+
function paneWidths(width = WIDTH) {
|
|
249
|
+
const inner = width - 4;
|
|
250
|
+
const list = Math.max(1, Math.min(LIST_MAX_WIDTH, Math.floor(inner * 0.45)));
|
|
251
|
+
return { inner, list, preview: Math.max(0, inner - list - 3) };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// The list column's cell of one row, without the card border.
|
|
255
|
+
function listLine(row, width = WIDTH) {
|
|
256
|
+
return [...row].slice(2, 2 + paneWidths(width).list).join('');
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// The preview pane's cell of the row the box top rides (S25).
|
|
260
|
+
function previewTop(rows) {
|
|
261
|
+
const start = previewStart(rows);
|
|
262
|
+
return [...rows[INFO_ROW]].slice(start, [...rows[INFO_ROW]].length - 2).join('');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// The list pane's cell of the info row: the counts, the fill and the order (S22).
|
|
266
|
+
function infoCell(rows, width = WIDTH) {
|
|
267
|
+
return listLine(rows[INFO_ROW], width);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// The selected row's list cell, without the three-cell marker column.
|
|
271
|
+
function selectedLabel(rows, width = WIDTH) {
|
|
272
|
+
return listLine(selectedRow(rows), width).slice(3).trim();
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// The selected row's first label token: a file name, or a group row's name.
|
|
276
|
+
function selectedName(rows, width = WIDTH) {
|
|
277
|
+
return selectedLabel(rows, width).split(/\s+/)[0];
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// The SGR sequence in force at the FIRST `glyph` of a painted row, or '' when the
|
|
281
|
+
// cell is unstyled: a theme role always leaves one behind (S26).
|
|
282
|
+
function sgrAt(line, glyph) {
|
|
283
|
+
const at = line.indexOf(glyph);
|
|
284
|
+
if (at < 0) return '';
|
|
285
|
+
const found = [...line.slice(0, at).matchAll(/\x1b\[[0-9;]*m/g)];
|
|
286
|
+
return found.length === 0 ? '' : found[found.length - 1][0];
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function previewPane(rows, offset) {
|
|
290
|
+
const row = [...rows[BODY_TOP + offset]];
|
|
291
|
+
const start = previewStart(rows);
|
|
292
|
+
return row.slice(start, row.length - 2).join('');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// A mouse event local to the last painted card.
|
|
296
|
+
function mouse(overrides = {}) {
|
|
297
|
+
return {
|
|
298
|
+
type: 'click',
|
|
299
|
+
button: 'left',
|
|
300
|
+
x: 3,
|
|
301
|
+
y: BODY_TOP,
|
|
302
|
+
width: WIDTH,
|
|
303
|
+
height: CARD_HEIGHT,
|
|
304
|
+
...overrides,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
describe('the card chrome (S1, S15)', () => {
|
|
309
|
+
test('the frame is exact at two widths, with Files at the left and esc at the right', async () => {
|
|
310
|
+
const { view } = await open({ scope: undefined });
|
|
311
|
+
for (const width of [120, 80]) {
|
|
312
|
+
const rows = rowsOf(view, width);
|
|
313
|
+
assert.equal(rows.length, CARD_HEIGHT);
|
|
314
|
+
for (const row of rows) assert.equal(helpers.visibleWidth(row), width, `no row is ragged at ${width}`);
|
|
315
|
+
assert.ok(rows[0].startsWith('╭─ ✿ Files'), rows[0]);
|
|
316
|
+
assert.ok(rows[0].endsWith('esc ╮'), rows[0]);
|
|
317
|
+
assert.ok(rows[rows.length - 1].startsWith('╰─'));
|
|
318
|
+
assert.ok(rows[rows.length - 1].endsWith('╯'));
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
test('the listing path rides the title at the left, and esc keeps the far corner alone (S37)', async () => {
|
|
323
|
+
const { view } = await open();
|
|
324
|
+
// The whole row, as painted: the panel's name, ` · `, the path, the filling
|
|
325
|
+
// rule, and `esc` alone at the right corner. The 63-column fill is
|
|
326
|
+
// 120 - 47 (title + path) - 5 (chrome) - 5 (the ` esc ` cell).
|
|
327
|
+
assert.equal(
|
|
328
|
+
rowsOf(view)[0],
|
|
329
|
+
`╭─ ✿ Files · ${SCOPE.root} ${'─'.repeat(63)} esc ╮`,
|
|
330
|
+
'the path rides the panel title, never the right corner',
|
|
331
|
+
);
|
|
332
|
+
// The path is nowhere near the corner: what follows it is only the rule and the
|
|
333
|
+
// `esc` cell.
|
|
334
|
+
const afterPath = rowsOf(view)[0].slice(3 + `✿ Files · ${SCOPE.root}`.length);
|
|
335
|
+
assert.match(afterPath, /^ ─+ esc ╮$/, `only the rule and esc follow the path: ${JSON.stringify(afterPath)}`);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test('a narrow card elides the path from its left, so the tail that identifies the checkout survives (S37)', async () => {
|
|
339
|
+
const { view } = await open();
|
|
340
|
+
// 50 columns: the title keeps 30 for the path (50 - 7 for `✿ Files` - 3 for
|
|
341
|
+
// ` · ` - 5 for the chrome - 5 for ` esc `), which keeps the last 29 characters.
|
|
342
|
+
assert.equal(
|
|
343
|
+
view.render(50).map(strip)[0],
|
|
344
|
+
'╭─ ✿ Files · …v/repo-worktrees/files-picker esc ╮',
|
|
345
|
+
);
|
|
346
|
+
// 40 columns leaves 20 for the path: the tail still names the checkout.
|
|
347
|
+
assert.equal(
|
|
348
|
+
view.render(40).map(strip)[0],
|
|
349
|
+
'╭─ ✿ Files · …ktrees/files-picker esc ╮',
|
|
350
|
+
);
|
|
351
|
+
for (const width of [50, 40]) {
|
|
352
|
+
const row = view.render(width).map(strip)[0];
|
|
353
|
+
assert.equal(helpers.visibleWidth(row), width);
|
|
354
|
+
assert.ok(row.startsWith('╭─ ✿ Files · …'), `the path still follows the title at ${width}: ${row}`);
|
|
355
|
+
assert.ok(!row.includes('/home'), 'the head of the path gives way, never its tail');
|
|
356
|
+
assert.ok(row.includes(SCOPE.root.slice(-10)), `the identifying tail survives at ${width}: ${row}`);
|
|
357
|
+
assert.ok(row.endsWith('esc ╮'), 'esc keeps the far right corner');
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test('the card uses the rows it is offered, grows with them and never exceeds them', async () => {
|
|
362
|
+
let previous = 0;
|
|
363
|
+
for (const rowsAvailable of [20, 40, 60]) {
|
|
364
|
+
const { view } = await open({ rowsAvailable });
|
|
365
|
+
const rows = rowsOf(view);
|
|
366
|
+
for (const row of rows) assert.equal(helpers.visibleWidth(row), WIDTH);
|
|
367
|
+
assert.ok(rows.length > previous, `the card grows with ${rowsAvailable} rows`);
|
|
368
|
+
assert.ok(rows.length <= rowsAvailable, `the card never exceeds the ${rowsAvailable} rows`);
|
|
369
|
+
const painted = footerOf(rows);
|
|
370
|
+
assert.ok(painted.includes('esc') && painted.includes('enter'), `the footer is painted: ${painted}`);
|
|
371
|
+
previous = rows.length;
|
|
372
|
+
}
|
|
373
|
+
assert.equal(mount({ rowsAvailable: () => 40 }).view.render(WIDTH).length, 34);
|
|
374
|
+
assert.deepEqual(mount({ rowsAvailable: () => { throw new Error('no rows'); } }).view.render(WIDTH), []);
|
|
375
|
+
const absent = createFilesPickerView({ loadEntries: async () => ({ ok: true, entries: [] }) });
|
|
376
|
+
assert.deepEqual(absent.render(WIDTH), []);
|
|
377
|
+
assert.deepEqual(absent.render(0), []);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test('a terminal too narrow or too short paints one fitted line', async () => {
|
|
381
|
+
const { view } = await open({ rowsAvailable: 12 });
|
|
382
|
+
const narrow = view.render(10).map(strip);
|
|
383
|
+
assert.equal(narrow.length, 1);
|
|
384
|
+
assert.equal(helpers.visibleWidth(narrow[0]), 10);
|
|
385
|
+
assert.ok(narrow[0].startsWith('Files'));
|
|
386
|
+
assert.equal(mount({ rowsAvailable: 5 }).view.render(WIDTH).length, 1);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test('the smallest card keeps the frame, the search row and the footer, and drops the path first', async () => {
|
|
390
|
+
const { view } = await open({ rowsAvailable: 8 });
|
|
391
|
+
for (const width of [20, 24]) {
|
|
392
|
+
const rows = rowsOf(view, width);
|
|
393
|
+
assert.equal(rows.length, 6, 'the smallest card still paints every chrome row');
|
|
394
|
+
for (const row of rows) assert.equal(helpers.visibleWidth(row), width, `no row is ragged at ${width}`);
|
|
395
|
+
assert.ok(rows[0].startsWith('╭─ ✿ Files'), rows[0]);
|
|
396
|
+
assert.ok(rows[0].endsWith('esc ╮'), 'too narrow a card drops the path, never the title or esc');
|
|
397
|
+
assert.ok(rows[SEARCH_ROW].startsWith('│ › '), `the search row keeps its prompt: ${rows[SEARCH_ROW]}`);
|
|
398
|
+
// The rule changed with S25: the search row is now the list pane's width, so
|
|
399
|
+
// the narrowest card elides the placeholder word instead of the query row
|
|
400
|
+
// crossing the whole card.
|
|
401
|
+
assert.ok(infoCell(rows).includes('/'), `the smallest card still counts its files: ${infoCell(rows)}`);
|
|
402
|
+
assert.ok(footerOf(rows).includes('esc'), `the smallest card still names esc: ${footerOf(rows)}`);
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
test('the search row sits under the title, narrowed to the list pane (S25)', async () => {
|
|
407
|
+
const { view } = await open();
|
|
408
|
+
const rows = rowsOf(view);
|
|
409
|
+
assert.ok(rows[SEARCH_ROW].startsWith('│ › Search'), rows[SEARCH_ROW]);
|
|
410
|
+
assert.ok(rows[SEARCH_ROW].endsWith('│'));
|
|
411
|
+
// The search row is the list pane's width; the preview column beside it is
|
|
412
|
+
// blank, and the info row sits directly under it in the list column.
|
|
413
|
+
assert.equal((rows[SEARCH_ROW].match(/│/g) || []).length, 2, 'no pane rule crosses the search row');
|
|
414
|
+
assert.equal(rows[SEARCH_ROW].slice(2 + listWidth(rows), -2).trim(), '', 'the search row never spills into the preview');
|
|
415
|
+
assert.match(infoCell(rows), /^4\/4 \(0\) ─+ files$/, 'the info row sits under the search row');
|
|
416
|
+
assert.ok(rows[BODY_TOP].includes('brand-new.ts'), 'the list starts under the info row');
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
test('the search row never paints past the list pane, however long the query', async () => {
|
|
420
|
+
const { view } = await open();
|
|
421
|
+
const long = 'a-very-long-query-that-cannot-fit-in-the-list-pane';
|
|
422
|
+
for (const character of long) view.handleInput(character);
|
|
423
|
+
// At 40 columns the list pane is 16 cells: the query is elided there, never
|
|
424
|
+
// painted over the preview's column.
|
|
425
|
+
const narrow = rowsOf(view, 40);
|
|
426
|
+
assert.ok(narrow[SEARCH_ROW].includes('a-very-long'), narrow[SEARCH_ROW]);
|
|
427
|
+
assert.ok(narrow[SEARCH_ROW].includes('\u2026'), 'the query is elided at the pane edge');
|
|
428
|
+
assert.equal(narrow[SEARCH_ROW].slice(2 + paneWidths(40).list, -2).trim(), '');
|
|
429
|
+
for (const row of narrow) assert.equal(helpers.visibleWidth(row), 40);
|
|
430
|
+
const wide = rowsOf(view);
|
|
431
|
+
assert.ok(wide[SEARCH_ROW].includes(long), 'the full query fits the wider list pane');
|
|
432
|
+
assert.equal(wide[SEARCH_ROW].slice(2 + paneWidths().list, -2).trim(), '');
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
test('the body is two panes split by one rule, the list at 45% and capped at 64 columns', async () => {
|
|
436
|
+
const { view } = await open();
|
|
437
|
+
for (const [width, expected] of [[72, 30], [120, 52], [200, LIST_MAX_WIDTH]]) {
|
|
438
|
+
const rows = rowsOf(view, width);
|
|
439
|
+
for (const row of rows) assert.equal(helpers.visibleWidth(row), width, `no row is ragged at ${width}`);
|
|
440
|
+
assert.equal(listWidth(rows), expected, `the list takes its share at ${width}`);
|
|
441
|
+
const preview = [...rows[BODY_TOP]].length - 2 - previewStart(rows);
|
|
442
|
+
assert.equal(preview, width - 4 - expected - 3, `the preview keeps the rest at ${width}`);
|
|
443
|
+
assert.equal((rows[BODY_TOP].match(/│/g) || []).length >= 3, true, 'the panes are ruled apart');
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
describe('the footer (S4)', () => {
|
|
449
|
+
test('names one option per key and never advertises the compatible alternates', async () => {
|
|
450
|
+
const { view } = await open();
|
|
451
|
+
// S32: the flat order paints no group, so its footer names no fold key.
|
|
452
|
+
const flat = footerOf(rowsOf(view, 200));
|
|
453
|
+
for (const token of [
|
|
454
|
+
'↑/↓ move', 'tab select', 'ctrl+j/k scroll', 'ctrl+o order',
|
|
455
|
+
'ctrl+u clear', 'ctrl+e edit', 'enter insert', 'esc close',
|
|
456
|
+
]) {
|
|
457
|
+
assert.ok(flat.includes(token), `the footer names ${token}: ${flat}`);
|
|
458
|
+
}
|
|
459
|
+
for (const hidden of ['space', 'fold', 'ctrl+k', 'ctrl+shift', 'ctrl+c', 'esc/', 'home', 'end', 'enter/']) {
|
|
460
|
+
assert.ok(!flat.includes(hidden), `the flat footer never names ${hidden}: ${flat}`);
|
|
461
|
+
}
|
|
462
|
+
assert.ok(flat.endsWith('esc close'), `the flat footer ends at its last key, not at an order name: ${flat}`);
|
|
463
|
+
|
|
464
|
+
// S32, S40: the trees earn the two fold keys, in the same one-key style, and the
|
|
465
|
+
// shift+space one names the action it would perform.
|
|
466
|
+
for (const [order, action] of [['tree', 'shift+space expand all'], ['ext', 'shift+space collapse all']]) {
|
|
467
|
+
view.handleInput('ctrl+o');
|
|
468
|
+
const tree = footerOf(rowsOf(view, 200));
|
|
469
|
+
for (const token of ['space fold', action, 'ctrl+u clear', 'ctrl+e edit', 'enter insert', 'esc close']) {
|
|
470
|
+
assert.ok(tree.includes(token), `the ${order} footer names ${token}: ${tree}`);
|
|
471
|
+
}
|
|
472
|
+
assert.ok(tree.endsWith('esc close'), `the ${order} footer ends at its last key: ${tree}`);
|
|
473
|
+
assert.match(infoCell(rowsOf(view, 200), 200), new RegExp(` ${order}$`), `the info row names the ${order} order`);
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
test('paints each key in the key role and its description muted', async () => {
|
|
478
|
+
const theme = recordingTheme();
|
|
479
|
+
const { view } = await open({ theme });
|
|
480
|
+
view.render(200);
|
|
481
|
+
for (const [keyText, rest] of [['↑/↓', ' move'], ['ctrl+o', ' order'], ['esc', ' close']]) {
|
|
482
|
+
assert.ok(theme.calls.some((call) => call.role === 'accent' && call.text === keyText), keyText);
|
|
483
|
+
assert.ok(theme.calls.some((call) => call.role === 'muted' && call.text === rest), rest);
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
test('a narrow footer compacts onto the one row instead of wrapping', async () => {
|
|
488
|
+
const { view } = await open();
|
|
489
|
+
// At 80 columns the substrate keeps every key and drops its word, so one
|
|
490
|
+
// option per key still fits on one row. The flat order names no fold key (S32).
|
|
491
|
+
const compact = rowsOf(view, 80);
|
|
492
|
+
const footer = footerOf(compact);
|
|
493
|
+
for (const keyName of ['↑/↓', 'tab', 'ctrl+o', 'ctrl+u', 'ctrl+e', 'enter', 'esc']) {
|
|
494
|
+
assert.ok(footer.includes(keyName), `the footer keeps ${keyName}: ${footer}`);
|
|
495
|
+
}
|
|
496
|
+
assert.ok(!footer.includes(' move'), `the words give way first: ${footer}`);
|
|
497
|
+
assert.equal(compact.length, CARD_HEIGHT, 'the footer never adds a row');
|
|
498
|
+
for (const row of compact) assert.equal(helpers.visibleWidth(row), 80);
|
|
499
|
+
|
|
500
|
+
// In a tree the two fold keys join the compact legend (S32, S40): at the default
|
|
501
|
+
// width both are named, and at 80 the longer legend still fits one row.
|
|
502
|
+
view.handleInput('ctrl+o');
|
|
503
|
+
const roomy = footerOf(rowsOf(view));
|
|
504
|
+
for (const keyName of ['space', 'shift+space']) {
|
|
505
|
+
assert.ok(roomy.includes(keyName), `the tree footer names ${keyName}: ${roomy}`);
|
|
506
|
+
}
|
|
507
|
+
const treeRows = rowsOf(view, 80);
|
|
508
|
+
assert.ok(footerOf(treeRows).includes('space'), `the tree keeps its fold key: ${footerOf(treeRows)}`);
|
|
509
|
+
assert.equal(treeRows.length, CARD_HEIGHT, 'the longer legend never adds a row');
|
|
510
|
+
for (const row of treeRows) assert.equal(helpers.visibleWidth(row), 80);
|
|
511
|
+
|
|
512
|
+
// Narrower still: only the highest-priority keys survive, on the same row.
|
|
513
|
+
const tiny = rowsOf(view, 40);
|
|
514
|
+
const dropped = footerOf(tiny);
|
|
515
|
+
assert.ok(dropped.includes('esc'), `esc never gives way: ${dropped}`);
|
|
516
|
+
assert.ok(!dropped.includes('ctrl+j/k') && !dropped.includes('ctrl+u'), `the least important keys give way: ${dropped}`);
|
|
517
|
+
assert.equal(tiny.length, CARD_HEIGHT);
|
|
518
|
+
for (const row of tiny) assert.equal(helpers.visibleWidth(row), 40);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
test('the active order is named once, on the info row, and never again in the footer', async () => {
|
|
522
|
+
const { view } = await open();
|
|
523
|
+
for (const order of ['files', 'tree', 'ext', 'files']) {
|
|
524
|
+
const rows = rowsOf(view);
|
|
525
|
+
assert.match(infoCell(rows), new RegExp(` ${order}$`), `S33/S23: the info row names the ${order} order`);
|
|
526
|
+
const footer = footerOf(rows);
|
|
527
|
+
assert.match(footer, /esc( close)?$/, `the footer is the legend alone and ends at its last key: ${footer}`);
|
|
528
|
+
assert.doesNotMatch(footer, / {2,}(files|tree|ext)$/, `the footer does not repeat the ${order} order at its right edge: ${footer}`);
|
|
529
|
+
view.handleInput('ctrl+o');
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
describe('the list rows (S6, S15)', () => {
|
|
535
|
+
test('changed files paint their letter and age at the right; a clean row paints neither', async () => {
|
|
536
|
+
const { view } = await open();
|
|
537
|
+
const rows = rowsOf(view);
|
|
538
|
+
assert.match(listCell(rows, 'brand-new.ts'), /^▸\s+brand-new\.ts +U 5s$/);
|
|
539
|
+
assert.match(listCell(rows, 'cursor.ts'), /^\s+cursor\.ts src +M 2h$/);
|
|
540
|
+
assert.match(listCell(rows, 'README.md'), /^\s+README\.md *$/, 'a clean row has no badge and no age');
|
|
541
|
+
assert.ok(!bodyText(rows).includes('new '), 'the word badge is never painted');
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
test('a changed row without an age keeps its letter and falls back to its mtime once', async () => {
|
|
545
|
+
const entries = [
|
|
546
|
+
{ path: 'brand-new.ts', state: 'new' },
|
|
547
|
+
{ path: 'edited.ts', state: 'updated', mtimeMs: NOW - 3 * HOUR },
|
|
548
|
+
{ path: 'plain.ts', state: 'clean' },
|
|
549
|
+
];
|
|
550
|
+
const { view } = await open({ entries, now: NOW });
|
|
551
|
+
assert.match(listCell(rowsOf(view), 'brand-new.ts'), /U$/);
|
|
552
|
+
assert.match(listCell(rowsOf(view), 'edited.ts'), /M 3h$/, 'the mtime and the injected clock decide the age');
|
|
553
|
+
// The clock is read once when the panel opens, so no repaint can move the age.
|
|
554
|
+
view.handleInput('tab');
|
|
555
|
+
view.handleInput('tab');
|
|
556
|
+
assert.match(listCell(rowsOf(view), 'edited.ts'), /M 3h$/, 'ages are computed once and never refreshed live');
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
test('a name paints in the row role and its trailing directory in dim, never at the root', async () => {
|
|
560
|
+
const theme = recordingTheme();
|
|
561
|
+
const { view } = await open({ theme });
|
|
562
|
+
const rows = rowsOf(view);
|
|
563
|
+
view.render(WIDTH);
|
|
564
|
+
assert.ok(theme.calls.some((call) => call.role === 'text' && call.text === 'util.ts'), 'the name is the plain text role');
|
|
565
|
+
assert.ok(theme.calls.some((call) => call.role === 'dim' && call.text === 'src/lib'), 'the directory is dim');
|
|
566
|
+
assert.ok(!theme.calls.some((call) => call.role === 'dim' && call.text.includes('README')), 'a root file has no directory');
|
|
567
|
+
assert.equal(listCell(rows, 'README.md').trim(), 'README.md', 'a root file paints its name alone');
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
test('the tree order paints no trailing directory, because the tree already places it', async () => {
|
|
571
|
+
const { view } = await open();
|
|
572
|
+
// S30: focus a file inside the tree first, so the change opens its folders.
|
|
573
|
+
for (let step = 0; step < 3; step += 1) view.handleInput('down'); // src/lib/util.ts
|
|
574
|
+
view.handleInput('ctrl+o');
|
|
575
|
+
const rows = rowsOf(view);
|
|
576
|
+
assert.ok(!listCell(rows, 'util.ts').includes('src/lib'), listCell(rows, 'util.ts'));
|
|
577
|
+
const painted = rows
|
|
578
|
+
.slice(BODY_TOP, rows.length - 2)
|
|
579
|
+
.map((row) => (row.split(' │ ')[0] || '').replace(/^│ /, '').trim());
|
|
580
|
+
// S29: a group row also carries its chevron, so the cell ends with the name.
|
|
581
|
+
assert.ok(painted.some((cell) => cell.endsWith('src')), 'the folder group paints its own row');
|
|
582
|
+
assert.ok(painted.some((cell) => cell.endsWith('lib')), 'the nested folder paints its own row');
|
|
583
|
+
assert.ok(
|
|
584
|
+
painted.findIndex((cell) => cell.endsWith('src')) < painted.findIndex((cell) => cell.endsWith('util.ts')),
|
|
585
|
+
'the tree places the file under its folder',
|
|
586
|
+
);
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
test('a narrow pane costs the name before the badge', async () => {
|
|
590
|
+
const entries = [
|
|
591
|
+
{ path: 'a-very-long-file-name-that-will-not-fit.ts', state: 'new', mtimeMs: NOW - 5 * MINUTE, age: '5m' },
|
|
592
|
+
{ path: 'b.ts', state: 'clean' },
|
|
593
|
+
];
|
|
594
|
+
const { view } = await open({ entries });
|
|
595
|
+
const rows = rowsOf(view, 40);
|
|
596
|
+
const changed = listCell(rows, 'U 5m');
|
|
597
|
+
assert.ok(changed.includes('U 5m'), changed);
|
|
598
|
+
assert.ok(changed.includes('\u2026'), `the name is elided: ${changed}`);
|
|
599
|
+
assert.ok(!changed.includes('a-very-long-file-name-that-will-not-fit.ts'));
|
|
600
|
+
for (const row of rows) assert.equal(helpers.visibleWidth(row), 40);
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
test('a long list keeps the selection visible with more indicators', async () => {
|
|
604
|
+
const entries = Array.from({ length: 30 }, (_, index) => ({
|
|
605
|
+
path: `file-${String(index).padStart(2, '0')}.ts`,
|
|
606
|
+
state: 'clean',
|
|
607
|
+
}));
|
|
608
|
+
const { view } = await open({ entries });
|
|
609
|
+
for (let step = 0; step < 20; step += 1) view.handleInput('down');
|
|
610
|
+
const rows = rowsOf(view);
|
|
611
|
+
assert.match(selectedRow(rows), /file-20\.ts/);
|
|
612
|
+
assert.match(bodyText(rows), /↑ \d+ more/);
|
|
613
|
+
assert.match(bodyText(rows), /↓ \d+ more/);
|
|
614
|
+
for (const row of rows) assert.equal(helpers.visibleWidth(row), WIDTH);
|
|
615
|
+
});
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
describe('search is always active (S2, S3)', () => {
|
|
619
|
+
test('typing filters immediately, paints the query and resets the highlight to the first file', async () => {
|
|
620
|
+
const entries = [
|
|
621
|
+
{ path: 'alpha.ts', state: 'clean' },
|
|
622
|
+
{ path: 'alpine.ts', state: 'clean' },
|
|
623
|
+
{ path: 'src/beta.ts', state: 'clean' },
|
|
624
|
+
];
|
|
625
|
+
const { view, calls } = await open({ entries });
|
|
626
|
+
view.handleInput('down');
|
|
627
|
+
assert.match(selectedRow(rowsOf(view)), /alpine\.ts/);
|
|
628
|
+
for (const character of 'al') view.handleInput(character);
|
|
629
|
+
const rows = rowsOf(view);
|
|
630
|
+
assert.ok(rows[SEARCH_ROW].startsWith('│ › al'), rows[SEARCH_ROW]);
|
|
631
|
+
assert.ok(!rows[SEARCH_ROW].includes('Search'), 'the placeholder gives way to the query');
|
|
632
|
+
assert.ok(bodyText(rows).includes('alpha.ts'));
|
|
633
|
+
assert.ok(bodyText(rows).includes('alpine.ts'));
|
|
634
|
+
assert.ok(!bodyText(rows).includes('beta.ts'), 'a non-matching file disappears immediately');
|
|
635
|
+
assert.match(selectedRow(rows), /alpha\.ts/, 'the highlight returns to the first match');
|
|
636
|
+
assert.deepEqual(calls.insert, []);
|
|
637
|
+
assert.deepEqual(calls.open, []);
|
|
638
|
+
assert.equal(calls.close, 0, 'typing never closes the panel');
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
test('a query matching nothing paints an explicit empty-state line', async () => {
|
|
642
|
+
const { view } = await open();
|
|
643
|
+
for (const character of 'zzz') view.handleInput(character);
|
|
644
|
+
const rows = rowsOf(view);
|
|
645
|
+
assert.ok(bodyText(rows).includes('No files match "zzz"'), bodyText(rows));
|
|
646
|
+
assert.equal(rows.length, CARD_HEIGHT, 'the card keeps its chrome');
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
test('backspace edits one character, ctrl+u clears, and a paste is never a keystroke', async () => {
|
|
650
|
+
const { view } = await open();
|
|
651
|
+
for (const character of 'brand') view.handleInput(character);
|
|
652
|
+
assert.ok(bodyText(rowsOf(view)).includes('brand-new.ts'));
|
|
653
|
+
view.handleInput('x');
|
|
654
|
+
assert.ok(bodyText(rowsOf(view)).includes('No files match "brandx"'));
|
|
655
|
+
view.handleInput('backspace');
|
|
656
|
+
assert.ok(bodyText(rowsOf(view)).includes('brand-new.ts'), 'backspace edits the query');
|
|
657
|
+
view.handleInput('ctrl+u');
|
|
658
|
+
assert.ok(bodyText(rowsOf(view)).includes('README.md'), 'ctrl+u clears the query');
|
|
659
|
+
view.handleInput('brand');
|
|
660
|
+
assert.ok(bodyText(rowsOf(view)).includes('README.md'), 'a multi-character paste never lands in the query');
|
|
661
|
+
});
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
describe('the listing load (S13)', () => {
|
|
665
|
+
test('the first frame paints the pending state and never blocks, then the listing appears', async () => {
|
|
666
|
+
const mounted = mount();
|
|
667
|
+
mounted.view.render(WIDTH);
|
|
668
|
+
assert.ok(bodyText(rowsOf(mounted.view)).includes('Loading files'), 'the first frame is honest about the read');
|
|
669
|
+
assert.equal(mounted.renderCount(), 0, 'the load blocks nothing and paints nothing by itself');
|
|
670
|
+
await tick();
|
|
671
|
+
mounted.view.render(WIDTH);
|
|
672
|
+
assert.ok(bodyText(rowsOf(mounted.view)).includes('brand-new.ts'));
|
|
673
|
+
assert.equal(mounted.renderCount(), 1, 'the landed listing asks for one repaint');
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
test('a failed listing paints its own message in the error role and no loading row', async () => {
|
|
677
|
+
const theme = recordingTheme();
|
|
678
|
+
const { view } = await open({
|
|
679
|
+
theme,
|
|
680
|
+
loadEntries: async () => ({ ok: false, message: 'Not a Git repository: /nowhere.' }),
|
|
681
|
+
});
|
|
682
|
+
const body = bodyText(rowsOf(view));
|
|
683
|
+
assert.ok(body.includes('Not a Git repository: /nowhere.'), body);
|
|
684
|
+
assert.ok(!body.includes('Loading files'));
|
|
685
|
+
assert.ok(theme.calls.some((call) => call.role === 'error' && call.text.includes('Not a Git repository')));
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
test('an empty repository says so, and a rejecting reader keeps its own sentence', async () => {
|
|
689
|
+
const empty = await open({ entries: [] });
|
|
690
|
+
assert.ok(bodyText(rowsOf(empty.view)).includes('No files in this repository.'));
|
|
691
|
+
|
|
692
|
+
const rejected = await open({ loadEntries: async () => { throw new Error('no listing'); } });
|
|
693
|
+
assert.ok(bodyText(rowsOf(rejected.view)).includes('Cannot list repository files: no listing.'));
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
test('the selection and the hover survive a preview landing and an ordinary repaint', async () => {
|
|
697
|
+
let release;
|
|
698
|
+
const gate = new Promise((resolve) => { release = resolve; });
|
|
699
|
+
const theme = recordingTheme();
|
|
700
|
+
const mounted = mount({ theme, loadPreview: () => gate });
|
|
701
|
+
mounted.view.render(WIDTH);
|
|
702
|
+
await tick();
|
|
703
|
+
mounted.view.render(WIDTH);
|
|
704
|
+
mounted.view.handleInput('down');
|
|
705
|
+
mounted.view.handleInput('down');
|
|
706
|
+
let rows = rowsOf(mounted.view);
|
|
707
|
+
assert.match(selectedRow(rows), /README\.md/);
|
|
708
|
+
mounted.view.handleMouse(mouse({ type: 'move', button: 'none', y: rowOf(rows, 'cursor.ts') }));
|
|
709
|
+
rows = rowsOf(mounted.view);
|
|
710
|
+
assert.ok(mounted.view.render(WIDTH)[rowOf(rows, 'cursor.ts')].includes('\x1b[96m'), 'the hovered row is painted');
|
|
711
|
+
|
|
712
|
+
release(preview(['landed']));
|
|
713
|
+
await tick();
|
|
714
|
+
rows = rowsOf(mounted.view);
|
|
715
|
+
assert.match(selectedRow(rows), /README\.md/, 'the selection survives the repaint');
|
|
716
|
+
assert.ok(mounted.view.render(WIDTH)[rowOf(rows, 'cursor.ts')].includes('\x1b[96m'), 'so does the hover');
|
|
717
|
+
assert.ok(bodyText(rows).includes('landed'), 'the preview landed');
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
describe('keys (S4)', () => {
|
|
722
|
+
test('the arrows move the selection and clamp at both ends', async () => {
|
|
723
|
+
const { view, calls } = await open();
|
|
724
|
+
assert.match(selectedRow(rowsOf(view)), /brand-new\.ts/);
|
|
725
|
+
view.handleInput('down');
|
|
726
|
+
assert.match(selectedRow(rowsOf(view)), /cursor\.ts/);
|
|
727
|
+
view.handleInput('up');
|
|
728
|
+
assert.match(selectedRow(rowsOf(view)), /brand-new\.ts/);
|
|
729
|
+
view.handleInput('up');
|
|
730
|
+
assert.match(selectedRow(rowsOf(view)), /brand-new\.ts/, 'the selection clamps at the top');
|
|
731
|
+
for (let step = 0; step < 6; step += 1) view.handleInput('down');
|
|
732
|
+
assert.match(selectedRow(rowsOf(view)), /util\.ts/, 'the selection clamps at the bottom');
|
|
733
|
+
assert.deepEqual(calls.insert, []);
|
|
734
|
+
assert.equal(calls.close, 0);
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
test('ctrl+j/k and the ctrl+shift forms scroll the preview and never move the selection', async () => {
|
|
738
|
+
const long = Array.from({ length: 60 }, (_, index) => `line ${index}`);
|
|
739
|
+
const { view, calls } = await open({ loadPreview: async () => preview(long) });
|
|
740
|
+
assert.match(previewPane(rowsOf(view), 0), /^│ 1 line 0/, 'the box starts at line 1');
|
|
741
|
+
view.handleInput('ctrl+j');
|
|
742
|
+
assert.match(previewPane(rowsOf(view), 0), /^│ 2 line 1/, 'ctrl+j scrolls one row');
|
|
743
|
+
assert.match(selectedRow(rowsOf(view)), /brand-new\.ts/, 'a scroll never moves the selection');
|
|
744
|
+
view.handleInput('ctrl+k');
|
|
745
|
+
assert.match(previewPane(rowsOf(view), 0), /^│ 1 line 0/);
|
|
746
|
+
view.handleInput('ctrl+shift+j');
|
|
747
|
+
assert.match(previewPane(rowsOf(view), 0), /^│ 2 line 1/, 'the ctrl+shift form scrolls too');
|
|
748
|
+
view.handleInput('ctrl+shift+k');
|
|
749
|
+
assert.match(previewPane(rowsOf(view), 0), /^│ 1 line 0/);
|
|
750
|
+
for (let step = 0; step < 200; step += 1) view.handleInput('ctrl+j');
|
|
751
|
+
const clamped = rowsOf(view);
|
|
752
|
+
assert.match(previewPane(clamped, 0), /^│51 line 50/, 'scrolling stops at the last full page');
|
|
753
|
+
assert.ok(bodyText(clamped).includes('line 59'), 'the last line is painted on that page');
|
|
754
|
+
const renders = calls.render;
|
|
755
|
+
view.handleInput('ctrl+j');
|
|
756
|
+
assert.equal(calls.render, renders, 'a clamped scroll repaints nothing');
|
|
757
|
+
assert.deepEqual(calls.insert, []);
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
test('home/end reach the first and last ROW, group rows included (S38)', async () => {
|
|
761
|
+
const { view } = await open();
|
|
762
|
+
// S30: a file inside the tree stays highlighted across the order change, which
|
|
763
|
+
// is what leaves its folders open under the fully-folded default.
|
|
764
|
+
for (let step = 0; step < 3; step += 1) view.handleInput('down'); // src/lib/util.ts
|
|
765
|
+
view.handleInput('ctrl+o');
|
|
766
|
+
assert.match(selectedRow(rowsOf(view)), /util\.ts/);
|
|
767
|
+
view.handleInput('home');
|
|
768
|
+
assert.equal(selectedName(rowsOf(view)), 'src', 'S38: the first row of the tree is its first folder');
|
|
769
|
+
view.handleInput('end');
|
|
770
|
+
assert.equal(selectedName(rowsOf(view)), 'brand-new.ts', 'the last row');
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
test('ctrl+home and ctrl+end reach the preview edges', async () => {
|
|
774
|
+
const long = Array.from({ length: 60 }, (_, index) => `line ${index}`);
|
|
775
|
+
const { view } = await open({ loadPreview: async () => preview(long) });
|
|
776
|
+
for (let step = 0; step < 5; step += 1) view.handleInput('ctrl+j');
|
|
777
|
+
assert.match(previewPane(rowsOf(view), 0), /^│ 6 line 5/);
|
|
778
|
+
view.handleInput('ctrl+home');
|
|
779
|
+
assert.match(previewPane(rowsOf(view), 0), /^│ 1 line 0/);
|
|
780
|
+
view.handleInput('ctrl+end');
|
|
781
|
+
assert.match(previewPane(rowsOf(view), 0), /^│51 line 50/, 'ctrl+end lands on the last page');
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
test('tab marks the highlighted file in place, in one constant column, and toggles off', async () => {
|
|
785
|
+
const { view } = await open();
|
|
786
|
+
let rows = rowsOf(view);
|
|
787
|
+
assert.equal(listCell(rows, 'brand-new.ts').indexOf('brand-new.ts'), 3, 'the marker column is three cells');
|
|
788
|
+
assert.ok(!bodyText(rows).includes('\u258f'), 'nothing is marked before Tab');
|
|
789
|
+
view.handleInput('tab');
|
|
790
|
+
rows = rowsOf(view);
|
|
791
|
+
assert.match(listCell(rows, 'brand-new.ts'), /^▸▏ brand-new\.ts/, 'the bar lands in its own column');
|
|
792
|
+
assert.match(selectedRow(rows), /▸/, 'the highlight stays');
|
|
793
|
+
assert.equal(listCell(rows, 'README.md').indexOf('README.md'), 3, 'an unmarked row keeps the column');
|
|
794
|
+
assert.ok(!listCell(rows, 'README.md').includes('\u258f'));
|
|
795
|
+
view.handleInput('tab');
|
|
796
|
+
assert.ok(!bodyText(rowsOf(view)).includes('\u258f'), 'Tab twice clears the mark');
|
|
797
|
+
});
|
|
798
|
+
|
|
799
|
+
test('enter inserts every selected file plus the highlighted one, in list order, then closes', async () => {
|
|
800
|
+
const entries = ['a.ts', 'b.ts', 'c.ts', 'd.ts'].map((path) => ({ path, state: 'clean' }));
|
|
801
|
+
const { view, calls } = await open({ entries });
|
|
802
|
+
for (let step = 0; step < 3; step += 1) view.handleInput('down');
|
|
803
|
+
view.handleInput('tab');
|
|
804
|
+
view.handleInput('up');
|
|
805
|
+
view.handleInput('up');
|
|
806
|
+
view.handleInput('tab');
|
|
807
|
+
assert.deepEqual(calls.insert, [], 'Tab never inserts');
|
|
808
|
+
view.handleInput('enter');
|
|
809
|
+
assert.deepEqual(calls.insert, [['b.ts', 'd.ts']], 'list order, not marking order');
|
|
810
|
+
assert.equal(calls.close, 1);
|
|
811
|
+
view.handleInput('enter');
|
|
812
|
+
view.handleInput('escape');
|
|
813
|
+
assert.deepEqual(calls.insert, [['b.ts', 'd.ts']], 'a settled panel cannot fire again');
|
|
814
|
+
assert.equal(calls.close, 1);
|
|
815
|
+
});
|
|
816
|
+
|
|
817
|
+
test('enter adds a highlighted file that Tab never marked, and never duplicates one', async () => {
|
|
818
|
+
const entries = ['a.ts', 'b.ts', 'c.ts'].map((path) => ({ path, state: 'clean' }));
|
|
819
|
+
const once = await open({ entries });
|
|
820
|
+
once.view.handleInput('tab');
|
|
821
|
+
once.view.handleInput('enter');
|
|
822
|
+
assert.deepEqual(once.calls.insert, [['a.ts']], 'the highlighted file is not duplicated');
|
|
823
|
+
|
|
824
|
+
const twice = await open({ entries });
|
|
825
|
+
twice.view.handleInput('down');
|
|
826
|
+
twice.view.handleInput('tab');
|
|
827
|
+
twice.view.handleInput('down');
|
|
828
|
+
twice.view.handleInput('enter');
|
|
829
|
+
assert.deepEqual(twice.calls.insert, [['b.ts', 'c.ts']]);
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
test('a selection a query hides is inserted after the visible ones', async () => {
|
|
833
|
+
const entries = ['alpha.ts', 'beta.ts', 'gamma.ts'].map((path) => ({ path, state: 'clean' }));
|
|
834
|
+
const { view, calls } = await open({ entries });
|
|
835
|
+
view.handleInput('down');
|
|
836
|
+
view.handleInput('tab');
|
|
837
|
+
for (const character of 'al') view.handleInput(character);
|
|
838
|
+
view.handleInput('tab');
|
|
839
|
+
view.handleInput('enter');
|
|
840
|
+
assert.deepEqual(calls.insert, [['alpha.ts', 'beta.ts']], 'the hidden mark keeps its own order');
|
|
841
|
+
assert.equal(calls.close, 1);
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
test('a click parks the cursor on a group row and folds it, and space folds the group holding the file', async () => {
|
|
845
|
+
const { view, calls } = await open();
|
|
846
|
+
view.handleInput('ctrl+o'); // tree, opened with every group collapsed (S29)
|
|
847
|
+
let rows = rowsOf(view);
|
|
848
|
+
assert.ok(!bodyText(rows).includes('util.ts'), 'every group starts collapsed');
|
|
849
|
+
assert.match(selectedRow(rows), /brand-new\.ts/);
|
|
850
|
+
// S38 replaces S24's "a click folds it without focusing it": the click parks
|
|
851
|
+
// the cursor on the group row AND folds it, so `space` has the row (S43 leaves
|
|
852
|
+
// `enter` to insert, and only the Tab marks on a group row).
|
|
853
|
+
assert.deepEqual(view.handleMouse(mouse({ y: BODY_TOP })), { handled: true, render: true });
|
|
854
|
+
rows = rowsOf(view);
|
|
855
|
+
assert.ok(bodyText(rows).includes('cursor.ts'), 'the click opened the folder');
|
|
856
|
+
assert.ok(!bodyText(rows).includes('util.ts'), 'its own subfolder stays exactly as it was');
|
|
857
|
+
assert.ok(bodyText(rows).includes('src'), 'the group row stays');
|
|
858
|
+
assert.equal(selectedName(rows), 'src', 'the click parks the cursor on the group row');
|
|
859
|
+
assert.deepEqual(calls.insert, [], 'a group row never inserts');
|
|
860
|
+
assert.equal(calls.close, 0);
|
|
861
|
+
// A second click closes it again.
|
|
862
|
+
assert.deepEqual(view.handleMouse(mouse({ y: BODY_TOP })), { handled: true, render: true });
|
|
863
|
+
assert.ok(!bodyText(rowsOf(view)).includes('cursor.ts'), 'the click collapsed the group');
|
|
864
|
+
// space on a file folds the folder that HOLDS it, never a row of its own.
|
|
865
|
+
view.handleMouse(mouse({ y: BODY_TOP })); // src
|
|
866
|
+
view.handleMouse(mouse({ y: BODY_TOP + 1 })); // src/lib
|
|
867
|
+
rows = rowsOf(view);
|
|
868
|
+
assert.ok(bodyText(rows).includes('util.ts'), 'both folders are open');
|
|
869
|
+
view.handleMouse(mouse({ y: BODY_TOP + 2 })); // src/lib/util.ts
|
|
870
|
+
assert.equal(selectedName(rowsOf(view)), 'util.ts', 'the click selected the file');
|
|
871
|
+
view.handleInput('space');
|
|
872
|
+
rows = rowsOf(view);
|
|
873
|
+
assert.ok(!bodyText(rows).includes('util.ts'), 'space folded the folder holding it');
|
|
874
|
+
assert.ok(bodyText(rows).includes('lib'), 'the folder row stays');
|
|
875
|
+
assert.equal(selectedName(rows), 'lib', 'S38: the cursor parks on the group row that held the file');
|
|
876
|
+
|
|
877
|
+
// S30 replaces S10's per-order memory: choosing the tree again re-seeds its
|
|
878
|
+
// folds to the focused file's path, so the folder just folded is open again.
|
|
879
|
+
view.handleInput('space'); // reopen the folder from its own row
|
|
880
|
+
view.handleInput('down'); // and step back onto the file it holds
|
|
881
|
+
assert.equal(selectedName(rowsOf(view)), 'util.ts');
|
|
882
|
+
view.handleInput('ctrl+o'); // ext
|
|
883
|
+
assert.ok(bodyText(rowsOf(view)).includes('.md'), 'the ext order paints its own groups');
|
|
884
|
+
view.handleInput('ctrl+o'); // files
|
|
885
|
+
view.handleInput('ctrl+o'); // tree again
|
|
886
|
+
rows = rowsOf(view);
|
|
887
|
+
assert.ok(bodyText(rows).includes('cursor.ts'), 'the focused file path is open again (S30)');
|
|
888
|
+
assert.ok(bodyText(rows).includes('util.ts'), 'and so is the nested folder that holds it');
|
|
889
|
+
assert.deepEqual(groupCells(rows), [' ▾ src', ' ▾ lib'], 'no fold the reader left behind is remembered');
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
test('a non-empty query forces every group open and makes the fold keys inert', async () => {
|
|
893
|
+
const { view } = await open();
|
|
894
|
+
view.handleInput('ctrl+o');
|
|
895
|
+
// S29: the tree is fully collapsed, and the query below is what opens it.
|
|
896
|
+
assert.ok(!bodyText(rowsOf(view)).includes('util.ts'));
|
|
897
|
+
for (const character of 'util') view.handleInput(character);
|
|
898
|
+
assert.ok(bodyText(rowsOf(view)).includes('util.ts'), 'a match is never hidden behind a fold');
|
|
899
|
+
view.handleInput('space');
|
|
900
|
+
assert.ok(bodyText(rowsOf(view)).includes('util.ts'), 'the fold key does nothing while a query is active');
|
|
901
|
+
view.handleInput('shift+space');
|
|
902
|
+
assert.ok(bodyText(rowsOf(view)).includes('util.ts'), 'neither does the fold-all key');
|
|
903
|
+
view.handleInput('ctrl+u');
|
|
904
|
+
assert.ok(!bodyText(rowsOf(view)).includes('util.ts'), 'the fold the query overrode is back once it clears');
|
|
905
|
+
});
|
|
906
|
+
|
|
907
|
+
test('ctrl+o keeps the same file highlighted and repaints the order', async () => {
|
|
908
|
+
const { view } = await open();
|
|
909
|
+
view.handleInput('down');
|
|
910
|
+
view.handleInput('ctrl+o');
|
|
911
|
+
assert.match(selectedRow(rowsOf(view)), /cursor\.ts/);
|
|
912
|
+
assert.match(infoCell(rowsOf(view)), / tree$/, 'the repainted order is named on the info row');
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
test('ctrl+e opens the highlighted file and closes, with no repaint before the terminal stops', async () => {
|
|
916
|
+
const { view, calls } = await open();
|
|
917
|
+
view.handleInput('down');
|
|
918
|
+
const renders = calls.render;
|
|
919
|
+
view.handleInput('ctrl+e');
|
|
920
|
+
assert.deepEqual(calls.open, ['src/cursor.ts']);
|
|
921
|
+
assert.equal(calls.close, 1);
|
|
922
|
+
assert.equal(calls.render, renders, 'the handoff never repaints first');
|
|
923
|
+
view.handleInput('ctrl+e');
|
|
924
|
+
assert.deepEqual(calls.open, ['src/cursor.ts'], 'the panel is settled');
|
|
925
|
+
assert.deepEqual(calls.insert, []);
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
test('escape and ctrl+c close once, and later keys are ignored', async () => {
|
|
929
|
+
const escaped = await open();
|
|
930
|
+
escaped.view.handleInput('escape');
|
|
931
|
+
assert.equal(escaped.calls.close, 1);
|
|
932
|
+
escaped.view.handleInput('escape');
|
|
933
|
+
assert.equal(escaped.calls.close, 1);
|
|
934
|
+
|
|
935
|
+
const ctrlC = await open();
|
|
936
|
+
ctrlC.view.handleInput('ctrl+c');
|
|
937
|
+
assert.equal(ctrlC.calls.close, 1);
|
|
938
|
+
ctrlC.view.handleInput('tab');
|
|
939
|
+
ctrlC.view.handleInput('enter');
|
|
940
|
+
assert.deepEqual(ctrlC.calls.insert, []);
|
|
941
|
+
});
|
|
942
|
+
|
|
943
|
+
test('a key release is ignored', async () => {
|
|
944
|
+
const { view, calls } = await open();
|
|
945
|
+
view.handleInput('release');
|
|
946
|
+
view.handleInput('release');
|
|
947
|
+
assert.equal(calls.close, 0);
|
|
948
|
+
view.handleInput('escape');
|
|
949
|
+
assert.equal(calls.close, 1);
|
|
950
|
+
});
|
|
951
|
+
|
|
952
|
+
test('a throwing insert or editor callback still closes the panel exactly once', async () => {
|
|
953
|
+
const insert = await open({ onInsert() { throw new Error('paste failed'); } });
|
|
954
|
+
assert.throws(() => insert.view.handleInput('enter'), /paste failed/);
|
|
955
|
+
assert.equal(insert.calls.close, 1);
|
|
956
|
+
insert.view.handleInput('enter');
|
|
957
|
+
assert.equal(insert.calls.close, 1);
|
|
958
|
+
|
|
959
|
+
const editor = await open({ onOpen() { throw new Error('editor failed'); } });
|
|
960
|
+
assert.throws(() => editor.view.handleInput('ctrl+e'), /editor failed/);
|
|
961
|
+
assert.equal(editor.calls.close, 1);
|
|
962
|
+
editor.view.handleInput('ctrl+e');
|
|
963
|
+
assert.equal(editor.calls.close, 1);
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
test('a hostile key matcher still routes the spelled sequences', async () => {
|
|
967
|
+
const { view, calls } = await open({
|
|
968
|
+
helpers: { ...helpers, matchesKey() { throw new Error('no matcher'); } },
|
|
969
|
+
});
|
|
970
|
+
view.handleInput('\x1b[B');
|
|
971
|
+
assert.match(selectedRow(rowsOf(view)), /cursor\.ts/);
|
|
972
|
+
view.handleInput('\r');
|
|
973
|
+
assert.deepEqual(calls.insert, [['src/cursor.ts']]);
|
|
974
|
+
assert.equal(calls.close, 1);
|
|
975
|
+
});
|
|
976
|
+
});
|
|
977
|
+
|
|
978
|
+
describe('mouse (S5)', () => {
|
|
979
|
+
test('a click selects the row under it, including the list pane\u2019s last column', async () => {
|
|
980
|
+
const entries = ['a.ts', 'b.ts', 'c.ts'].map((path) => ({ path, state: 'clean' }));
|
|
981
|
+
const { view, calls } = await open({ entries });
|
|
982
|
+
let rows = rowsOf(view);
|
|
983
|
+
const target = rowOf(rows, 'b.ts');
|
|
984
|
+
assert.deepEqual(view.handleMouse(mouse({ y: target })), { handled: true, render: true });
|
|
985
|
+
rows = rowsOf(view);
|
|
986
|
+
assert.match(selectedRow(rows), /b\.ts/);
|
|
987
|
+
assert.equal(rowOf(rows, '▸'), target, 'the selection lands on the row that was under the pointer');
|
|
988
|
+
|
|
989
|
+
const lastColumn = 2 + listWidth(rows) - 1;
|
|
990
|
+
assert.deepEqual(view.handleMouse(mouse({ x: lastColumn, y: rowOf(rows, 'c.ts') })), { handled: true, render: true });
|
|
991
|
+
assert.match(selectedRow(rowsOf(view)), /c\.ts/);
|
|
992
|
+
assert.deepEqual(calls.insert, []);
|
|
993
|
+
assert.equal(calls.close, 0);
|
|
994
|
+
});
|
|
995
|
+
|
|
996
|
+
test('a press claims the gesture and a preview click is absorbed', async () => {
|
|
997
|
+
const { view, calls } = await open();
|
|
998
|
+
let rows = rowsOf(view);
|
|
999
|
+
assert.deepEqual(view.handleMouse(mouse({ type: 'press', y: rowOf(rows, 'README.md') })), { handled: true, render: false });
|
|
1000
|
+
assert.match(selectedRow(rowsOf(view)), /brand-new\.ts/, 'a press selects nothing');
|
|
1001
|
+
rows = rowsOf(view);
|
|
1002
|
+
assert.deepEqual(view.handleMouse(mouse({ x: previewStart(rows) + 1, y: BODY_TOP })), { handled: true, render: false });
|
|
1003
|
+
assert.match(selectedRow(rowsOf(view)), /brand-new\.ts/);
|
|
1004
|
+
assert.deepEqual(calls.insert, []);
|
|
1005
|
+
assert.equal(calls.close, 0);
|
|
1006
|
+
});
|
|
1007
|
+
|
|
1008
|
+
test('the wheel over the list moves the selection and never scrolls the preview', async () => {
|
|
1009
|
+
const long = Array.from({ length: 60 }, (_, index) => `line ${index}`);
|
|
1010
|
+
const entries = [{ path: 'a.ts', state: 'clean' }, { path: 'b.ts', state: 'clean' }];
|
|
1011
|
+
const { view } = await open({ entries, loadPreview: async (path) => preview(long.map((line) => `${path} ${line}`)) });
|
|
1012
|
+
for (let step = 0; step < 5; step += 1) view.handleInput('ctrl+j');
|
|
1013
|
+
assert.ok(bodyText(rowsOf(view)).includes('a.ts line 5'), 'the preview is scrolled before the wheel');
|
|
1014
|
+
|
|
1015
|
+
assert.deepEqual(
|
|
1016
|
+
view.handleMouse(mouse({ type: 'wheel', button: 'none', wheelDelta: 1, y: BODY_TOP })),
|
|
1017
|
+
{ handled: true, render: true },
|
|
1018
|
+
);
|
|
1019
|
+
let rows = rowsOf(view);
|
|
1020
|
+
assert.match(selectedRow(rows), /b\.ts/, 'the list wheel moves the selection');
|
|
1021
|
+
await tick();
|
|
1022
|
+
rows = rowsOf(view);
|
|
1023
|
+
assert.ok(bodyText(rows).includes('b.ts line 0'), 'the preview follows the file, at its own top');
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
test('the preview wheel scrolls the preview, never the selection, and clamps', async () => {
|
|
1027
|
+
const long = Array.from({ length: 60 }, (_, index) => `line ${index}`);
|
|
1028
|
+
const { view } = await open({ entries: [{ path: 'a.ts', state: 'clean' }], loadPreview: async () => preview(long) });
|
|
1029
|
+
for (let step = 0; step < 5; step += 1) view.handleInput('ctrl+j');
|
|
1030
|
+
let rows = rowsOf(view);
|
|
1031
|
+
assert.match(previewPane(rows, 0), /^│ 6 line 5/);
|
|
1032
|
+
|
|
1033
|
+
assert.deepEqual(
|
|
1034
|
+
view.handleMouse(mouse({ type: 'wheel', button: 'none', wheelDelta: 1, y: BODY_TOP })),
|
|
1035
|
+
{ handled: true, render: false },
|
|
1036
|
+
'a one-file list has nowhere to move',
|
|
1037
|
+
);
|
|
1038
|
+
rows = rowsOf(view);
|
|
1039
|
+
assert.match(previewPane(rows, 0), /^│ 6 line 5/, 'the list wheel never scrolls the preview');
|
|
1040
|
+
|
|
1041
|
+
const previewX = previewStart(rows) + 2;
|
|
1042
|
+
assert.deepEqual(
|
|
1043
|
+
view.handleMouse(mouse({ type: 'wheel', button: 'none', wheelDelta: 1, x: previewX, y: BODY_TOP })),
|
|
1044
|
+
{ handled: true, render: true },
|
|
1045
|
+
);
|
|
1046
|
+
rows = rowsOf(view);
|
|
1047
|
+
assert.match(previewPane(rows, 0), /^│ 7 line 6/, 'the preview wheel scrolls the preview');
|
|
1048
|
+
assert.match(selectedRow(rows), /a\.ts/, 'and never moves the selection');
|
|
1049
|
+
|
|
1050
|
+
for (let step = 0; step < 200; step += 1) {
|
|
1051
|
+
view.handleMouse(mouse({ type: 'wheel', button: 'none', wheelDelta: 1, x: previewX, y: BODY_TOP }));
|
|
1052
|
+
}
|
|
1053
|
+
rows = rowsOf(view);
|
|
1054
|
+
assert.match(previewPane(rows, 0), /^│51 line 50/);
|
|
1055
|
+
assert.deepEqual(
|
|
1056
|
+
view.handleMouse(mouse({ type: 'wheel', button: 'none', wheelDelta: 1, x: previewX, y: BODY_TOP })),
|
|
1057
|
+
{ handled: true, render: false },
|
|
1058
|
+
'a clamped preview wheel repaints nothing',
|
|
1059
|
+
);
|
|
1060
|
+
assert.equal(
|
|
1061
|
+
view.handleMouse(mouse({ type: 'wheel', button: 'none', wheelDelta: 1, x: 1, y: BODY_TOP })),
|
|
1062
|
+
undefined,
|
|
1063
|
+
'the wheel outside both panes is not handled',
|
|
1064
|
+
);
|
|
1065
|
+
});
|
|
1066
|
+
|
|
1067
|
+
test('hover paints the row in the key role and clears when the pointer leaves', async () => {
|
|
1068
|
+
const theme = recordingTheme();
|
|
1069
|
+
const { view } = await open({ theme });
|
|
1070
|
+
let rows = rowsOf(view);
|
|
1071
|
+
assert.deepEqual(view.handleMouse(mouse({ type: 'move', button: 'none', y: rowOf(rows, 'README.md') })), { handled: true, render: true });
|
|
1072
|
+
rows = rowsOf(view);
|
|
1073
|
+
assert.ok(theme.calls.some((call) => call.role === 'accent' && call.text === 'README.md'), 'the hovered name takes the key role');
|
|
1074
|
+
assert.deepEqual(view.handleMouse(mouse({ type: 'move', button: 'none', y: BODY_TOP - 1 })), { handled: true, render: true });
|
|
1075
|
+
const callsBefore = theme.calls.length;
|
|
1076
|
+
view.render(WIDTH);
|
|
1077
|
+
assert.ok(!theme.calls.slice(callsBefore).some((call) => call.role === 'accent' && call.text === 'README.md'));
|
|
1078
|
+
});
|
|
1079
|
+
|
|
1080
|
+
test('events from another geometry, or from outside the card, are not handled', async () => {
|
|
1081
|
+
const { view } = await open();
|
|
1082
|
+
view.render(WIDTH);
|
|
1083
|
+
assert.equal(view.handleMouse(mouse({ x: 1, y: BODY_TOP })), undefined);
|
|
1084
|
+
assert.equal(view.handleMouse(mouse({ y: 0 })), undefined);
|
|
1085
|
+
assert.equal(view.handleMouse(mouse({ y: 200 })), undefined);
|
|
1086
|
+
assert.equal(view.handleMouse(mouse({ width: 60 })), undefined);
|
|
1087
|
+
assert.equal(view.handleMouse(null), undefined);
|
|
1088
|
+
assert.equal(view.handleMouse({ type: 'click', button: 'right', x: 3, y: BODY_TOP, width: WIDTH, height: CARD_HEIGHT }), undefined);
|
|
1089
|
+
|
|
1090
|
+
view.handleMouse(mouse({ type: 'move', button: 'none', y: BODY_TOP }));
|
|
1091
|
+
view.invalidate();
|
|
1092
|
+
assert.equal(view.handleMouse(mouse({ y: BODY_TOP })), undefined, 'invalidate drops the hit geometry');
|
|
1093
|
+
view.render(WIDTH);
|
|
1094
|
+
view.handleInput('escape');
|
|
1095
|
+
assert.equal(view.handleMouse(mouse({ y: BODY_TOP })), undefined, 'a settled panel takes no mouse');
|
|
1096
|
+
});
|
|
1097
|
+
|
|
1098
|
+
test('dispose stops the input and the mouse routes', async () => {
|
|
1099
|
+
const { view, calls } = await open();
|
|
1100
|
+
view.render(WIDTH);
|
|
1101
|
+
view.dispose();
|
|
1102
|
+
view.handleInput('down');
|
|
1103
|
+
view.handleInput('escape');
|
|
1104
|
+
assert.equal(calls.close, 0);
|
|
1105
|
+
assert.equal(view.handleMouse(mouse({})), undefined);
|
|
1106
|
+
});
|
|
1107
|
+
});
|
|
1108
|
+
|
|
1109
|
+
describe('the info row (S22)', () => {
|
|
1110
|
+
test('counts the listed files out of the total, the Tab selection, then the order at the list edge', async () => {
|
|
1111
|
+
const { view } = await open();
|
|
1112
|
+
const rows = rowsOf(view);
|
|
1113
|
+
assert.equal(infoCell(rows).length, listWidth(rows), 'the info row fills exactly the list column');
|
|
1114
|
+
assert.match(infoCell(rows), /^4\/4 \(0\) ─+ files$/, infoCell(rows));
|
|
1115
|
+
view.handleInput('tab');
|
|
1116
|
+
assert.match(infoCell(rowsOf(view)), /^4\/4 \(1\) ─+ files$/, 'the Tab mark is counted');
|
|
1117
|
+
view.handleInput('down');
|
|
1118
|
+
view.handleInput('tab');
|
|
1119
|
+
assert.match(infoCell(rowsOf(view)), /^4\/4 \(2\) ─+ files$/);
|
|
1120
|
+
view.handleInput('tab');
|
|
1121
|
+
assert.match(infoCell(rowsOf(view)), /^4\/4 \(1\) ─+ files$/, 'unmarking counts back down');
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
test('the listed count follows the query while the total stays the whole listing', async () => {
|
|
1125
|
+
const { view } = await open();
|
|
1126
|
+
for (const character of 'util') view.handleInput(character);
|
|
1127
|
+
assert.match(infoCell(rowsOf(view)), /^1\/4 \(0\) ─+ files$/);
|
|
1128
|
+
for (const character of 'zzz') view.handleInput(character);
|
|
1129
|
+
assert.match(infoCell(rowsOf(view)), /^0\/4 \(0\) ─+ files$/, 'a query that matches nothing lists none');
|
|
1130
|
+
view.handleInput('ctrl+u');
|
|
1131
|
+
assert.match(infoCell(rowsOf(view)), /^4\/4 \(0\) ─+ files$/);
|
|
1132
|
+
});
|
|
1133
|
+
|
|
1134
|
+
test('the order is right-aligned at the list edge and follows ctrl+o', async () => {
|
|
1135
|
+
const { view } = await open();
|
|
1136
|
+
view.handleInput('ctrl+o');
|
|
1137
|
+
assert.match(infoCell(rowsOf(view)), /^4\/4 \(0\) ─+ tree$/, 'S23: the folder order is named tree');
|
|
1138
|
+
view.handleInput('ctrl+o');
|
|
1139
|
+
assert.match(infoCell(rowsOf(view)), /^4\/4 \(0\) ─+ ext$/);
|
|
1140
|
+
assert.equal(infoCell(rowsOf(view)).length, listWidth(rowsOf(view)), 'the order sits at the list pane edge');
|
|
1141
|
+
});
|
|
1142
|
+
|
|
1143
|
+
test('a pending or failed listing counts zero and still paints its own line', async () => {
|
|
1144
|
+
const pending = mount({ loadEntries: () => new Promise(() => {}) });
|
|
1145
|
+
const rows = pending.view.render(WIDTH).map(strip);
|
|
1146
|
+
assert.match(infoCell(rows), /^0\/0 \(0\) ─+ files$/);
|
|
1147
|
+
assert.ok(bodyText(rows).includes('Loading files'), 'a pending listing still says so');
|
|
1148
|
+
|
|
1149
|
+
const failed = await open({ loadEntries: async () => ({ ok: false, message: 'Not a Git repository: /nowhere.' }) });
|
|
1150
|
+
assert.match(infoCell(rowsOf(failed.view)), /^0\/0 \(0\) ─+ files$/);
|
|
1151
|
+
assert.ok(bodyText(rowsOf(failed.view)).includes('Not a Git repository: /nowhere.'), 'a failed listing still says so');
|
|
1152
|
+
});
|
|
1153
|
+
|
|
1154
|
+
test('the info row fits the narrowest card without overflowing its column', async () => {
|
|
1155
|
+
const { view } = await open();
|
|
1156
|
+
for (const width of [20, 24, 40, 72, 200]) {
|
|
1157
|
+
const rows = rowsOf(view, width);
|
|
1158
|
+
for (const row of rows) assert.equal(helpers.visibleWidth(row), width, `no row is ragged at ${width}`);
|
|
1159
|
+
const info = infoCell(rows, width);
|
|
1160
|
+
assert.ok(helpers.visibleWidth(info) <= paneWidths(width).list, `the info row stays inside its column at ${width}`);
|
|
1161
|
+
assert.ok(info.includes('/'), `the counts survive ${width}: ${info}`);
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
});
|
|
1165
|
+
|
|
1166
|
+
describe('every row of tree and ext takes the cursor (S38)', () => {
|
|
1167
|
+
test('the arrows and home/end park the cursor on a group row exactly as on a file row', async () => {
|
|
1168
|
+
const { view, calls } = await open();
|
|
1169
|
+
view.handleInput('ctrl+o'); // tree, every group collapsed: [src] README.md brand-new.ts
|
|
1170
|
+
view.handleInput('home');
|
|
1171
|
+
assert.equal(selectedName(rowsOf(view)), 'src', 'home reaches the first row, the folder group');
|
|
1172
|
+
const walked = [];
|
|
1173
|
+
for (let step = 0; step < 4; step += 1) {
|
|
1174
|
+
walked.push(selectedName(rowsOf(view)));
|
|
1175
|
+
view.handleInput('down');
|
|
1176
|
+
}
|
|
1177
|
+
assert.deepEqual(walked, ['src', 'README.md', 'brand-new.ts', 'brand-new.ts'],
|
|
1178
|
+
'walking down visits the group row and every file row, and clamps on the last one');
|
|
1179
|
+
view.handleInput('home');
|
|
1180
|
+
view.handleInput('up');
|
|
1181
|
+
assert.equal(selectedName(rowsOf(view)), 'src', 'the cursor clamps on the first row, the group');
|
|
1182
|
+
view.handleInput('end');
|
|
1183
|
+
assert.equal(selectedName(rowsOf(view)), 'brand-new.ts', 'end is the last row');
|
|
1184
|
+
|
|
1185
|
+
// `ext`: its extension groups are rows the cursor takes too.
|
|
1186
|
+
view.handleInput('ctrl+o'); // ext: [.md] [.ts] brand-new.ts cursor.ts util.ts
|
|
1187
|
+
view.handleInput('home');
|
|
1188
|
+
assert.equal(selectedName(rowsOf(view)), '.md', 'the ext order starts on its first extension row');
|
|
1189
|
+
view.handleInput('down');
|
|
1190
|
+
assert.equal(selectedName(rowsOf(view)), '.ts', 'the cursor walks the extension rows too');
|
|
1191
|
+
view.handleInput('down');
|
|
1192
|
+
assert.equal(selectedName(rowsOf(view)), 'brand-new.ts', 'and continues into the files');
|
|
1193
|
+
assert.deepEqual(calls.insert, []);
|
|
1194
|
+
assert.equal(calls.close, 0);
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
test('the wheel and the page moves park the cursor on a group row too', async () => {
|
|
1198
|
+
const entries = ['a', 'b', 'c', 'd', 'e']
|
|
1199
|
+
.map((name) => ({ path: `src/${name}.ts`, state: 'clean' }))
|
|
1200
|
+
.concat([{ path: 'z.ts', state: 'clean' }]);
|
|
1201
|
+
const { view } = await open({ entries });
|
|
1202
|
+
view.handleInput('ctrl+o'); // tree: S30 opened `src`, the folder holding the focused file
|
|
1203
|
+
view.handleInput('home');
|
|
1204
|
+
assert.equal(selectedName(rowsOf(view)), 'src', 'the wheel below starts from the folder row');
|
|
1205
|
+
assert.equal(bodyCells(rowsOf(view))[0], '▸▾ src', 'the focused folder row paints its cursor and chevron');
|
|
1206
|
+
// S10 stands: space on a group row folds it, and S38 says the cursor stays there.
|
|
1207
|
+
view.handleInput('space');
|
|
1208
|
+
assert.equal(selectedName(rowsOf(view)), 'src', 'the folded folder keeps the cursor');
|
|
1209
|
+
assert.equal(bodyCells(rowsOf(view))[0], '▸▸ src', 'and paints its collapsed chevron');
|
|
1210
|
+
view.handleInput('space');
|
|
1211
|
+
assert.equal(bodyCells(rowsOf(view))[0], '▸▾ src', 'space reopened it from that same row');
|
|
1212
|
+
|
|
1213
|
+
assert.deepEqual(
|
|
1214
|
+
view.handleMouse(mouse({ type: 'wheel', button: 'none', wheelDelta: 1, y: BODY_TOP })),
|
|
1215
|
+
{ handled: true, render: true },
|
|
1216
|
+
);
|
|
1217
|
+
assert.equal(selectedName(rowsOf(view)), 'a.ts', 'the wheel moves off the group row');
|
|
1218
|
+
view.handleMouse(mouse({ type: 'wheel', button: 'none', wheelDelta: -1, y: BODY_TOP }));
|
|
1219
|
+
assert.equal(selectedName(rowsOf(view)), 'src', 'and back onto it');
|
|
1220
|
+
|
|
1221
|
+
// The page moves are compatibility bindings S4 never names (like home/end).
|
|
1222
|
+
view.handleInput('pagedown');
|
|
1223
|
+
assert.equal(selectedName(rowsOf(view)), 'z.ts', 'a page down clamps on the last row');
|
|
1224
|
+
view.handleInput('\x1b[5~');
|
|
1225
|
+
assert.equal(selectedName(rowsOf(view)), 'src', 'a page up from a raw sequence returns to the first row');
|
|
1226
|
+
});
|
|
1227
|
+
|
|
1228
|
+
test('tab and enter on a group row mark and insert nothing, and the panel stays open', async () => {
|
|
1229
|
+
const entries = [{ path: 'src/a.ts', state: 'clean' }, { path: 'src/b.ts', state: 'clean' }];
|
|
1230
|
+
const { view, calls } = await open({ entries });
|
|
1231
|
+
view.handleInput('ctrl+o'); // tree: [src] a.ts b.ts
|
|
1232
|
+
view.handleInput('home');
|
|
1233
|
+
assert.equal(selectedName(rowsOf(view)), 'src');
|
|
1234
|
+
const before = rowsOf(view);
|
|
1235
|
+
assert.ok(bodyText(before).includes('a.ts'), 'the folder holding the focused file is open (S30)');
|
|
1236
|
+
const renders = calls.render;
|
|
1237
|
+
view.handleInput('tab');
|
|
1238
|
+
assert.deepEqual(rowsOf(view), before, 'tab changes nothing on a group row');
|
|
1239
|
+
assert.equal(calls.render, renders, 'so it repaints nothing');
|
|
1240
|
+
assert.ok(!bodyText(rowsOf(view)).includes(SELECTION_MARK), 'and it never marks the group');
|
|
1241
|
+
// S43: enter is only the insert key. With no Tab mark it sends nothing, keeps the
|
|
1242
|
+
// panel open and leaves the group exactly as it found it — never a fold.
|
|
1243
|
+
view.handleInput('enter');
|
|
1244
|
+
assert.deepEqual(calls.insert, [], 'enter on a group row inserts nothing');
|
|
1245
|
+
assert.equal(calls.close, 0, 'and leaves the panel open');
|
|
1246
|
+
const after = rowsOf(view);
|
|
1247
|
+
assert.deepEqual(after, before, 'enter folds nothing and repaints nothing else');
|
|
1248
|
+
assert.ok(bodyText(after).includes('a.ts'), 'the folder under the cursor is still open');
|
|
1249
|
+
// S43: with a Tab mark the same row sends the marks alone, once, and closes.
|
|
1250
|
+
view.handleInput('down');
|
|
1251
|
+
assert.equal(selectedName(rowsOf(view)), 'a.ts');
|
|
1252
|
+
view.handleInput('tab');
|
|
1253
|
+
view.handleInput('home');
|
|
1254
|
+
assert.equal(selectedName(rowsOf(view)), 'src', 'the cursor is back on the group row');
|
|
1255
|
+
view.handleInput('enter');
|
|
1256
|
+
assert.deepEqual(calls.insert, [['src/a.ts']], 'the Tab selection alone is the payload');
|
|
1257
|
+
assert.equal(calls.close, 1, 'and the panel closes');
|
|
1258
|
+
});
|
|
1259
|
+
|
|
1260
|
+
test('the preview settles on a group row and the panel stays live', async () => {
|
|
1261
|
+
const { view, calls } = await open();
|
|
1262
|
+
view.handleInput('ctrl+o'); // tree, every group collapsed
|
|
1263
|
+
view.handleInput('home'); // the src group
|
|
1264
|
+
assert.equal(selectedName(rowsOf(view)), 'src');
|
|
1265
|
+
const rows = rowsOf(view);
|
|
1266
|
+
assert.ok(previewTop(rows).startsWith('╭'), `the preview keeps its box: ${previewTop(rows)}`);
|
|
1267
|
+
assert.ok(bodyText(rows).includes('No file selected.'), 'the pane says it shows no file');
|
|
1268
|
+
assert.ok(!/\d+\/\d+/.test(previewTop(rows)), 'and claims no line position');
|
|
1269
|
+
// The panel keeps answering: the group folds, nothing opens, escape still closes.
|
|
1270
|
+
view.handleInput('space');
|
|
1271
|
+
assert.ok(bodyText(rowsOf(view)).includes('cursor.ts'), 'space opened the focused group');
|
|
1272
|
+
view.handleInput('ctrl+e');
|
|
1273
|
+
assert.deepEqual(calls.open, [], 'a group row is never opened in the editor');
|
|
1274
|
+
assert.equal(calls.close, 0);
|
|
1275
|
+
view.handleInput('escape');
|
|
1276
|
+
assert.equal(calls.close, 1, 'the panel still closes');
|
|
1277
|
+
});
|
|
1278
|
+
|
|
1279
|
+
test('a click folds a group while no query is active, and does nothing during one', async () => {
|
|
1280
|
+
const { view } = await open();
|
|
1281
|
+
view.handleInput('ctrl+o'); // tree, every group collapsed (S29)
|
|
1282
|
+
for (const character of 'src') view.handleInput(character);
|
|
1283
|
+
assert.ok(bodyText(rowsOf(view)).includes('cursor.ts'), 'the query holds the groups open');
|
|
1284
|
+
assert.deepEqual(view.handleMouse(mouse({ y: BODY_TOP })), { handled: true, render: false });
|
|
1285
|
+
assert.ok(bodyText(rowsOf(view)).includes('cursor.ts'), 'a click cannot fold while a query is active');
|
|
1286
|
+
view.handleInput('ctrl+u');
|
|
1287
|
+
rowsOf(view); // a key invalidates the hit geometry; the host repaints
|
|
1288
|
+
view.handleMouse(mouse({ y: BODY_TOP }));
|
|
1289
|
+
assert.ok(bodyText(rowsOf(view)).includes('cursor.ts'), 'the cleared query leaves the group as it was, folded under S29');
|
|
1290
|
+
assert.ok(!bodyText(rowsOf(view)).includes('util.ts'), 'and a click opened only the row it landed on');
|
|
1291
|
+
});
|
|
1292
|
+
|
|
1293
|
+
test('PRESERVE: the flat files order keeps its old arrow and space behaviour', async () => {
|
|
1294
|
+
// `files` paints no group row, so the new fold rules and the new cursor rule
|
|
1295
|
+
// must change nothing here: the arrows still clamp and `space` still does not
|
|
1296
|
+
// move the highlight.
|
|
1297
|
+
const { view, calls } = await open();
|
|
1298
|
+
view.handleInput('down');
|
|
1299
|
+
assert.match(selectedRow(rowsOf(view)), /cursor\.ts/);
|
|
1300
|
+
view.handleInput('space');
|
|
1301
|
+
assert.match(selectedRow(rowsOf(view)), /cursor\.ts/, 'nothing folds and the cursor stays');
|
|
1302
|
+
assert.ok(bodyText(rowsOf(view)).includes('util.ts'), 'every file row is still painted');
|
|
1303
|
+
for (let step = 0; step < 9; step += 1) view.handleInput('down');
|
|
1304
|
+
assert.match(selectedRow(rowsOf(view)), /util\.ts/);
|
|
1305
|
+
for (let step = 0; step < 9; step += 1) view.handleInput('up');
|
|
1306
|
+
assert.match(selectedRow(rowsOf(view)), /brand-new\.ts/);
|
|
1307
|
+
assert.deepEqual(calls.insert, []);
|
|
1308
|
+
assert.equal(calls.close, 0);
|
|
1309
|
+
});
|
|
1310
|
+
|
|
1311
|
+
test('a query parks the cursor on the first matching row, group or file', async () => {
|
|
1312
|
+
const entries = [
|
|
1313
|
+
{ path: 'src/a.ts', state: 'clean' },
|
|
1314
|
+
{ path: 'src/b.ts', state: 'clean' },
|
|
1315
|
+
{ path: 'z.ts', state: 'clean' },
|
|
1316
|
+
];
|
|
1317
|
+
const { view } = await open({ entries });
|
|
1318
|
+
view.handleInput('ctrl+o'); // tree: S30 opened `src`
|
|
1319
|
+
for (const character of 'src') view.handleInput(character);
|
|
1320
|
+
assert.equal(selectedName(rowsOf(view)), 'src', 'a query parks the cursor on the first row it lists');
|
|
1321
|
+
// S10 stands: the query holds every group open, so the fold key changes nothing.
|
|
1322
|
+
const during = rowsOf(view);
|
|
1323
|
+
view.handleInput('space');
|
|
1324
|
+
assert.deepEqual(rowsOf(view), during, 'the query holds the folder open');
|
|
1325
|
+
view.handleInput('ctrl+u');
|
|
1326
|
+
assert.equal(selectedName(rowsOf(view)), 'src', 'and clearing it keeps the first row, the group');
|
|
1327
|
+
});
|
|
1328
|
+
|
|
1329
|
+
test('space folds the group holding the focused file and parks the cursor on its row', async () => {
|
|
1330
|
+
const entries = [{ path: 'src/a.ts', state: 'clean' }, { path: 'src/b.ts', state: 'clean' }];
|
|
1331
|
+
const { view, calls } = await open({ entries });
|
|
1332
|
+
view.handleInput('ctrl+o'); // tree: [src] a.ts b.ts
|
|
1333
|
+
assert.equal(selectedName(rowsOf(view)), 'a.ts');
|
|
1334
|
+
view.handleInput('space'); // folds `src`, the folder holding a.ts
|
|
1335
|
+
let rows = rowsOf(view);
|
|
1336
|
+
assert.ok(!bodyText(rows).includes('a.ts'), 'the only group is folded, so no file row is left');
|
|
1337
|
+
assert.equal(selectedName(rows), 'src', 'S38: the cursor rests on the group row that held the file');
|
|
1338
|
+
// A group row is still not a file: nothing marks, opens or inserts it.
|
|
1339
|
+
view.handleInput('tab');
|
|
1340
|
+
assert.ok(!bodyText(rowsOf(view)).includes(SELECTION_MARK), 'a group row is never marked');
|
|
1341
|
+
view.handleInput('ctrl+e');
|
|
1342
|
+
assert.deepEqual(calls.open, [], 'a group row is never opened');
|
|
1343
|
+
assert.equal(calls.close, 0);
|
|
1344
|
+
view.handleInput('space');
|
|
1345
|
+
rows = rowsOf(view);
|
|
1346
|
+
assert.equal(selectedName(rows), 'src', 'space reopened the tree and the cursor stays on the folder row');
|
|
1347
|
+
assert.ok(bodyText(rows).includes('a.ts'), 'the files paint again');
|
|
1348
|
+
view.handleInput('down');
|
|
1349
|
+
assert.equal(selectedName(rowsOf(view)), 'a.ts', 'and one step down reaches the first file');
|
|
1350
|
+
// S43 supersedes S10's "enter also folds": the fold keys are space, shift+space
|
|
1351
|
+
// and the click, so enter on this group row changes nothing and stays open.
|
|
1352
|
+
view.handleInput('up');
|
|
1353
|
+
view.handleInput('enter');
|
|
1354
|
+
rows = rowsOf(view);
|
|
1355
|
+
assert.ok(bodyText(rows).includes('a.ts'), 'enter leaves the folder under the cursor open');
|
|
1356
|
+
assert.equal(selectedName(rows), 'src', 'and the group row keeps the cursor');
|
|
1357
|
+
assert.deepEqual(calls.insert, [], 'a group row never inserts');
|
|
1358
|
+
assert.equal(calls.close, 0, 'and the panel stays open');
|
|
1359
|
+
});
|
|
1360
|
+
});
|
|
1361
|
+
|
|
1362
|
+
describe('the tree orders fold by default with a chevron (S29)', () => {
|
|
1363
|
+
test('a chosen tree paints every group collapsed, with the collapsed chevron', async () => {
|
|
1364
|
+
const { view } = await open();
|
|
1365
|
+
view.handleInput('ctrl+o'); // tree, with the root file brand-new.ts highlighted
|
|
1366
|
+
let rows = rowsOf(view);
|
|
1367
|
+
assert.deepEqual(groupCells(rows), [' ▸ src'], 'the folder is collapsed, and its chevron paints');
|
|
1368
|
+
assert.ok(!bodyText(rows).includes('util.ts'), 'nothing below the folded folder paints');
|
|
1369
|
+
// S30 also holds here: the highlighted file has no folder to open, so the tree
|
|
1370
|
+
// paints no file row for it at all beyond the repository root.
|
|
1371
|
+
view.handleInput('ctrl+o'); // ext
|
|
1372
|
+
rows = rowsOf(view);
|
|
1373
|
+
assert.deepEqual(groupCells(rows), [' ▸ .md', ' ▾ .ts'], 'only the highlighted file extension is open');
|
|
1374
|
+
assert.ok(bodyText(rows).includes('cursor.ts'), 'the ts group paints its files');
|
|
1375
|
+
assert.ok(!bodyText(rows).includes('README.md'), 'the md group stays collapsed');
|
|
1376
|
+
});
|
|
1377
|
+
|
|
1378
|
+
test('an open group paints the expanded chevron, and the names keep their column', async () => {
|
|
1379
|
+
const { view } = await open();
|
|
1380
|
+
for (let step = 0; step < 3; step += 1) view.handleInput('down'); // src/lib/util.ts
|
|
1381
|
+
view.handleInput('ctrl+o'); // tree: src and src/lib open (S30)
|
|
1382
|
+
const cells = bodyCells(rowsOf(view));
|
|
1383
|
+
assert.deepEqual(groupCells(rowsOf(view)), [' ▾ src', ' ▾ lib']);
|
|
1384
|
+
// The chevron lives in the marker column, so a name starts three cells in (plus
|
|
1385
|
+
// one indent level per depth) on a group row AND on a file row.
|
|
1386
|
+
assert.equal(cells[0].indexOf('src'), 3);
|
|
1387
|
+
assert.equal(cells[1].indexOf('lib'), 5);
|
|
1388
|
+
assert.equal(cells[2].indexOf('util.ts'), 7);
|
|
1389
|
+
assert.equal(cells[3].indexOf('cursor.ts'), 5);
|
|
1390
|
+
assert.equal(cells[4].indexOf('README.md'), 3);
|
|
1391
|
+
assert.equal(cells[5].indexOf('brand-new.ts'), 3);
|
|
1392
|
+
});
|
|
1393
|
+
|
|
1394
|
+
test('the cursor mark stays readable next to the chevron on a group row', async () => {
|
|
1395
|
+
// S38: the cursor rests on the group row it folded, where the marker column holds
|
|
1396
|
+
// both glyphs.
|
|
1397
|
+
const entries = [{ path: 'src/a.ts', state: 'clean' }];
|
|
1398
|
+
const { view } = await open({ entries });
|
|
1399
|
+
view.handleInput('ctrl+o'); // tree: [src] a.ts
|
|
1400
|
+
view.handleInput('space'); // folds `src`, the folder holding the file
|
|
1401
|
+
const cells = bodyCells(rowsOf(view));
|
|
1402
|
+
assert.equal(cells[0], '▸▸ src', 'the cursor mark and the collapsed chevron share the three-cell marker column');
|
|
1403
|
+
assert.equal(listLine(rowsOf(view)[BODY_TOP]).length, listWidth(rowsOf(view)), 'the row keeps the pane width');
|
|
1404
|
+
});
|
|
1405
|
+
|
|
1406
|
+
test('paint and hit-testing still read one geometry with the chevrons in place', async () => {
|
|
1407
|
+
const { view } = await open();
|
|
1408
|
+
view.handleInput('ctrl+o'); // tree, every group collapsed
|
|
1409
|
+
rowsOf(view); // the host paints, which is what the hit map is built from
|
|
1410
|
+
// The first body row is the `src` group row; a click on it opens it.
|
|
1411
|
+
assert.deepEqual(view.handleMouse(mouse({ y: BODY_TOP })), { handled: true, render: true });
|
|
1412
|
+
assert.ok(bodyText(rowsOf(view)).includes('cursor.ts'), 'the click landed on the row it looks like');
|
|
1413
|
+
});
|
|
1414
|
+
});
|
|
1415
|
+
|
|
1416
|
+
describe('only the focused file path opens on an order change (S30)', () => {
|
|
1417
|
+
test('tree opens the folders holding the highlighted file and collapses the rest', async () => {
|
|
1418
|
+
const { view } = await open({ entries: NESTED });
|
|
1419
|
+
view.handleInput('down');
|
|
1420
|
+
view.handleInput('down'); // src/web/test.ts
|
|
1421
|
+
assert.equal(selectedName(rowsOf(view)), 'test.ts');
|
|
1422
|
+
view.handleInput('ctrl+o'); // tree
|
|
1423
|
+
const rows = rowsOf(view);
|
|
1424
|
+
assert.deepEqual(groupCells(rows), [' ▾ src', ' ▾ web', ' ▸ web'],
|
|
1425
|
+
'src and src/web are the only folders open, and the other `web` stays collapsed');
|
|
1426
|
+
assert.ok(bodyText(rows).includes('index.ts'), 'the folder holding the file paints its own files');
|
|
1427
|
+
assert.ok(!bodyText(rows).includes('app.ts'), 'a group the file is not in stays collapsed');
|
|
1428
|
+
assert.equal(selectedName(rows), 'test.ts', 'the highlight follows the same file');
|
|
1429
|
+
});
|
|
1430
|
+
|
|
1431
|
+
test('ext opens only the highlighted file extension group', async () => {
|
|
1432
|
+
const { view } = await open({ entries: NESTED });
|
|
1433
|
+
view.handleInput('down');
|
|
1434
|
+
view.handleInput('down'); // src/web/test.ts
|
|
1435
|
+
view.handleInput('ctrl+o'); // tree
|
|
1436
|
+
view.handleInput('ctrl+o'); // ext
|
|
1437
|
+
const rows = rowsOf(view);
|
|
1438
|
+
assert.deepEqual(groupCells(rows), [' ▸ .md', ' ▾ .ts'], 'only the `ts` group is open');
|
|
1439
|
+
assert.ok(bodyText(rows).includes('app.ts'), 'every ts file paints inside it');
|
|
1440
|
+
assert.ok(!bodyText(rows).includes('README.md'), 'the md group stays collapsed');
|
|
1441
|
+
assert.equal(selectedName(rows), 'test.ts');
|
|
1442
|
+
});
|
|
1443
|
+
|
|
1444
|
+
test('a repository-root file opens no folder in tree', async () => {
|
|
1445
|
+
const { view } = await open({ entries: NESTED });
|
|
1446
|
+
view.handleInput('home'); // README.md, at the repository root
|
|
1447
|
+
assert.equal(selectedName(rowsOf(view)), 'README.md');
|
|
1448
|
+
view.handleInput('ctrl+o'); // tree
|
|
1449
|
+
const rows = rowsOf(view);
|
|
1450
|
+
assert.deepEqual(groupCells(rows), [' ▸ src', ' ▸ web'], 'every folder stays collapsed');
|
|
1451
|
+
assert.equal(selectedName(rows), 'README.md', 'the root file still paints, and keeps the cursor');
|
|
1452
|
+
});
|
|
1453
|
+
|
|
1454
|
+
test('moving the highlight leaves the fold state the reader has', async () => {
|
|
1455
|
+
const { view } = await open({ entries: NESTED });
|
|
1456
|
+
view.handleInput('down');
|
|
1457
|
+
view.handleInput('down'); // src/web/test.ts
|
|
1458
|
+
view.handleInput('ctrl+o'); // tree: src and src/web open, the other `web` collapsed
|
|
1459
|
+
view.handleInput('down'); // src/index.ts
|
|
1460
|
+
view.handleInput('down'); // S38: the next row is the collapsed `web` group
|
|
1461
|
+
const rows = rowsOf(view);
|
|
1462
|
+
assert.equal(selectedName(rows), 'web');
|
|
1463
|
+
assert.ok(bodyText(rows).includes('index.ts'), 'the folder the reader had open stays open');
|
|
1464
|
+
assert.ok(!bodyText(rows).includes('app.ts'), 'a group the highlight moved past never opens by itself');
|
|
1465
|
+
});
|
|
1466
|
+
|
|
1467
|
+
test('choosing an order again re-seeds it, instead of the old per-order memory', async () => {
|
|
1468
|
+
const { view } = await open({ entries: NESTED });
|
|
1469
|
+
view.handleInput('down');
|
|
1470
|
+
view.handleInput('down'); // src/web/test.ts
|
|
1471
|
+
view.handleInput('ctrl+o'); // tree
|
|
1472
|
+
view.handleInput('shift+space'); // S39: collapses every group
|
|
1473
|
+
view.handleInput('shift+space'); // and the second press expands them all
|
|
1474
|
+
assert.ok(bodyText(rowsOf(view)).includes('app.ts'), 'every group is open');
|
|
1475
|
+
view.handleInput('home');
|
|
1476
|
+
view.handleInput('down');
|
|
1477
|
+
view.handleInput('down'); // back onto src/web/test.ts
|
|
1478
|
+
assert.equal(selectedName(rowsOf(view)), 'test.ts');
|
|
1479
|
+
view.handleInput('ctrl+o'); // ext
|
|
1480
|
+
view.handleInput('ctrl+o'); // files
|
|
1481
|
+
view.handleInput('ctrl+o'); // tree again
|
|
1482
|
+
const rows = rowsOf(view);
|
|
1483
|
+
assert.ok(bodyText(rows).includes('test.ts'), 'the focused file path is open');
|
|
1484
|
+
assert.ok(!bodyText(rows).includes('app.ts'), 'S30 supersedes S10: the tree re-seeds, it does not remember');
|
|
1485
|
+
});
|
|
1486
|
+
});
|
|
1487
|
+
|
|
1488
|
+
describe('group rows read in the grey role (S31)', () => {
|
|
1489
|
+
test('a folder row paints in dim, never the file row text tone', async () => {
|
|
1490
|
+
const theme = recordingTheme();
|
|
1491
|
+
const { view } = await open({ theme });
|
|
1492
|
+
view.handleInput('ctrl+o'); // tree, every group collapsed and the cursor on a file
|
|
1493
|
+
view.render(WIDTH);
|
|
1494
|
+
assert.ok(theme.calls.some((call) => call.role === 'dim' && call.text === 'src'), 'the folder name is dim');
|
|
1495
|
+
assert.ok(!theme.calls.some((call) => call.role === 'text' && call.text === 'src'), 'never the file text tone');
|
|
1496
|
+
assert.ok(theme.calls.some((call) => call.role === 'text' && call.text === 'README.md'), 'a file name keeps the text tone');
|
|
1497
|
+
});
|
|
1498
|
+
|
|
1499
|
+
test('a focused group row keeps the grey label inside the focus band', async () => {
|
|
1500
|
+
const theme = recordingTheme();
|
|
1501
|
+
const entries = [{ path: 'src/a.ts', state: 'clean' }];
|
|
1502
|
+
const { view } = await open({ theme, entries });
|
|
1503
|
+
view.handleInput('ctrl+o'); // tree: [src] a.ts
|
|
1504
|
+
view.handleInput('space'); // folds src; the cursor rests on the group row
|
|
1505
|
+
theme.calls.length = 0;
|
|
1506
|
+
view.render(WIDTH);
|
|
1507
|
+
assert.ok(theme.calls.some((call) => call.role === 'dim' && call.text === 'src'), 'the focused folder is still grey');
|
|
1508
|
+
assert.ok(
|
|
1509
|
+
theme.calls.some((call) => call.role === 'bg:selectedBg' && call.text.includes('\x1b[2msrc')),
|
|
1510
|
+
'and the focus band is wrapped around that grey label',
|
|
1511
|
+
);
|
|
1512
|
+
});
|
|
1513
|
+
|
|
1514
|
+
test('the chevron, the marker and the row width are unchanged', async () => {
|
|
1515
|
+
const theme = recordingTheme();
|
|
1516
|
+
const { view } = await open({ theme });
|
|
1517
|
+
view.handleInput('ctrl+o');
|
|
1518
|
+
const rows = rowsOf(view);
|
|
1519
|
+
assert.equal(listLine(rows[BODY_TOP]).length, listWidth(rows), 'the group row keeps the pane width');
|
|
1520
|
+
assert.ok(!theme.calls.some((call) => call.text === '\u25be' || call.text === '\u25b8'), 'the chevron and the marker stay unpainted');
|
|
1521
|
+
});
|
|
1522
|
+
});
|
|
1523
|
+
|
|
1524
|
+
describe('space folds only where the order paints groups (S32)', () => {
|
|
1525
|
+
test('in the flat files order space does nothing at all', async () => {
|
|
1526
|
+
const { view, calls } = await open();
|
|
1527
|
+
const before = rowsOf(view);
|
|
1528
|
+
const renders = calls.render;
|
|
1529
|
+
view.handleInput('space');
|
|
1530
|
+
assert.deepEqual(rowsOf(view), before, 'no fold, no cursor move and no query character');
|
|
1531
|
+
assert.equal(calls.render, renders, 'nothing changed, so nothing repaints');
|
|
1532
|
+
});
|
|
1533
|
+
|
|
1534
|
+
test('the footer names the fold keys only while the order paints groups', async () => {
|
|
1535
|
+
const { view } = await open();
|
|
1536
|
+
for (const [order, action] of [
|
|
1537
|
+
['files', undefined],
|
|
1538
|
+
['tree', 'shift+space expand all'],
|
|
1539
|
+
['ext', 'shift+space collapse all'],
|
|
1540
|
+
['files', undefined],
|
|
1541
|
+
]) {
|
|
1542
|
+
const footer = footerOf(rowsOf(view, 200));
|
|
1543
|
+
if (action === undefined) {
|
|
1544
|
+
assert.ok(!footer.includes('space') && !footer.includes('fold'), `the ${order} footer names no fold key: ${footer}`);
|
|
1545
|
+
} else {
|
|
1546
|
+
assert.ok(footer.includes('space fold'), `the ${order} footer names space fold: ${footer}`);
|
|
1547
|
+
assert.ok(footer.includes(action), `the ${order} footer names ${action}: ${footer}`);
|
|
1548
|
+
}
|
|
1549
|
+
view.handleInput('ctrl+o');
|
|
1550
|
+
}
|
|
1551
|
+
});
|
|
1552
|
+
});
|
|
1553
|
+
|
|
1554
|
+
describe('shift+space is one toggle over every group (S39)', () => {
|
|
1555
|
+
test('it collapses EVERY group, the ones holding the focused file included, and parks the cursor on the group that held it', async () => {
|
|
1556
|
+
const { view, calls } = await open({ entries: NESTED });
|
|
1557
|
+
view.handleInput('down');
|
|
1558
|
+
view.handleInput('down'); // src/web/test.ts
|
|
1559
|
+
view.handleInput('ctrl+o'); // tree: src and src/web open, the other `web` collapsed
|
|
1560
|
+
assert.equal(selectedName(rowsOf(view)), 'test.ts');
|
|
1561
|
+
view.handleInput('shift+space');
|
|
1562
|
+
let rows = rowsOf(view);
|
|
1563
|
+
assert.ok(!bodyText(rows).includes('test.ts'), 'the folders holding the focused file collapse too');
|
|
1564
|
+
assert.ok(!bodyText(rows).includes('app.ts'), 'and so does every other group');
|
|
1565
|
+
assert.deepEqual(groupCells(rows), ['▸▸ src', ' ▸ web'], 'every group row paints collapsed, and the cursor rests on src');
|
|
1566
|
+
// S39: the group that held the file keeps the cursor. In a nested tree the
|
|
1567
|
+
// deepest holder (`src/web`) is hidden by its own collapse, so the cursor rests
|
|
1568
|
+
// on the nearest group row above it that still paints — `src`.
|
|
1569
|
+
assert.equal(selectedName(rows), 'src', 'the cursor rests on the group row that held the file');
|
|
1570
|
+
assert.deepEqual(calls.insert, []);
|
|
1571
|
+
assert.equal(calls.close, 0);
|
|
1572
|
+
// The same key now expands every group, and the cursor stays on its row.
|
|
1573
|
+
view.handleInput('shift+space');
|
|
1574
|
+
rows = rowsOf(view);
|
|
1575
|
+
assert.ok(bodyText(rows).includes('app.ts'), 'every group is open again');
|
|
1576
|
+
assert.ok(bodyText(rows).includes('test.ts'));
|
|
1577
|
+
assert.equal(selectedName(rows), 'src', 'the group row under the cursor stays the one the file came from');
|
|
1578
|
+
});
|
|
1579
|
+
|
|
1580
|
+
test('a cursor already on a group row keeps that row across both directions', async () => {
|
|
1581
|
+
const entries = [{ path: 'src/a.ts', state: 'clean' }, { path: 'src/b.ts', state: 'clean' }];
|
|
1582
|
+
const { view } = await open({ entries });
|
|
1583
|
+
view.handleInput('ctrl+o'); // tree: src open, a.ts b.ts
|
|
1584
|
+
view.handleInput('home'); // the src group row
|
|
1585
|
+
view.handleInput('shift+space');
|
|
1586
|
+
let rows = rowsOf(view);
|
|
1587
|
+
assert.equal(selectedName(rows), 'src', 'the focused group row keeps the cursor');
|
|
1588
|
+
assert.ok(!bodyText(rows).includes('a.ts'), 'and every group is collapsed');
|
|
1589
|
+
view.handleInput('shift+space');
|
|
1590
|
+
rows = rowsOf(view);
|
|
1591
|
+
assert.ok(bodyText(rows).includes('a.ts'), 'the second press expands every group');
|
|
1592
|
+
assert.equal(selectedName(rows), 'src', 'with the cursor still on its row');
|
|
1593
|
+
});
|
|
1594
|
+
|
|
1595
|
+
test('a repository-root file has no group to park on, so the cursor keeps its own row', async () => {
|
|
1596
|
+
const entries = [{ path: 'src/a.ts', state: 'clean' }, { path: 'README.md', state: 'clean' }];
|
|
1597
|
+
const { view } = await open({ entries });
|
|
1598
|
+
view.handleInput('ctrl+o'); // tree with the root file focused: every group collapsed
|
|
1599
|
+
assert.equal(selectedName(rowsOf(view)), 'README.md');
|
|
1600
|
+
view.handleInput('shift+space'); // every group is collapsed, so this expands them
|
|
1601
|
+
const rows = rowsOf(view);
|
|
1602
|
+
assert.ok(bodyText(rows).includes('a.ts'), 'every group opened');
|
|
1603
|
+
assert.equal(selectedName(rows), 'README.md', 'the row the reader was on stays under the cursor');
|
|
1604
|
+
});
|
|
1605
|
+
|
|
1606
|
+
test('in ext it collapses the focused extension group too and parks on it', async () => {
|
|
1607
|
+
const { view } = await open({ entries: NESTED });
|
|
1608
|
+
view.handleInput('down');
|
|
1609
|
+
view.handleInput('down'); // src/web/test.ts
|
|
1610
|
+
view.handleInput('ctrl+o'); // tree
|
|
1611
|
+
view.handleInput('ctrl+o'); // ext: only .ts open
|
|
1612
|
+
assert.equal(selectedName(rowsOf(view)), 'test.ts');
|
|
1613
|
+
view.handleInput('shift+space');
|
|
1614
|
+
let rows = rowsOf(view);
|
|
1615
|
+
assert.ok(!bodyText(rows).includes('test.ts'), 'the focused extension group collapses too');
|
|
1616
|
+
assert.equal(selectedName(rows), '.ts', 'the cursor rests on the extension group that held the file');
|
|
1617
|
+
view.handleInput('shift+space');
|
|
1618
|
+
rows = rowsOf(view);
|
|
1619
|
+
assert.ok(bodyText(rows).includes('README.md'), 'every extension group opens again');
|
|
1620
|
+
assert.equal(selectedName(rows), '.ts', 'with the cursor still on that group row');
|
|
1621
|
+
});
|
|
1622
|
+
|
|
1623
|
+
test('in the flat files order it does nothing', async () => {
|
|
1624
|
+
const { view, calls } = await open();
|
|
1625
|
+
const before = rowsOf(view);
|
|
1626
|
+
const renders = calls.render;
|
|
1627
|
+
view.handleInput('shift+space');
|
|
1628
|
+
assert.deepEqual(rowsOf(view), before);
|
|
1629
|
+
assert.equal(calls.render, renders);
|
|
1630
|
+
});
|
|
1631
|
+
|
|
1632
|
+
test('the host delivers shift+space as a CSI-u or modifyOtherKeys sequence', { skip: !TUI_AVAILABLE }, async () => {
|
|
1633
|
+
const tui = await import('@earendil-works/pi-tui');
|
|
1634
|
+
// Kitty keyboard protocol: codepoint 32 (space) with modifier 2 = shift.
|
|
1635
|
+
assert.equal(tui.matchesKey('\x1b[32;2u', 'shift+space'), true);
|
|
1636
|
+
// xterm modifyOtherKeys when the Kitty protocol is not enabled.
|
|
1637
|
+
assert.equal(tui.matchesKey('\x1b[27;2;32~', 'shift+space'), true);
|
|
1638
|
+
// A legacy terminal cannot tell it from a plain space, which stays the fold key.
|
|
1639
|
+
assert.equal(tui.matchesKey(' ', 'shift+space'), false);
|
|
1640
|
+
assert.equal(tui.matchesKey(' ', 'space'), true);
|
|
1641
|
+
|
|
1642
|
+
const { view } = await open({ entries: NESTED, helpers: { ...helpers, matchesKey: tui.matchesKey } });
|
|
1643
|
+
view.handleInput('\x1b[B');
|
|
1644
|
+
view.handleInput('\x1b[B'); // raw down arrow to src/web/test.ts
|
|
1645
|
+
view.handleInput('\x0f'); // raw ctrl+o
|
|
1646
|
+
assert.ok(!bodyText(rowsOf(view)).includes('app.ts'));
|
|
1647
|
+
view.handleInput('\x1b[32;2u');
|
|
1648
|
+
assert.ok(!bodyText(rowsOf(view)).includes('app.ts'), 'the kitty sequence reaches the fold-all key');
|
|
1649
|
+
view.handleInput('\x1b[27;2;32~');
|
|
1650
|
+
assert.ok(bodyText(rowsOf(view)).includes('app.ts'), 'so does the modifyOtherKeys one');
|
|
1651
|
+
});
|
|
1652
|
+
});
|
|
1653
|
+
|
|
1654
|
+
describe('the fold-all legend states the action it performs (S40)', () => {
|
|
1655
|
+
test('it names expand all while every group is collapsed, and collapse all otherwise', async () => {
|
|
1656
|
+
const { view } = await open({ entries: NESTED });
|
|
1657
|
+
// The flat order names neither fold key (S32 stands).
|
|
1658
|
+
let footer = footerOf(rowsOf(view, 200));
|
|
1659
|
+
assert.ok(!footer.includes('space') && !footer.includes('fold'), `the flat footer names no fold key: ${footer}`);
|
|
1660
|
+
|
|
1661
|
+
view.handleInput('ctrl+o'); // tree, with a root file focused: every group is collapsed
|
|
1662
|
+
footer = footerOf(rowsOf(view, 200));
|
|
1663
|
+
assert.ok(footer.includes('space fold'), footer);
|
|
1664
|
+
assert.ok(footer.includes('shift+space expand all'), footer);
|
|
1665
|
+
assert.ok(!footer.includes('collapse all'), footer);
|
|
1666
|
+
|
|
1667
|
+
view.handleInput('shift+space');
|
|
1668
|
+
footer = footerOf(rowsOf(view, 200));
|
|
1669
|
+
assert.ok(footer.includes('shift+space collapse all'), footer);
|
|
1670
|
+
assert.ok(!footer.includes('expand all'), footer);
|
|
1671
|
+
|
|
1672
|
+
// A hand-folded group makes the tree mixed, so the legend says it would collapse.
|
|
1673
|
+
view.handleInput('home');
|
|
1674
|
+
view.handleInput('space'); // folds `src` from its own row
|
|
1675
|
+
footer = footerOf(rowsOf(view, 200));
|
|
1676
|
+
assert.ok(footer.includes('shift+space collapse all'), `a mixed tree would collapse: ${footer}`);
|
|
1677
|
+
|
|
1678
|
+
// ext paints the same two states.
|
|
1679
|
+
view.handleInput('ctrl+o'); // ext, every group collapsed (the cursor came from a group row)
|
|
1680
|
+
footer = footerOf(rowsOf(view, 200));
|
|
1681
|
+
assert.ok(footer.includes('shift+space expand all'), `ext starts collapsed: ${footer}`);
|
|
1682
|
+
view.handleInput('shift+space');
|
|
1683
|
+
footer = footerOf(rowsOf(view, 200));
|
|
1684
|
+
assert.ok(footer.includes('shift+space collapse all'), `ext now shows the other action: ${footer}`);
|
|
1685
|
+
|
|
1686
|
+
// And the flat order drops both tokens again.
|
|
1687
|
+
view.handleInput('ctrl+o');
|
|
1688
|
+
footer = footerOf(rowsOf(view, 200));
|
|
1689
|
+
assert.ok(!footer.includes('space') && !footer.includes('fold'), `the flat footer names no fold key: ${footer}`);
|
|
1690
|
+
});
|
|
1691
|
+
|
|
1692
|
+
test('a query holds every group open, so the legend offers to collapse them', async () => {
|
|
1693
|
+
const { view } = await open({ entries: NESTED });
|
|
1694
|
+
view.handleInput('ctrl+o'); // tree, every group collapsed
|
|
1695
|
+
for (const character of 'app') view.handleInput(character);
|
|
1696
|
+
const footer = footerOf(rowsOf(view, 200));
|
|
1697
|
+
assert.ok(footer.includes('shift+space collapse all'), footer);
|
|
1698
|
+
});
|
|
1699
|
+
});
|
|
1700
|
+
|
|
1701
|
+
describe('the body geometry (S25)', () => {
|
|
1702
|
+
test('the preview box rides the info row, closes on the list last row and a rule closes the body', async () => {
|
|
1703
|
+
const { view } = await open();
|
|
1704
|
+
const rows = rowsOf(view);
|
|
1705
|
+
assert.equal(rows.length, CARD_HEIGHT, 'the card keeps its height budget');
|
|
1706
|
+
const top = previewTop(rows);
|
|
1707
|
+
assert.ok(top.startsWith('╭'), top);
|
|
1708
|
+
assert.ok(top.endsWith('1/2╮'), `the position rides the box top on the info row: ${top}`);
|
|
1709
|
+
assert.match(previewPane(rows, BODY_ROWS - 1), /^╰─+╯$/, 'the box closes on the list last body row');
|
|
1710
|
+
assert.equal(listWidth(rows), paneWidths().list, 'the list keeps its share');
|
|
1711
|
+
assert.ok(helpers.visibleWidth(previewTop(rows)) === paneWidths().preview, 'the box keeps the preview width');
|
|
1712
|
+
assert.equal(strip(rows[RULE_ROW]), `│ ${'─'.repeat(WIDTH - 4)} │`, 'one rule closes the body under both columns');
|
|
1713
|
+
assert.ok(footerOf(rows).includes('esc'), 'the footer follows the rule');
|
|
1714
|
+
assert.equal(RULE_ROW + 2, rows.length - 1, 'the rule, the footer and the bottom rule are the last three rows');
|
|
1715
|
+
// The boxed pane keeps `bodyRows - 1` content rows.
|
|
1716
|
+
assert.match(previewPane(rows, 0), /^│1 preview of brand-new\.ts/, 'the first content row is the file first line');
|
|
1717
|
+
assert.match(previewPane(rows, BODY_ROWS - 2), /^│ +│$/, 'the last content row is an empty row inside the box');
|
|
1718
|
+
for (const row of rows) assert.equal(helpers.visibleWidth(row), WIDTH, 'every row still one terminal line');
|
|
1719
|
+
// Painting and hit-testing read one geometry: the click lands on the row it sees.
|
|
1720
|
+
const target = rowOf(rows, 'README.md');
|
|
1721
|
+
assert.deepEqual(view.handleMouse(mouse({ y: target })), { handled: true, render: true });
|
|
1722
|
+
assert.equal(selectedName(rowsOf(view)), 'README.md');
|
|
1723
|
+
});
|
|
1724
|
+
|
|
1725
|
+
test('the unboxed fallback fills the same rows on a body too short for a box', async () => {
|
|
1726
|
+
const { view } = await open({ rowsAvailable: 9 });
|
|
1727
|
+
const rows = rowsOf(view);
|
|
1728
|
+
assert.equal(rows.length, 7, 'the card keeps its height budget');
|
|
1729
|
+
const top = previewTop(rows);
|
|
1730
|
+
assert.ok(!top.includes('╭'), `no box at this height: ${top}`);
|
|
1731
|
+
assert.ok(top.trimEnd().endsWith('1/2'), `the position still rides the info row: ${top}`);
|
|
1732
|
+
assert.match(previewPane(rows, 0), /^1 preview of brand-new\.ts/, 'the one content row is the file first line');
|
|
1733
|
+
assert.ok(!previewPane(rows, 0).includes('╭'));
|
|
1734
|
+
const bodyRows = rows.length - 6;
|
|
1735
|
+
assert.equal(strip(rows[BODY_TOP + bodyRows]).startsWith('│ ─'), true, 'the rule still closes the body');
|
|
1736
|
+
});
|
|
1737
|
+
|
|
1738
|
+
test('the info row counts as part of the preview for the wheel and the click', async () => {
|
|
1739
|
+
const long = Array.from({ length: 60 }, (_, index) => `line ${index}`);
|
|
1740
|
+
const { view } = await open({ loadPreview: async () => preview(long) });
|
|
1741
|
+
const rows = rowsOf(view);
|
|
1742
|
+
const previewX = previewStart(rows) + 2;
|
|
1743
|
+
assert.deepEqual(
|
|
1744
|
+
view.handleMouse(mouse({ type: 'wheel', button: 'none', wheelDelta: 1, x: previewX, y: INFO_ROW })),
|
|
1745
|
+
{ handled: true, render: true },
|
|
1746
|
+
'the wheel over the box top scrolls the preview',
|
|
1747
|
+
);
|
|
1748
|
+
assert.match(previewPane(rowsOf(view), 0), /^│ 2 line 1/);
|
|
1749
|
+
assert.deepEqual(
|
|
1750
|
+
view.handleMouse(mouse({ x: previewX, y: INFO_ROW })),
|
|
1751
|
+
{ handled: true, render: false },
|
|
1752
|
+
'a click on the box top is absorbed and moves nothing',
|
|
1753
|
+
);
|
|
1754
|
+
assert.match(previewPane(rowsOf(view), 0), /^│ 2 line 1/);
|
|
1755
|
+
});
|
|
1756
|
+
});
|
|
1757
|
+
|
|
1758
|
+
describe('the Tab mark bar (S26)', () => {
|
|
1759
|
+
test('a marked row paints its bar in a theme role whether it is focused or idle', async () => {
|
|
1760
|
+
const theme = recordingTheme();
|
|
1761
|
+
const { view } = await open({ theme });
|
|
1762
|
+
view.handleInput('tab'); // the highlighted row is marked AND focused
|
|
1763
|
+
let rows = rowsOf(view);
|
|
1764
|
+
const focused = view.render(WIDTH)[rowOf(rows, 'brand-new.ts')];
|
|
1765
|
+
assert.ok(strip(focused).includes(CURSOR_MARK), 'the marked row is the focused one');
|
|
1766
|
+
assert.notEqual(sgrAt(focused, SELECTION_MARK), '', 'the focused marked row paints its bar');
|
|
1767
|
+
view.handleInput('down'); // the marked row is idle now
|
|
1768
|
+
rows = rowsOf(view);
|
|
1769
|
+
const idle = view.render(WIDTH)[rowOf(rows, 'brand-new.ts')];
|
|
1770
|
+
assert.ok(!strip(idle).includes(CURSOR_MARK), 'the marked row is no longer focused');
|
|
1771
|
+
assert.ok(strip(idle).includes(SELECTION_MARK), 'its bar is still painted');
|
|
1772
|
+
assert.notEqual(sgrAt(idle, SELECTION_MARK), '', 'the idle marked row paints its bar too');
|
|
1773
|
+
assert.ok(
|
|
1774
|
+
theme.calls.some((call) => call.role === 'accent' && call.text === SELECTION_MARK),
|
|
1775
|
+
'the idle bar carries the theme key role, never an unstyled cell',
|
|
1776
|
+
);
|
|
1777
|
+
assert.equal(listCell(rows, 'brand-new.ts').indexOf('brand-new.ts'), 3, 'the marker column never moves');
|
|
1778
|
+
});
|
|
1779
|
+
|
|
1780
|
+
test('an unmarked row paints no bar and keeps the marker column', async () => {
|
|
1781
|
+
const theme = recordingTheme();
|
|
1782
|
+
const { view } = await open({ theme });
|
|
1783
|
+
view.handleInput('down');
|
|
1784
|
+
const rows = rowsOf(view);
|
|
1785
|
+
assert.ok(!bodyText(rows).includes(SELECTION_MARK), 'nothing is marked');
|
|
1786
|
+
assert.equal(listCell(rows, 'README.md').indexOf('README.md'), 3);
|
|
1787
|
+
assert.ok(!theme.calls.some((call) => call.text === SELECTION_MARK), 'no bar is painted at all');
|
|
1788
|
+
});
|
|
1789
|
+
});
|
|
1790
|
+
|
|
1791
|
+
describe('the preview pane (S11, S12 as composed)', () => {
|
|
1792
|
+
test('the preview sits in its own boxed pane with a gutter and its position', async () => {
|
|
1793
|
+
const { view } = await open();
|
|
1794
|
+
const rows = rowsOf(view);
|
|
1795
|
+
const top = previewTop(rows);
|
|
1796
|
+
assert.ok(top.startsWith('╭'), top);
|
|
1797
|
+
assert.ok(top.endsWith('1/2╮'), top);
|
|
1798
|
+
assert.match(previewPane(rows, 0), /^│1 preview of brand-new\.ts/, 'the gutter numbers the first line');
|
|
1799
|
+
assert.match(previewPane(rows, 1), /^│2 second line/);
|
|
1800
|
+
assert.match(previewPane(rows, BODY_ROWS - 1), /^╰─+╯$/, 'the box closes on the list last body row (S25)');
|
|
1801
|
+
for (const row of rows) assert.equal(helpers.visibleWidth(row), WIDTH, 'the box never makes a row ragged');
|
|
1802
|
+
});
|
|
1803
|
+
|
|
1804
|
+
test('a pending preview paints its own notice and lands without a second read', async () => {
|
|
1805
|
+
let reads = 0;
|
|
1806
|
+
const mounted = mount({ loadPreview: async () => { reads += 1; return preview(['landed']); } });
|
|
1807
|
+
mounted.view.render(WIDTH);
|
|
1808
|
+
await tick();
|
|
1809
|
+
mounted.view.render(WIDTH);
|
|
1810
|
+
assert.ok(bodyText(rowsOf(mounted.view)).includes('Loading preview'), 'the pending read asks for nothing it does not have');
|
|
1811
|
+
await tick();
|
|
1812
|
+
const rows = rowsOf(mounted.view);
|
|
1813
|
+
assert.ok(bodyText(rows).includes('landed'));
|
|
1814
|
+
assert.equal(reads, 1, 'one read per highlighted file');
|
|
1815
|
+
mounted.view.render(WIDTH);
|
|
1816
|
+
mounted.view.render(WIDTH);
|
|
1817
|
+
assert.equal(reads, 1);
|
|
1818
|
+
});
|
|
1819
|
+
|
|
1820
|
+
test('the highlighter runs once per preview, never per repaint', async () => {
|
|
1821
|
+
let paints = 0;
|
|
1822
|
+
const { view } = await open({
|
|
1823
|
+
highlight: (code) => {
|
|
1824
|
+
paints += 1;
|
|
1825
|
+
return code.split('\n').map((line) => `\x1b[33m${line}\x1b[39m`);
|
|
1826
|
+
},
|
|
1827
|
+
languageForPath: () => 'ts',
|
|
1828
|
+
});
|
|
1829
|
+
assert.equal(paints, 1, 'the preview is highlighted once when it lands');
|
|
1830
|
+
view.render(WIDTH);
|
|
1831
|
+
view.render(WIDTH);
|
|
1832
|
+
view.handleInput('tab');
|
|
1833
|
+
assert.equal(paints, 1, 'a repaint never pays for the highlighter again');
|
|
1834
|
+
});
|
|
1835
|
+
|
|
1836
|
+
test('a binary preview and a failed read paint their own sentences', async () => {
|
|
1837
|
+
const binary = await open({ loadPreview: async () => ({ kind: 'binary', message: 'Binary file \u2014 preview not available.' }) });
|
|
1838
|
+
assert.ok(bodyText(rowsOf(binary.view)).includes('Binary file'), 'the binary notice is painted as it is');
|
|
1839
|
+
assert.ok(!bodyText(rowsOf(binary.view)).includes('/2'), 'a binary preview claims no line position');
|
|
1840
|
+
|
|
1841
|
+
const failed = await open({ loadPreview: async () => { throw new Error('denied'); } });
|
|
1842
|
+
assert.ok(bodyText(rowsOf(failed.view)).includes('Cannot read brand-new.ts: denied.'), bodyText(rowsOf(failed.view)));
|
|
1843
|
+
assert.equal(failed.calls.close, 0, 'a failed preview never closes the panel');
|
|
1844
|
+
});
|
|
1845
|
+
});
|
|
1846
|
+
|
|
1847
|
+
describe('degradations (S1, S15)', () => {
|
|
1848
|
+
test('a hostile theme and an absent theme still paint every row at the requested width', async () => {
|
|
1849
|
+
const hostile = {
|
|
1850
|
+
fg() { throw new Error('no colour'); },
|
|
1851
|
+
bold() { throw new Error('no bold'); },
|
|
1852
|
+
bg() { throw new Error('no band'); },
|
|
1853
|
+
};
|
|
1854
|
+
const painted = await open({ theme: hostile });
|
|
1855
|
+
const rows = rowsOf(painted.view);
|
|
1856
|
+
assert.equal(rows.length, CARD_HEIGHT);
|
|
1857
|
+
for (const row of rows) assert.equal(helpers.visibleWidth(row), WIDTH);
|
|
1858
|
+
assert.ok(rows[BODY_TOP].includes('brand-new.ts'));
|
|
1859
|
+
|
|
1860
|
+
const absent = await open({ theme: null });
|
|
1861
|
+
assert.ok(rowsOf(absent.view)[BODY_TOP].includes('brand-new.ts'));
|
|
1862
|
+
assert.ok(footerOf(rowsOf(absent.view)).includes('esc'));
|
|
1863
|
+
});
|
|
1864
|
+
|
|
1865
|
+
test('an unwritable terminal sequence in the scope path never reaches the frame', async () => {
|
|
1866
|
+
const { view } = await open({ scope: { root: '/repo/evil\x1b[31mred\x07/x', kind: 'main', label: 'main' } });
|
|
1867
|
+
const top = view.render(WIDTH)[0];
|
|
1868
|
+
assert.ok(!top.includes('\x1b'), 'no escape sequence is painted');
|
|
1869
|
+
assert.ok(!top.includes('\x07'));
|
|
1870
|
+
assert.ok(strip(top).includes('evilred'), strip(top));
|
|
1871
|
+
assert.equal(helpers.visibleWidth(top), WIDTH);
|
|
1872
|
+
});
|
|
1873
|
+
|
|
1874
|
+
test('a missing listing reader and a missing preview reader keep the panel alive', async () => {
|
|
1875
|
+
const noListing = createFilesPickerView({
|
|
1876
|
+
theme: plainTheme,
|
|
1877
|
+
helpers,
|
|
1878
|
+
rowsAvailable: ROWS_AVAILABLE,
|
|
1879
|
+
loadEntries: null,
|
|
1880
|
+
loadPreview: async () => preview(['x']),
|
|
1881
|
+
});
|
|
1882
|
+
await tick();
|
|
1883
|
+
assert.ok(bodyText(rowsOf(noListing)).includes('no listing reader'));
|
|
1884
|
+
|
|
1885
|
+
const noPreview = await open({ loadPreview: null });
|
|
1886
|
+
assert.ok(bodyText(rowsOf(noPreview.view)).includes('Cannot read brand-new.ts: no preview reader was supplied.'));
|
|
1887
|
+
assert.equal(noPreview.calls.close, 0);
|
|
1888
|
+
});
|
|
1889
|
+
});
|