@kabmo-labs/kabmo 0.9.0 → 0.10.0
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 +45 -0
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +333 -333
- package/dist/client/static/js/index-18xe7655.css +1 -0
- package/dist/client/static/js/{index-bpptfkz2.js → index-nxpe7835.js} +768 -763
- package/package.json +3 -1
- package/src/client/components/common/code-surface/bracket-guide.test.ts +249 -0
- package/src/client/components/common/code-surface/bracket-guide.ts +131 -0
- package/src/client/components/common/code-surface/documents.test.ts +5 -3
- package/src/client/components/common/code-surface/documents.ts +85 -0
- package/src/client/components/common/code-surface/extensions.test.ts +5 -0
- package/src/client/components/common/code-surface/extensions.ts +140 -7
- package/src/client/components/common/code-surface/fold-stack.test.ts +218 -0
- package/src/client/components/common/code-surface/fold.test.ts +148 -0
- package/src/client/components/common/code-surface/fold.ts +118 -0
- package/src/client/components/common/code-surface/indent-guide.ts +104 -0
- package/src/client/components/common/code-surface/indent.test.ts +239 -0
- package/src/client/components/common/code-surface/indent.ts +124 -0
- package/src/client/components/common/code-surface/index.tsx +76 -46
- package/src/client/components/common/code-surface/keymap.ts +12 -23
- package/src/client/components/common/code-surface/line-commands.test.ts +90 -0
- package/src/client/components/common/code-surface/line-commands.ts +103 -0
- package/src/client/components/common/code-surface/props.ts +87 -0
- package/src/client/components/common/code-surface/stream-language.test.ts +118 -0
- package/src/client/components/common/code-surface/stream-language.ts +123 -0
- package/src/client/components/common/code-surface/theme.test.ts +40 -5
- package/src/client/components/common/code-surface/theme.ts +113 -0
- package/src/client/components/common/code-surface/typing.test.ts +97 -0
- package/src/client/components/common/code-surface/typing.ts +111 -0
- package/src/client/components/common/toolbar-row/index.test.tsx +53 -4
- package/src/client/components/common/toolbar-row/index.tsx +101 -30
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +17 -0
- package/src/client/components/layout/desktop-layout/index.tsx +18 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +35 -33
- package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +20 -1
- package/src/client/components/mobile/mobile-right-sidebar/editor-props.ts +25 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +6 -0
- package/src/client/components/settings/categories/appearance-settings/EditorIndentSection.tsx +87 -0
- package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +99 -0
- package/src/client/components/workspace/chat-timeline/chat-input/expansion.ts +9 -4
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +15 -11
- package/src/client/components/workspace/chat-timeline/chat-input/stretch-send.test.tsx +165 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.test.ts +17 -3
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.tsx +10 -6
- package/src/client/components/workspace/editor/Body.tsx +24 -0
- package/src/client/components/workspace/editor/CommandPalette.tsx +4 -4
- package/src/client/components/workspace/editor/ConflictStrip.tsx +77 -0
- package/src/client/components/workspace/editor/Dialogs.tsx +53 -0
- package/src/client/components/workspace/editor/EmptyEditor.tsx +23 -0
- package/src/client/components/workspace/editor/ExternalChangeStrip.tsx +61 -0
- package/src/client/components/workspace/editor/FileDocument.tsx +89 -1
- package/src/client/components/workspace/editor/FilePane.tsx +43 -0
- package/src/client/components/workspace/editor/FindWidget.test.ts +9 -5
- package/src/client/components/workspace/editor/FindWidget.tsx +29 -0
- package/src/client/components/workspace/editor/GoToLineModal.tsx +123 -0
- package/src/client/components/workspace/editor/Notices.tsx +71 -0
- package/src/client/components/workspace/editor/Pane.tsx +118 -0
- package/src/client/components/workspace/editor/PluginColumn.tsx +32 -0
- package/src/client/components/workspace/editor/QuickOpenModal.tsx +146 -0
- package/src/client/components/workspace/editor/SaveAsModal.tsx +175 -0
- package/src/client/components/workspace/editor/SplitColumn.tsx +98 -0
- package/src/client/components/workspace/editor/SplitPane.tsx +57 -0
- package/src/client/components/workspace/editor/StatusBar.tsx +106 -0
- package/src/client/components/workspace/editor/TabContextMenu.tsx +75 -0
- package/src/client/components/workspace/editor/Tabs.tsx +195 -18
- package/src/client/components/workspace/editor/Toolbar.tsx +54 -181
- package/src/client/components/workspace/editor/index.tsx +199 -189
- package/src/client/components/workspace/editor/props.ts +64 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +300 -0
- package/src/client/components/workspace/file-explorer/Modals.tsx +14 -1
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +2 -1
- package/src/client/components/workspace/file-explorer/clipboard.test.ts +3 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +61 -0
- package/src/client/components/workspace/file-explorer/index.tsx +10 -48
- package/src/client/components/workspace/file-explorer/local-edit.test.ts +8 -3
- package/src/client/components/workspace/search-panel/Body.tsx +6 -1
- package/src/client/hooks/chat/composer/file-drop.ts +22 -37
- package/src/client/hooks/chat/composer/pipeline.test.ts +76 -0
- package/src/client/hooks/chat/composer/pipeline.ts +12 -1
- package/src/client/hooks/editor/caret-position.test.ts +58 -0
- package/src/client/hooks/editor/caret-position.ts +48 -0
- package/src/client/hooks/editor/file-editor-types.ts +200 -0
- package/src/client/hooks/editor/find-history.test.ts +132 -0
- package/src/client/hooks/editor/find-history.ts +46 -0
- package/src/client/hooks/editor/find-selection-range.test.ts +100 -0
- package/src/client/hooks/editor/find-selection-range.ts +49 -0
- package/src/client/hooks/editor/find-state.ts +13 -0
- package/src/client/hooks/editor/font.test.ts +0 -93
- package/src/client/hooks/editor/indent-settings.test.ts +104 -0
- package/src/client/hooks/editor/indent-settings.ts +88 -0
- package/src/client/hooks/editor/quick-open.test.ts +141 -0
- package/src/client/hooks/editor/quick-open.ts +127 -0
- package/src/client/hooks/editor/save-as.test.ts +156 -0
- package/src/client/hooks/editor/save-as.ts +122 -0
- package/src/client/hooks/editor/save-file.test.ts +179 -0
- package/src/client/hooks/editor/save-file.ts +73 -28
- package/src/client/hooks/editor/typing-settings.test.ts +73 -0
- package/src/client/hooks/editor/typing-settings.ts +65 -0
- package/src/client/hooks/editor/use-close-guard.ts +98 -0
- package/src/client/hooks/editor/use-editor-drop-overlay.test.ts +159 -0
- package/src/client/hooks/editor/use-editor-drop.shell.test.ts +224 -0
- package/src/client/hooks/editor/use-editor-drop.ts +58 -68
- package/src/client/hooks/editor/use-editor-find.test.ts +2 -2
- package/src/client/hooks/editor/use-editor-find.ts +38 -3
- package/src/client/hooks/editor/use-editor-panel-keys.ts +152 -0
- package/src/client/hooks/editor/use-editor-tab-state.ts +71 -0
- package/src/client/hooks/editor/use-external-change-notice.ts +71 -0
- package/src/client/hooks/editor/use-external-change.test.ts +88 -0
- package/src/client/hooks/editor/use-external-change.ts +146 -0
- package/src/client/hooks/editor/use-file-editor.ts +83 -116
- package/src/client/hooks/editor/use-file-read.ts +16 -8
- package/src/client/hooks/editor/use-file-writes.ts +28 -3
- package/src/client/hooks/editor/use-mobile-editor-find.ts +69 -0
- package/src/client/hooks/editor/use-mobile-reveal.ts +53 -0
- package/src/client/hooks/editor/use-search-reveal-jump.ts +57 -0
- package/src/client/hooks/editor/use-split-editor.test.tsx +169 -0
- package/src/client/hooks/editor/use-split-editor.ts +91 -0
- package/src/client/hooks/editor/use-unload-guard.tsx +117 -0
- package/src/client/hooks/editor/use-write-conflict.test.ts +164 -0
- package/src/client/hooks/editor/use-write-conflict.ts +152 -0
- package/src/client/hooks/editor/wheel-zoom.test.ts +141 -0
- package/src/client/hooks/editor/wheel-zoom.ts +96 -0
- package/src/client/hooks/ui/drag-presence.test.ts +193 -0
- package/src/client/hooks/ui/drag-presence.ts +108 -0
- package/src/client/hooks/ui/settings-modal.test.ts +115 -0
- package/src/client/hooks/workspace/file-listing.ts +36 -24
- package/src/client/hooks/workspace/file-tabs.test.ts +90 -0
- package/src/client/hooks/workspace/file-tabs.ts +46 -0
- package/src/client/hooks/workspace/file-tree-edits.ts +103 -0
- package/src/client/lib/desktop/dropped-paths.ts +83 -0
- package/src/client/lib/editor/tab-menu.test.ts +127 -0
- package/src/client/lib/editor/tab-menu.ts +127 -0
- package/src/client/lib/editor-dirty-tabs.test.ts +102 -0
- package/src/client/lib/editor-dirty-tabs.ts +103 -0
- package/src/client/lib/native/resume.test.ts +66 -0
- package/src/client/lib/native/resume.ts +42 -0
- package/src/client/main.tsx +8 -0
- package/src/client/tailwind.css +38 -0
- package/src/server/lib/bundler/css.test.ts +31 -0
- package/src/server/lib/fs/listing.test.ts +81 -16
- package/src/server/lib/fs/listing.ts +72 -5
- package/src/server/lib/fs/write-conflict.test.ts +68 -0
- package/src/server/lib/fs/write-conflict.ts +84 -0
- package/src/server/routes/fs/action-save-as.test.ts +82 -0
- package/src/server/routes/fs/action.test.ts +82 -0
- package/src/server/routes/fs/action.ts +54 -1
- package/src/server/routes/fs/exists.ts +11 -1
- package/src/server/routes/fs/read.ts +6 -1
- package/src/shared/lib/code/editor/find-replace.test.ts +1 -1
- package/src/shared/lib/code/editor/find-scan.test.ts +1 -1
- package/src/shared/lib/code/editor/find-scan.ts +22 -1
- package/src/shared/lib/code/editor/find-selection.test.ts +56 -0
- package/src/shared/lib/code/editor/indent-guide-rule.test.ts +65 -0
- package/src/shared/lib/code/editor/indent-guide-rule.ts +47 -0
- package/src/shared/lib/code/editor/indent-rules.test.ts +219 -0
- package/src/shared/lib/code/editor/indent-rules.ts +198 -0
- package/src/shared/lib/code/editor/keymap.test.ts +23 -0
- package/src/shared/lib/code/editor/keymap.ts +40 -3
- package/src/shared/lib/code/editor/palette.test.ts +25 -2
- package/src/shared/lib/code/editor/palette.ts +10 -0
- package/src/shared/lib/code/editor/stream-modes.ts +225 -0
- package/src/shared/lib/code/syntax-highlight.test.ts +1 -1
- package/src/shared/lib/fs/file-tree.test.ts +41 -0
- package/src/shared/lib/fs/file-tree.ts +126 -34
- package/src/shared/lib/fs/folder-chain.test.ts +87 -0
- package/src/shared/lib/fs/folder-chain.ts +91 -0
- package/src/shared/lib/fs/fs-helpers.test.ts +4 -50
- package/src/shared/lib/realtime/connection.test.ts +5 -1
- package/src/shared/lib/realtime/connection.ts +25 -119
- package/src/shared/lib/realtime/frozen-recovery.test.ts +93 -0
- package/src/shared/lib/realtime/resume.ts +223 -0
- package/src/shared/lib/realtime/state.ts +22 -0
- package/src/shared/lib/realtime/watchdog-wiring.test.ts +224 -0
- package/src/shared/lib/realtime/watchdog.test.ts +99 -0
- package/src/shared/lib/realtime/watchdog.ts +72 -0
- package/src/shared/lib/workspace/split-editor.test.ts +104 -0
- package/src/shared/lib/workspace/split-editor.ts +129 -0
- package/src/test-support/file-explorer-disk.test-util.ts +30 -3
- package/src/test-support/pristine-globals.ts +7 -0
- package/dist/client/static/js/index-k315p1e8.css +0 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The tab strip's right-click menu.
|
|
8
|
+
*
|
|
9
|
+
* One tab, many ways to close it — and the difference between them is the whole
|
|
10
|
+
* reason the menu exists. `Close` on a strip of twelve tabs is not the operation
|
|
11
|
+
* people want; they want the other eleven gone, or the saved ones gone, or the one
|
|
12
|
+
* they closed by accident back.
|
|
13
|
+
*
|
|
14
|
+
* ## The rows are DATA, and the ones that cannot apply are ABSENT
|
|
15
|
+
*
|
|
16
|
+
* `Close saved` with no saved tabs, `Reopen closed` with an empty stack: a row that
|
|
17
|
+
* is always present and always refuses reads as a broken menu. `buildTabMenuRows`
|
|
18
|
+
* decides which exist, so the component only draws them — the same split the Files
|
|
19
|
+
* panel's row menu uses.
|
|
20
|
+
*
|
|
21
|
+
* ## `Reopen` is a stack, and it lives with the tab list
|
|
22
|
+
*
|
|
23
|
+
* It needs the closed `OpenedFile` kept WHOLE (name, path, scope, and whether it was a
|
|
24
|
+
* diff), because reopening reconstructs the tab rather than re-deriving it from a path.
|
|
25
|
+
* The stack is therefore owned by `useFileTabs`, next to `handleCloseFile` — a second
|
|
26
|
+
* copy elsewhere would be a second answer to "what was closed".
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import type { OpenedFile } from '@/shared/types/fs';
|
|
30
|
+
import { canSplitTo } from '@/shared/lib/workspace/split-editor';
|
|
31
|
+
|
|
32
|
+
/** What a tab menu row asks for. */
|
|
33
|
+
export type TabMenuAction =
|
|
34
|
+
| 'split-right'
|
|
35
|
+
| 'unsplit'
|
|
36
|
+
| 'close'
|
|
37
|
+
| 'close-others'
|
|
38
|
+
| 'close-all'
|
|
39
|
+
| 'close-saved'
|
|
40
|
+
| 'copy-path'
|
|
41
|
+
| 'reveal-in-files'
|
|
42
|
+
| 'reopen-closed';
|
|
43
|
+
|
|
44
|
+
export interface TabMenuRow {
|
|
45
|
+
action: TabMenuAction;
|
|
46
|
+
label: string;
|
|
47
|
+
/** A row that cannot apply here is absent, not disabled. */
|
|
48
|
+
enabled: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface BuildTabMenuRowsOptions {
|
|
52
|
+
/** The tab the menu was opened on. */
|
|
53
|
+
tab: OpenedFile;
|
|
54
|
+
/** Every open tab. */
|
|
55
|
+
openedFiles: readonly OpenedFile[];
|
|
56
|
+
/** Tab ids whose buffer holds edits that are not on disk. */
|
|
57
|
+
dirtyIds: ReadonlySet<string | number>;
|
|
58
|
+
/** How many closed tabs can still be reopened. */
|
|
59
|
+
reopenable: number;
|
|
60
|
+
/** The LEFT pane's tab: the tab the split would be divided FROM. */
|
|
61
|
+
activeFileId: string | number | null;
|
|
62
|
+
/** The tab the right pane currently shows, or null when the column is unsplit. */
|
|
63
|
+
splitRightFileId: string | number | null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The rows this menu offers, in the order a reader looks for them.
|
|
68
|
+
*
|
|
69
|
+
* `Close others` and `Close all` are absent when they would close nothing, and
|
|
70
|
+
* `Close saved` is absent when every open tab is dirty — a row that would do nothing
|
|
71
|
+
* is noise in a menu whose whole point is that each row does one thing.
|
|
72
|
+
*/
|
|
73
|
+
export function buildTabMenuRows({
|
|
74
|
+
tab,
|
|
75
|
+
openedFiles,
|
|
76
|
+
dirtyIds,
|
|
77
|
+
reopenable,
|
|
78
|
+
activeFileId,
|
|
79
|
+
splitRightFileId,
|
|
80
|
+
}: BuildTabMenuRowsOptions): TabMenuRow[] {
|
|
81
|
+
const others = openedFiles.filter((file) => file.id !== tab.id);
|
|
82
|
+
const saved = openedFiles.filter((file) => !dirtyIds.has(file.id));
|
|
83
|
+
const openIds = openedFiles.map((file) => file.id);
|
|
84
|
+
const rows: TabMenuRow[] = [
|
|
85
|
+
// Split rows sit FIRST, above the closes: they are the only rows here that ADD
|
|
86
|
+
// something, and a menu whose first four rows all destroy is a menu you read slowly.
|
|
87
|
+
{ action: 'split-right', label: 'Split right', enabled: canSplitTo(tab.id, activeFileId, openIds) },
|
|
88
|
+
{ action: 'unsplit', label: 'Unsplit', enabled: splitRightFileId !== null },
|
|
89
|
+
{ action: 'close', label: 'Close', enabled: true },
|
|
90
|
+
{ action: 'close-others', label: 'Close others', enabled: others.length > 0 },
|
|
91
|
+
{ action: 'close-all', label: 'Close all', enabled: openedFiles.length > 0 },
|
|
92
|
+
// Only worth a row when there is at least one SAVED tab OTHER than this one — the
|
|
93
|
+
// point of the row is to leave the saved ones behind.
|
|
94
|
+
{
|
|
95
|
+
action: 'close-saved',
|
|
96
|
+
label: 'Close saved',
|
|
97
|
+
enabled: saved.some((file) => file.id !== tab.id),
|
|
98
|
+
},
|
|
99
|
+
{ action: 'copy-path', label: 'Copy path', enabled: Boolean(tab.path) },
|
|
100
|
+
{ action: 'reveal-in-files', label: 'Reveal in Files', enabled: Boolean(tab.path) && !tab.isDiff },
|
|
101
|
+
{ action: 'reopen-closed', label: 'Reopen closed tab', enabled: reopenable > 0 },
|
|
102
|
+
];
|
|
103
|
+
return rows.filter((row) => row.enabled);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The ids a menu action leaves open, or null when the action is not a close. */
|
|
107
|
+
export function tabIdsAfterClose(
|
|
108
|
+
action: TabMenuAction,
|
|
109
|
+
tab: OpenedFile,
|
|
110
|
+
openedFiles: readonly OpenedFile[],
|
|
111
|
+
dirtyIds: ReadonlySet<string | number>,
|
|
112
|
+
): Array<string | number> | null {
|
|
113
|
+
switch (action) {
|
|
114
|
+
case 'close':
|
|
115
|
+
return openedFiles.filter((file) => file.id !== tab.id).map((file) => file.id);
|
|
116
|
+
case 'close-others':
|
|
117
|
+
return [tab.id];
|
|
118
|
+
case 'close-all':
|
|
119
|
+
return [];
|
|
120
|
+
case 'close-saved':
|
|
121
|
+
// The dirty ones stay, which is the only reading that makes the row safe: it
|
|
122
|
+
// cannot lose an edit.
|
|
123
|
+
return openedFiles.filter((file) => dirtyIds.has(file.id)).map((file) => file.id);
|
|
124
|
+
default:
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The per-tab dirty store.
|
|
8
|
+
*
|
|
9
|
+
* The rule worth pinning is the one a `Set` makes easy to get wrong: an unchanged
|
|
10
|
+
* publish must return the SAME snapshot object, or every subscriber re-renders on
|
|
11
|
+
* every keystroke elsewhere in the panel. And `retain` must drop a closed tab's
|
|
12
|
+
* entry, or a freshly opened tab that reuses the id would come up already dotted.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
hasDirtyTabs,
|
|
19
|
+
isTabDirty,
|
|
20
|
+
resetDirtyTabs,
|
|
21
|
+
retainDirtyTabs,
|
|
22
|
+
setDirtyTabs,
|
|
23
|
+
subscribeDirtyTabs,
|
|
24
|
+
} from '@/client/lib/editor-dirty-tabs';
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
resetDirtyTabs();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('setDirtyTabs', () => {
|
|
31
|
+
test('records exactly what it was given', () => {
|
|
32
|
+
setDirtyTabs(['a', 2]);
|
|
33
|
+
expect(isTabDirty('a')).toBe(true);
|
|
34
|
+
expect(isTabDirty(2)).toBe(true);
|
|
35
|
+
expect(isTabDirty('b')).toBe(false);
|
|
36
|
+
expect(hasDirtyTabs()).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('replaces rather than merges, so a saved tab stops being dirty', () => {
|
|
40
|
+
setDirtyTabs(['a', 'b']);
|
|
41
|
+
setDirtyTabs(['a']);
|
|
42
|
+
expect(isTabDirty('b')).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('an empty set clears the flag the unload guard reads', () => {
|
|
46
|
+
setDirtyTabs(['a']);
|
|
47
|
+
setDirtyTabs([]);
|
|
48
|
+
expect(hasDirtyTabs()).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('retainDirtyTabs', () => {
|
|
53
|
+
test('drops the ids that left the tab set', () => {
|
|
54
|
+
setDirtyTabs(['a', 'b', 'c']);
|
|
55
|
+
retainDirtyTabs(['a']);
|
|
56
|
+
expect(isTabDirty('a')).toBe(true);
|
|
57
|
+
expect(isTabDirty('b')).toBe(false);
|
|
58
|
+
expect(isTabDirty('c')).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('a closed tab’s id does not decorate a tab that reuses it', () => {
|
|
62
|
+
setDirtyTabs([7]);
|
|
63
|
+
retainDirtyTabs([]);
|
|
64
|
+
// The same id, a different file: the entry is gone, so the tab opens clean.
|
|
65
|
+
expect(isTabDirty(7)).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('a publish that changes nothing notifies nobody', () => {
|
|
70
|
+
test('the same set twice is ONE notification', () => {
|
|
71
|
+
// The panel re-renders on every keystroke, so a publish that re-notifies an
|
|
72
|
+
// unchanged set would re-render the whole tab strip for nothing.
|
|
73
|
+
let calls = 0;
|
|
74
|
+
const stop = subscribeDirtyTabs(() => { calls += 1; });
|
|
75
|
+
setDirtyTabs(['a']);
|
|
76
|
+
expect(calls).toBe(1);
|
|
77
|
+
setDirtyTabs(['a']);
|
|
78
|
+
expect(calls).toBe(1);
|
|
79
|
+
setDirtyTabs(['a', 'b']);
|
|
80
|
+
expect(calls).toBe(2);
|
|
81
|
+
stop();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('a retain that drops nothing is silent, and one that drops a row notifies', () => {
|
|
85
|
+
setDirtyTabs(['a']);
|
|
86
|
+
let calls = 0;
|
|
87
|
+
const stop = subscribeDirtyTabs(() => { calls += 1; });
|
|
88
|
+
retainDirtyTabs(['a', 'b']);
|
|
89
|
+
expect(calls).toBe(0);
|
|
90
|
+
retainDirtyTabs(['b']);
|
|
91
|
+
expect(calls).toBe(1);
|
|
92
|
+
stop();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('a released subscriber stops hearing about changes', () => {
|
|
96
|
+
let calls = 0;
|
|
97
|
+
const stop = subscribeDirtyTabs(() => { calls += 1; });
|
|
98
|
+
stop();
|
|
99
|
+
setDirtyTabs(['a']);
|
|
100
|
+
expect(calls).toBe(0);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which OPEN editor tabs hold edits that are not on disk.
|
|
8
|
+
*
|
|
9
|
+
* `useFileEditor` computes `isDirty` for the ACTIVE tab, and that is all a single
|
|
10
|
+
* hook can know: it caches one buffer at a time. The tab strip needs the same
|
|
11
|
+
* answer for a BACKGROUND tab — the one the user is about to close — so the editor
|
|
12
|
+
* publishes a per-tab record here and the strip reads it.
|
|
13
|
+
*
|
|
14
|
+
* ## Why a store and not a prop
|
|
15
|
+
*
|
|
16
|
+
* The editor panel owns the tabs (`openedFiles` comes from the layout) while the
|
|
17
|
+
* buffer state lives in `useFileEditor`. Threading a `dirtyIds` prop through
|
|
18
|
+
* `Editor → EditorTabs` would mean the panel recomputing dirtiness it cannot see;
|
|
19
|
+
* a store lets the ONE component that knows (the editor) publish it, and the one
|
|
20
|
+
* that draws it (the strip) subscribe.
|
|
21
|
+
*
|
|
22
|
+
* ## A closed tab's entry is dropped with the tab
|
|
23
|
+
*
|
|
24
|
+
* Keyed by tab id, and `retain` prunes it — the same lifecycle as the content
|
|
25
|
+
* cache. A stale entry would draw a dot on a freshly opened tab that happens to
|
|
26
|
+
* reuse an id.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { useSyncExternalStore } from 'preact/compat';
|
|
30
|
+
|
|
31
|
+
/** Tab ids currently holding unsaved edits. */
|
|
32
|
+
const dirty = new Set<string | number>();
|
|
33
|
+
const listeners = new Set<() => void>();
|
|
34
|
+
/** A stable snapshot object, so `useSyncExternalStore` does not re-render forever. */
|
|
35
|
+
let snapshot: ReadonlySet<string | number> = new Set();
|
|
36
|
+
|
|
37
|
+
function publish(): void {
|
|
38
|
+
snapshot = new Set(dirty);
|
|
39
|
+
for (const listener of [...listeners]) listener();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Replace the whole set. The editor calls this after every render that moved it. */
|
|
43
|
+
export function setDirtyTabs(ids: Iterable<string | number>): void {
|
|
44
|
+
const next = new Set(ids);
|
|
45
|
+
if (next.size === dirty.size) {
|
|
46
|
+
let same = true;
|
|
47
|
+
for (const id of next) {
|
|
48
|
+
if (!dirty.has(id)) { same = false; break; }
|
|
49
|
+
}
|
|
50
|
+
if (same) return;
|
|
51
|
+
}
|
|
52
|
+
dirty.clear();
|
|
53
|
+
for (const id of next) dirty.add(id);
|
|
54
|
+
publish();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Drop the ids that left the tab set. */
|
|
58
|
+
export function retainDirtyTabs(keep: Iterable<string | number>): void {
|
|
59
|
+
const keepSet = new Set(keep);
|
|
60
|
+
let dropped = false;
|
|
61
|
+
for (const id of [...dirty]) {
|
|
62
|
+
if (!keepSet.has(id)) { dirty.delete(id); dropped = true; }
|
|
63
|
+
}
|
|
64
|
+
if (dropped) publish();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Whether `id` currently holds unsaved edits. */
|
|
68
|
+
export function isTabDirty(id: string | number): boolean {
|
|
69
|
+
return dirty.has(id);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Whether ANY tab does — the condition `beforeunload` is armed on. */
|
|
73
|
+
export function hasDirtyTabs(): boolean {
|
|
74
|
+
return dirty.size > 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Observe changes.
|
|
79
|
+
*
|
|
80
|
+
* Exported because the hook is not the only reader that matters: the panel's own
|
|
81
|
+
* tests assert that an unchanged publish notifies nobody, and a subscription is the
|
|
82
|
+
* only way to see that.
|
|
83
|
+
*/
|
|
84
|
+
export function subscribeDirtyTabs(listener: () => void): () => void {
|
|
85
|
+
listeners.add(listener);
|
|
86
|
+
return () => {
|
|
87
|
+
listeners.delete(listener);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const subscribe = subscribeDirtyTabs;
|
|
92
|
+
|
|
93
|
+
/** The live set, for a component that draws a dot per row. */
|
|
94
|
+
export function useDirtyTabs(): ReadonlySet<string | number> {
|
|
95
|
+
return useSyncExternalStore(subscribe, () => snapshot);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Test seam: forget every entry. */
|
|
99
|
+
export function resetDirtyTabs(): void {
|
|
100
|
+
if (dirty.size === 0) return;
|
|
101
|
+
dirty.clear();
|
|
102
|
+
publish();
|
|
103
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The native shell's resume hook.
|
|
8
|
+
*
|
|
9
|
+
* A backgrounded Android WebView fires no `visibilitychange` on return, and a
|
|
10
|
+
* socket the server's heartbeat reaped while the page was frozen produces no
|
|
11
|
+
* `close` — so the shell is the only thing that knows the app came back. It
|
|
12
|
+
* evaluates `window.__kabmoResume()`, and that has to be a function the page
|
|
13
|
+
* installed before the first render.
|
|
14
|
+
*
|
|
15
|
+
* What is pinned here is the CONTRACT between the two sides (the property name,
|
|
16
|
+
* and that it is installed idempotently) plus the one behaviour that makes it
|
|
17
|
+
* safe to call unconditionally: with nothing subscribed it does nothing at all,
|
|
18
|
+
* because the shell calls it on every foreground, including the first.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
22
|
+
import { Window } from 'happy-dom';
|
|
23
|
+
|
|
24
|
+
import { RESUME_PROPERTY, installResumeDispatcher } from '@/client/lib/native/resume';
|
|
25
|
+
import { resetRealtimeClient } from '@/shared/lib/realtime/client';
|
|
26
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
resetRealtimeClient();
|
|
30
|
+
restoreDomGlobals();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function installWindow(): Window {
|
|
34
|
+
const win = new Window({ url: 'http://localhost/' });
|
|
35
|
+
installDomGlobals(win);
|
|
36
|
+
return win;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('installResumeDispatcher', () => {
|
|
40
|
+
test('exposes window.__kabmoResume and is idempotent', () => {
|
|
41
|
+
const win = installWindow();
|
|
42
|
+
installResumeDispatcher();
|
|
43
|
+
installResumeDispatcher();
|
|
44
|
+
|
|
45
|
+
const installed = (win as unknown as Record<string, unknown>)[RESUME_PROPERTY];
|
|
46
|
+
expect(typeof installed).toBe('function');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('the property name is the one the shells evaluate', () => {
|
|
50
|
+
// Spelled out rather than read from the module: the Kotlin and Swift shells
|
|
51
|
+
// hardcode the string in an `evaluateJavascript`, so a rename here has to be
|
|
52
|
+
// a deliberate edit there too. This is the assertion that fails if it is not.
|
|
53
|
+
expect(RESUME_PROPERTY).toBe('__kabmoResume');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('calling it with nothing subscribed dials nothing', () => {
|
|
57
|
+
const win = installWindow();
|
|
58
|
+
installResumeDispatcher();
|
|
59
|
+
const resume = (win as unknown as Record<string, unknown>)[RESUME_PROPERTY] as () => void;
|
|
60
|
+
|
|
61
|
+
// The shell calls this on EVERY foreground, including the very first, so it
|
|
62
|
+
// must be inert when the page has no subscription — otherwise a phone would
|
|
63
|
+
// open a socket the moment the app appears, before anything asked for one.
|
|
64
|
+
expect(() => resume()).not.toThrow();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The native shell's resume hook, delegated to the page.
|
|
8
|
+
*
|
|
9
|
+
* A backgrounded Android WebView does not reliably deliver the browser events
|
|
10
|
+
* the realtime channel listens for: the document is never reported hidden when
|
|
11
|
+
* the app goes to the background, so returning to it fires no
|
|
12
|
+
* `visibilitychange`, and a socket the server reaped while the page was frozen
|
|
13
|
+
* produces no `close`. The channel's watchdog (`shared/lib/realtime/resume.ts`)
|
|
14
|
+
* repairs that on its own, but only on its next tick — up to 5s, plus a 2s probe
|
|
15
|
+
* — which is the difference between the stream continuing and the user
|
|
16
|
+
* concluding it is dead.
|
|
17
|
+
*
|
|
18
|
+
* So the shell says so directly: `MainActivity.onResume` /
|
|
19
|
+
* `ShellViewController.viewDidAppear` evaluate `window.__kabmoResume()`, and the
|
|
20
|
+
* repair starts on that tick. Same indirection as `__kabmoBack`, and for the
|
|
21
|
+
* same reason — the page owns the state, the shell only knows the moment.
|
|
22
|
+
*
|
|
23
|
+
* Idempotent and safe to call at any time: a healthy connection is probed, a
|
|
24
|
+
* dead one is re-dialed, and a tab with no subscribers does nothing.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { wake } from '@/shared/lib/realtime/connection';
|
|
28
|
+
|
|
29
|
+
/** The property the shell calls. Named once so both sides agree. */
|
|
30
|
+
export const RESUME_PROPERTY = '__kabmoResume';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Install `window.__kabmoResume`. Idempotent — a hot reload re-runs it.
|
|
34
|
+
*
|
|
35
|
+
* Installed unconditionally: the function is inert in a browser (nothing calls
|
|
36
|
+
* it), and gating it on a user agent would be a second place that has to know
|
|
37
|
+
* which shells exist.
|
|
38
|
+
*/
|
|
39
|
+
export function installResumeDispatcher(): void {
|
|
40
|
+
if (typeof window === 'undefined') return;
|
|
41
|
+
(window as unknown as Record<string, unknown>)[RESUME_PROPERTY] = wake;
|
|
42
|
+
}
|
package/src/client/main.tsx
CHANGED
|
@@ -10,6 +10,7 @@ import { installPluginRuntime } from '@/client/lib/plugins/runtime';
|
|
|
10
10
|
import { installUiKit } from '@/client/lib/plugins/kit';
|
|
11
11
|
import { installScrollbarActivity } from '@/client/lib/scrollbar-activity';
|
|
12
12
|
import { installBackDispatcher } from '@/client/lib/native/back';
|
|
13
|
+
import { installResumeDispatcher } from '@/client/lib/native/resume';
|
|
13
14
|
import { installFileLaunchHandler } from '@/client/lib/launch/file-handlers';
|
|
14
15
|
|
|
15
16
|
import '@/client/tailwind.css';
|
|
@@ -60,6 +61,13 @@ installScrollbarActivity();
|
|
|
60
61
|
// a back press during hydration must find the dispatcher, not `undefined`.
|
|
61
62
|
installBackDispatcher();
|
|
62
63
|
|
|
64
|
+
// The native shell calls `window.__kabmoResume()` when its app returns to the
|
|
65
|
+
// foreground. A backgrounded Android WebView fires no `visibilitychange` and
|
|
66
|
+
// gets no `close` for a socket the server reaped, so the shell's own lifecycle
|
|
67
|
+
// is the only reliable resume signal there — see `shared/lib/realtime/resume.ts`
|
|
68
|
+
// for the watchdog that covers the case no event arrives at all.
|
|
69
|
+
installResumeDispatcher();
|
|
70
|
+
|
|
63
71
|
// A file the OS handed to Kabmo (PWA File Handling) arrives as a
|
|
64
72
|
// `FileSystemFileHandle` on `launchQueue`, and the consumer must be installed
|
|
65
73
|
// before the first render: launches that happened before the script ran are
|
package/src/client/tailwind.css
CHANGED
|
@@ -421,6 +421,44 @@ html[data-theme-variant="dark"] .shiki span { color: var(--shiki-dark); }
|
|
|
421
421
|
background: none;
|
|
422
422
|
}
|
|
423
423
|
|
|
424
|
+
/* The CodeMirror root FILLS its host, so a bounded host scrolls instead of
|
|
425
|
+
* clipping.
|
|
426
|
+
*
|
|
427
|
+
* `.cm-editor` (and a merge view's `.cm-mergeView`) carries `height: 100%` in
|
|
428
|
+
* the surface theme, and a percentage height resolves against a DEFINITE
|
|
429
|
+
* containing block. The diff panel's host has one — its parent is a sized flex
|
|
430
|
+
* column — but a chat card's diff only has a CEILING (`max-h-72` on the
|
|
431
|
+
* wrapper), and a box whose height comes from `max-height` is indefinite for
|
|
432
|
+
* percentage resolution. The root therefore computed to `auto`, grew to its
|
|
433
|
+
* content and the host's `overflow: hidden` clipped it: measured in the
|
|
434
|
+
* timeline, a 1847px editor inside a 288px host with `scrollHeight ===
|
|
435
|
+
* clientHeight` — a 30-line edit card that showed 9 rows with no way to reach
|
|
436
|
+
* the rest, in BOTH shapes (unified 1847px, split 1928px).
|
|
437
|
+
*
|
|
438
|
+
* Making the host a column flex container and the root a shrinking flex item
|
|
439
|
+
* gives the root the host's height through LAYOUT rather than through a
|
|
440
|
+
* percentage, so it works whether the host's height is definite, capped or
|
|
441
|
+
* automatic: `min-height: 0` is what allows the item to go below its content
|
|
442
|
+
* height, and the editor's own `.cm-scroller` then owns the overflow (it is
|
|
443
|
+
* the element with `overflow: auto`). Verified on both shapes: 288px host,
|
|
444
|
+
* scroller `clientHeight 288 / scrollHeight 1847`, scrolled to 400. An
|
|
445
|
+
* unconstrained host (`max-h-none`, the full-output reader) still sizes to its
|
|
446
|
+
* content, because an auto-height flex column does.
|
|
447
|
+
*
|
|
448
|
+
* This is stated on the shared marker rather than per call site: every host
|
|
449
|
+
* that claims to BE a code surface wants the same thing, and the two surfaces
|
|
450
|
+
* that draw one (the editor pane and a diff) each restated it wrong once. */
|
|
451
|
+
[data-code-surface] {
|
|
452
|
+
display: flex;
|
|
453
|
+
flex-direction: column;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
[data-code-surface] > .cm-editor,
|
|
457
|
+
[data-code-surface] > .cm-mergeView {
|
|
458
|
+
flex: 1 1 auto;
|
|
459
|
+
min-height: 0;
|
|
460
|
+
}
|
|
461
|
+
|
|
424
462
|
/* Find matches, painted inside the token spans the highlighter emits. An
|
|
425
463
|
* inline <mark> colours a background without moving a glyph, which is what
|
|
426
464
|
* keeps the transparent <textarea> above aligned with this layer — a block or
|
|
@@ -213,6 +213,37 @@ describe('css plugin — the scrollbar system reaches the browser', () => {
|
|
|
213
213
|
});
|
|
214
214
|
});
|
|
215
215
|
|
|
216
|
+
/**
|
|
217
|
+
* The CodeMirror root filling its host, which is what makes a bounded diff
|
|
218
|
+
* scroll at all.
|
|
219
|
+
*
|
|
220
|
+
* `.cm-editor` carries `height: 100%`, and a percentage resolves against a
|
|
221
|
+
* DEFINITE containing block. A chat card's diff host is bounded only by a
|
|
222
|
+
* `max-height`, which is indefinite for that purpose, so the root computed to
|
|
223
|
+
* `auto` and grew to its content — measured in the timeline: a 1847px editor
|
|
224
|
+
* inside a 288px host, `scrollHeight === clientHeight`, a 30-line edit card
|
|
225
|
+
* showing 9 rows with no way to reach the rest. The fix is layout rather than
|
|
226
|
+
* a percentage: the host is a column flex container and the root a shrinking
|
|
227
|
+
* flex item.
|
|
228
|
+
*
|
|
229
|
+
* Both halves are asserted because either alone is inert: `min-height: 0` on
|
|
230
|
+
* the item is what lets it go below its content height, and the host's
|
|
231
|
+
* `flex-direction` is what makes that height the one the item is measured
|
|
232
|
+
* against. The minifier also rewrites `flex: 1 1 auto` to `flex: auto`, which
|
|
233
|
+
* is why the gate reads the built sheet.
|
|
234
|
+
*/
|
|
235
|
+
describe('css plugin — a code surface fills its host', () => {
|
|
236
|
+
test('the host is a column flex container and the root shrinks inside it', async () => {
|
|
237
|
+
const out = await buildProjectStylesheet();
|
|
238
|
+
|
|
239
|
+
expect(out).toContain('[data-code-surface]{display:flex;flex-direction:column}');
|
|
240
|
+
expect(out).toContain('[data-code-surface]>.cm-editor');
|
|
241
|
+
expect(out).toContain('[data-code-surface]>.cm-mergeView');
|
|
242
|
+
expect(out).toContain('min-height:0');
|
|
243
|
+
expect(out).toMatch(/\[data-code-surface\]>\.cm-(editor|mergeView)[^{]*\{[^}]*flex:auto/);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
216
247
|
/**
|
|
217
248
|
* The collapsible-section reveal (Source Control's stash section).
|
|
218
249
|
*
|
|
@@ -12,8 +12,13 @@
|
|
|
12
12
|
* filter at all: every entry is listed, and the `ignored` flag (one
|
|
13
13
|
* `git check-ignore` per listing) is what marks the untracked ones for dimming.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* The other half is the COLLAPSE: a folder holding exactly one folder and
|
|
16
|
+
* nothing else becomes one row naming the whole chain, which is what keeps a
|
|
17
|
+
* Java package tree (`com/java/app/package`) from spending four rows to reach
|
|
18
|
+
* the files inside it.
|
|
19
|
+
*
|
|
20
|
+
* Driven against a real temp directory, because the listing stats every entry,
|
|
21
|
+
* walks every single-child chain and asks git about it.
|
|
17
22
|
*/
|
|
18
23
|
|
|
19
24
|
import { afterEach, describe, expect, test } from 'bun:test';
|
|
@@ -48,9 +53,11 @@ describe('listDirectoryEntries', () => {
|
|
|
48
53
|
expect(names).toContain('dist');
|
|
49
54
|
expect(names).toContain('build');
|
|
50
55
|
expect(names).toContain('src');
|
|
51
|
-
// No name table: the panel must be able to reach anything on disk.
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
// No name table: the panel must be able to reach anything on disk. A
|
|
57
|
+
// dependency folder is a single-child chain on its own, so it is listed by
|
|
58
|
+
// the chain it collapses to — `node_modules/preact`, not `node_modules`.
|
|
59
|
+
expect(names).toContain('node_modules/preact');
|
|
60
|
+
expect(names).toContain('.git/objects');
|
|
54
61
|
});
|
|
55
62
|
|
|
56
63
|
test('a nested dist is listed where it lives, not filtered by name', async () => {
|
|
@@ -58,17 +65,14 @@ describe('listDirectoryEntries', () => {
|
|
|
58
65
|
mkdirs(root, ['packages/android/dist', 'packages/core']);
|
|
59
66
|
|
|
60
67
|
const packages = await listDirectoryEntries(path.join(root, 'packages'), root);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
expect(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// backslash — left the whole listing un-dimmed there. This assertion is the
|
|
70
|
-
// guard; it is what failed on the Windows CI leg.
|
|
71
|
-
expect(android[0]!.path).toBe('packages/android/dist');
|
|
68
|
+
// `android` holds nothing but `dist`, so the two collapse into one row —
|
|
69
|
+
// and the path still names the deepest directory, which is the one whose
|
|
70
|
+
// contents the row expands into.
|
|
71
|
+
expect(packages.map((entry) => entry.name)).toEqual(['android/dist', 'core']);
|
|
72
|
+
expect(packages[0]!.path).toBe('packages/android/dist');
|
|
73
|
+
|
|
74
|
+
const dist = await listDirectoryEntries(path.join(root, 'packages/android/dist'), root);
|
|
75
|
+
expect(dist).toEqual([]);
|
|
72
76
|
});
|
|
73
77
|
|
|
74
78
|
test('folders sort before files, and dot-entries are listed', async () => {
|
|
@@ -84,3 +88,64 @@ describe('listDirectoryEntries', () => {
|
|
|
84
88
|
expect(names).toEqual(['zebra', '.env', 'alpha.txt']);
|
|
85
89
|
});
|
|
86
90
|
});
|
|
91
|
+
|
|
92
|
+
describe('single-child chains', () => {
|
|
93
|
+
test('a package tree collapses into one row naming the whole chain', async () => {
|
|
94
|
+
const root = makeRoot();
|
|
95
|
+
fs.mkdirSync(path.join(root, 'com/java/app/package'), { recursive: true });
|
|
96
|
+
fs.writeFileSync(path.join(root, 'com/java/app/package/Main.java'), 'class Main {}\n');
|
|
97
|
+
|
|
98
|
+
const entries = await listDirectoryEntries(root, root);
|
|
99
|
+
|
|
100
|
+
expect(entries).toHaveLength(1);
|
|
101
|
+
expect(entries[0]!.name).toBe('com/java/app/package');
|
|
102
|
+
expect(entries[0]!.path).toBe('com/java/app/package');
|
|
103
|
+
expect(entries[0]!.id).toBe('com/java/app/package');
|
|
104
|
+
expect(entries[0]!.type).toBe('folder');
|
|
105
|
+
// The chain's own levels are never listed, so the panel reads one directory
|
|
106
|
+
// to show the row and one more when it expands.
|
|
107
|
+
const inner = await listDirectoryEntries(path.join(root, 'com/java/app/package'), root);
|
|
108
|
+
expect(inner.map((entry) => entry.name)).toEqual(['Main.java']);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('a chain stops at the first level that holds a file', async () => {
|
|
112
|
+
const root = makeRoot();
|
|
113
|
+
fs.mkdirSync(path.join(root, 'a/b/c'), { recursive: true });
|
|
114
|
+
fs.writeFileSync(path.join(root, 'a/b/README.md'), 'x\n');
|
|
115
|
+
|
|
116
|
+
const entries = await listDirectoryEntries(root, root);
|
|
117
|
+
|
|
118
|
+
// `a` holds nothing but `b`, so the walk continues; `b` holds a folder AND a
|
|
119
|
+
// file, so it is where the chain ends.
|
|
120
|
+
expect(entries.map((entry) => entry.name)).toEqual(['a/b']);
|
|
121
|
+
const insideB = await listDirectoryEntries(path.join(root, 'a/b'), root);
|
|
122
|
+
expect(insideB.map((entry) => entry.name)).toEqual(['c', 'README.md']);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('two folders never collapse, and neither does an empty one', async () => {
|
|
126
|
+
const root = makeRoot();
|
|
127
|
+
mkdirs(root, ['pair/one', 'pair/two', 'empty']);
|
|
128
|
+
|
|
129
|
+
const entries = await listDirectoryEntries(root, root);
|
|
130
|
+
|
|
131
|
+
expect(entries.map((entry) => entry.name)).toEqual(['empty', 'pair']);
|
|
132
|
+
const pair = await listDirectoryEntries(path.join(root, 'pair'), root);
|
|
133
|
+
expect(pair.map((entry) => entry.name)).toEqual(['one', 'two']);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('a git-ignored chain is dimmed from its deepest directory', async () => {
|
|
137
|
+
const root = makeRoot();
|
|
138
|
+
fs.mkdirSync(path.join(root, 'a/b/c'), { recursive: true });
|
|
139
|
+
fs.writeFileSync(path.join(root, 'a/b/c/f.txt'), 'x\n');
|
|
140
|
+
fs.writeFileSync(path.join(root, '.gitignore'), 'a/\n');
|
|
141
|
+
Bun.spawnSync({ cmd: ['git', 'init', '-q'], cwd: root });
|
|
142
|
+
|
|
143
|
+
const entries = await listDirectoryEntries(root, root);
|
|
144
|
+
|
|
145
|
+
const row = entries.find((entry) => entry.path === 'a/b/c');
|
|
146
|
+
expect(row?.name).toBe('a/b/c');
|
|
147
|
+
// A rule matching an OUTER level of the chain answers for the deepest one
|
|
148
|
+
// too (verified against `git check-ignore`), which is the path the row names.
|
|
149
|
+
expect(row?.ignored).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
});
|