@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.
Files changed (180) hide show
  1. package/README.md +45 -0
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +333 -333
  4. package/dist/client/static/js/index-18xe7655.css +1 -0
  5. package/dist/client/static/js/{index-bpptfkz2.js → index-nxpe7835.js} +768 -763
  6. package/package.json +3 -1
  7. package/src/client/components/common/code-surface/bracket-guide.test.ts +249 -0
  8. package/src/client/components/common/code-surface/bracket-guide.ts +131 -0
  9. package/src/client/components/common/code-surface/documents.test.ts +5 -3
  10. package/src/client/components/common/code-surface/documents.ts +85 -0
  11. package/src/client/components/common/code-surface/extensions.test.ts +5 -0
  12. package/src/client/components/common/code-surface/extensions.ts +140 -7
  13. package/src/client/components/common/code-surface/fold-stack.test.ts +218 -0
  14. package/src/client/components/common/code-surface/fold.test.ts +148 -0
  15. package/src/client/components/common/code-surface/fold.ts +118 -0
  16. package/src/client/components/common/code-surface/indent-guide.ts +104 -0
  17. package/src/client/components/common/code-surface/indent.test.ts +239 -0
  18. package/src/client/components/common/code-surface/indent.ts +124 -0
  19. package/src/client/components/common/code-surface/index.tsx +76 -46
  20. package/src/client/components/common/code-surface/keymap.ts +12 -23
  21. package/src/client/components/common/code-surface/line-commands.test.ts +90 -0
  22. package/src/client/components/common/code-surface/line-commands.ts +103 -0
  23. package/src/client/components/common/code-surface/props.ts +87 -0
  24. package/src/client/components/common/code-surface/stream-language.test.ts +118 -0
  25. package/src/client/components/common/code-surface/stream-language.ts +123 -0
  26. package/src/client/components/common/code-surface/theme.test.ts +40 -5
  27. package/src/client/components/common/code-surface/theme.ts +113 -0
  28. package/src/client/components/common/code-surface/typing.test.ts +97 -0
  29. package/src/client/components/common/code-surface/typing.ts +111 -0
  30. package/src/client/components/common/toolbar-row/index.test.tsx +53 -4
  31. package/src/client/components/common/toolbar-row/index.tsx +101 -30
  32. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +17 -0
  33. package/src/client/components/layout/desktop-layout/index.tsx +18 -0
  34. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +35 -33
  35. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +20 -1
  36. package/src/client/components/mobile/mobile-right-sidebar/editor-props.ts +25 -0
  37. package/src/client/components/settings/categories/AppearanceSettings.tsx +6 -0
  38. package/src/client/components/settings/categories/appearance-settings/EditorIndentSection.tsx +87 -0
  39. package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +99 -0
  40. package/src/client/components/workspace/chat-timeline/chat-input/expansion.ts +9 -4
  41. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +15 -11
  42. package/src/client/components/workspace/chat-timeline/chat-input/stretch-send.test.tsx +165 -0
  43. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.test.ts +17 -3
  44. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.tsx +10 -6
  45. package/src/client/components/workspace/editor/Body.tsx +24 -0
  46. package/src/client/components/workspace/editor/CommandPalette.tsx +4 -4
  47. package/src/client/components/workspace/editor/ConflictStrip.tsx +77 -0
  48. package/src/client/components/workspace/editor/Dialogs.tsx +53 -0
  49. package/src/client/components/workspace/editor/EmptyEditor.tsx +23 -0
  50. package/src/client/components/workspace/editor/ExternalChangeStrip.tsx +61 -0
  51. package/src/client/components/workspace/editor/FileDocument.tsx +89 -1
  52. package/src/client/components/workspace/editor/FilePane.tsx +43 -0
  53. package/src/client/components/workspace/editor/FindWidget.test.ts +9 -5
  54. package/src/client/components/workspace/editor/FindWidget.tsx +29 -0
  55. package/src/client/components/workspace/editor/GoToLineModal.tsx +123 -0
  56. package/src/client/components/workspace/editor/Notices.tsx +71 -0
  57. package/src/client/components/workspace/editor/Pane.tsx +118 -0
  58. package/src/client/components/workspace/editor/PluginColumn.tsx +32 -0
  59. package/src/client/components/workspace/editor/QuickOpenModal.tsx +146 -0
  60. package/src/client/components/workspace/editor/SaveAsModal.tsx +175 -0
  61. package/src/client/components/workspace/editor/SplitColumn.tsx +98 -0
  62. package/src/client/components/workspace/editor/SplitPane.tsx +57 -0
  63. package/src/client/components/workspace/editor/StatusBar.tsx +106 -0
  64. package/src/client/components/workspace/editor/TabContextMenu.tsx +75 -0
  65. package/src/client/components/workspace/editor/Tabs.tsx +195 -18
  66. package/src/client/components/workspace/editor/Toolbar.tsx +54 -181
  67. package/src/client/components/workspace/editor/index.tsx +199 -189
  68. package/src/client/components/workspace/editor/props.ts +64 -0
  69. package/src/client/components/workspace/editor/toolbar-clusters.tsx +300 -0
  70. package/src/client/components/workspace/file-explorer/Modals.tsx +14 -1
  71. package/src/client/components/workspace/file-explorer/TreeItem.tsx +2 -1
  72. package/src/client/components/workspace/file-explorer/clipboard.test.ts +3 -1
  73. package/src/client/components/workspace/file-explorer/index.test.ts +61 -0
  74. package/src/client/components/workspace/file-explorer/index.tsx +10 -48
  75. package/src/client/components/workspace/file-explorer/local-edit.test.ts +8 -3
  76. package/src/client/components/workspace/search-panel/Body.tsx +6 -1
  77. package/src/client/hooks/chat/composer/file-drop.ts +22 -37
  78. package/src/client/hooks/chat/composer/pipeline.test.ts +76 -0
  79. package/src/client/hooks/chat/composer/pipeline.ts +12 -1
  80. package/src/client/hooks/editor/caret-position.test.ts +58 -0
  81. package/src/client/hooks/editor/caret-position.ts +48 -0
  82. package/src/client/hooks/editor/file-editor-types.ts +200 -0
  83. package/src/client/hooks/editor/find-history.test.ts +132 -0
  84. package/src/client/hooks/editor/find-history.ts +46 -0
  85. package/src/client/hooks/editor/find-selection-range.test.ts +100 -0
  86. package/src/client/hooks/editor/find-selection-range.ts +49 -0
  87. package/src/client/hooks/editor/find-state.ts +13 -0
  88. package/src/client/hooks/editor/font.test.ts +0 -93
  89. package/src/client/hooks/editor/indent-settings.test.ts +104 -0
  90. package/src/client/hooks/editor/indent-settings.ts +88 -0
  91. package/src/client/hooks/editor/quick-open.test.ts +141 -0
  92. package/src/client/hooks/editor/quick-open.ts +127 -0
  93. package/src/client/hooks/editor/save-as.test.ts +156 -0
  94. package/src/client/hooks/editor/save-as.ts +122 -0
  95. package/src/client/hooks/editor/save-file.test.ts +179 -0
  96. package/src/client/hooks/editor/save-file.ts +73 -28
  97. package/src/client/hooks/editor/typing-settings.test.ts +73 -0
  98. package/src/client/hooks/editor/typing-settings.ts +65 -0
  99. package/src/client/hooks/editor/use-close-guard.ts +98 -0
  100. package/src/client/hooks/editor/use-editor-drop-overlay.test.ts +159 -0
  101. package/src/client/hooks/editor/use-editor-drop.shell.test.ts +224 -0
  102. package/src/client/hooks/editor/use-editor-drop.ts +58 -68
  103. package/src/client/hooks/editor/use-editor-find.test.ts +2 -2
  104. package/src/client/hooks/editor/use-editor-find.ts +38 -3
  105. package/src/client/hooks/editor/use-editor-panel-keys.ts +152 -0
  106. package/src/client/hooks/editor/use-editor-tab-state.ts +71 -0
  107. package/src/client/hooks/editor/use-external-change-notice.ts +71 -0
  108. package/src/client/hooks/editor/use-external-change.test.ts +88 -0
  109. package/src/client/hooks/editor/use-external-change.ts +146 -0
  110. package/src/client/hooks/editor/use-file-editor.ts +83 -116
  111. package/src/client/hooks/editor/use-file-read.ts +16 -8
  112. package/src/client/hooks/editor/use-file-writes.ts +28 -3
  113. package/src/client/hooks/editor/use-mobile-editor-find.ts +69 -0
  114. package/src/client/hooks/editor/use-mobile-reveal.ts +53 -0
  115. package/src/client/hooks/editor/use-search-reveal-jump.ts +57 -0
  116. package/src/client/hooks/editor/use-split-editor.test.tsx +169 -0
  117. package/src/client/hooks/editor/use-split-editor.ts +91 -0
  118. package/src/client/hooks/editor/use-unload-guard.tsx +117 -0
  119. package/src/client/hooks/editor/use-write-conflict.test.ts +164 -0
  120. package/src/client/hooks/editor/use-write-conflict.ts +152 -0
  121. package/src/client/hooks/editor/wheel-zoom.test.ts +141 -0
  122. package/src/client/hooks/editor/wheel-zoom.ts +96 -0
  123. package/src/client/hooks/ui/drag-presence.test.ts +193 -0
  124. package/src/client/hooks/ui/drag-presence.ts +108 -0
  125. package/src/client/hooks/ui/settings-modal.test.ts +115 -0
  126. package/src/client/hooks/workspace/file-listing.ts +36 -24
  127. package/src/client/hooks/workspace/file-tabs.test.ts +90 -0
  128. package/src/client/hooks/workspace/file-tabs.ts +46 -0
  129. package/src/client/hooks/workspace/file-tree-edits.ts +103 -0
  130. package/src/client/lib/desktop/dropped-paths.ts +83 -0
  131. package/src/client/lib/editor/tab-menu.test.ts +127 -0
  132. package/src/client/lib/editor/tab-menu.ts +127 -0
  133. package/src/client/lib/editor-dirty-tabs.test.ts +102 -0
  134. package/src/client/lib/editor-dirty-tabs.ts +103 -0
  135. package/src/client/lib/native/resume.test.ts +66 -0
  136. package/src/client/lib/native/resume.ts +42 -0
  137. package/src/client/main.tsx +8 -0
  138. package/src/client/tailwind.css +38 -0
  139. package/src/server/lib/bundler/css.test.ts +31 -0
  140. package/src/server/lib/fs/listing.test.ts +81 -16
  141. package/src/server/lib/fs/listing.ts +72 -5
  142. package/src/server/lib/fs/write-conflict.test.ts +68 -0
  143. package/src/server/lib/fs/write-conflict.ts +84 -0
  144. package/src/server/routes/fs/action-save-as.test.ts +82 -0
  145. package/src/server/routes/fs/action.test.ts +82 -0
  146. package/src/server/routes/fs/action.ts +54 -1
  147. package/src/server/routes/fs/exists.ts +11 -1
  148. package/src/server/routes/fs/read.ts +6 -1
  149. package/src/shared/lib/code/editor/find-replace.test.ts +1 -1
  150. package/src/shared/lib/code/editor/find-scan.test.ts +1 -1
  151. package/src/shared/lib/code/editor/find-scan.ts +22 -1
  152. package/src/shared/lib/code/editor/find-selection.test.ts +56 -0
  153. package/src/shared/lib/code/editor/indent-guide-rule.test.ts +65 -0
  154. package/src/shared/lib/code/editor/indent-guide-rule.ts +47 -0
  155. package/src/shared/lib/code/editor/indent-rules.test.ts +219 -0
  156. package/src/shared/lib/code/editor/indent-rules.ts +198 -0
  157. package/src/shared/lib/code/editor/keymap.test.ts +23 -0
  158. package/src/shared/lib/code/editor/keymap.ts +40 -3
  159. package/src/shared/lib/code/editor/palette.test.ts +25 -2
  160. package/src/shared/lib/code/editor/palette.ts +10 -0
  161. package/src/shared/lib/code/editor/stream-modes.ts +225 -0
  162. package/src/shared/lib/code/syntax-highlight.test.ts +1 -1
  163. package/src/shared/lib/fs/file-tree.test.ts +41 -0
  164. package/src/shared/lib/fs/file-tree.ts +126 -34
  165. package/src/shared/lib/fs/folder-chain.test.ts +87 -0
  166. package/src/shared/lib/fs/folder-chain.ts +91 -0
  167. package/src/shared/lib/fs/fs-helpers.test.ts +4 -50
  168. package/src/shared/lib/realtime/connection.test.ts +5 -1
  169. package/src/shared/lib/realtime/connection.ts +25 -119
  170. package/src/shared/lib/realtime/frozen-recovery.test.ts +93 -0
  171. package/src/shared/lib/realtime/resume.ts +223 -0
  172. package/src/shared/lib/realtime/state.ts +22 -0
  173. package/src/shared/lib/realtime/watchdog-wiring.test.ts +224 -0
  174. package/src/shared/lib/realtime/watchdog.test.ts +99 -0
  175. package/src/shared/lib/realtime/watchdog.ts +72 -0
  176. package/src/shared/lib/workspace/split-editor.test.ts +104 -0
  177. package/src/shared/lib/workspace/split-editor.ts +129 -0
  178. package/src/test-support/file-explorer-disk.test-util.ts +30 -3
  179. package/src/test-support/pristine-globals.ts +7 -0
  180. package/dist/client/static/js/index-k315p1e8.css +0 -1
@@ -13,8 +13,11 @@
13
13
  * palette and unbound in the editor.
14
14
  *
15
15
  * VS Code's defaults are followed wherever this editor has an equivalent. Where
16
- * it has none — folding, go-to-definition, the `⌘K` prefix chords — the command
17
- * is absent rather than bound to something that would surprise.
16
+ * it has none — go-to-definition, the `⌘K` prefix chords — the command is absent
17
+ * rather than bound to something that would surprise. Folding used to be in that
18
+ * list; it is here now because the surface folds by INDENTATION (`fold.ts`), so
19
+ * the commands do something in every language rather than only in the 19 that
20
+ * have a grammar.
18
21
  */
19
22
 
20
23
  import type { KeyBinding, KeyStroke } from '@/shared/lib/ui/key-binding';
@@ -33,16 +36,24 @@ export type EditorCommand =
33
36
  | 'selectNextOccurrence'
34
37
  | 'selectAllOccurrences'
35
38
  | 'insertCursorBelow'
39
+ | 'insertCursorAbove'
36
40
  | 'moveLineUp'
37
41
  | 'moveLineDown'
38
42
  | 'copyLineUp'
39
43
  | 'copyLineDown'
40
44
  | 'deleteLine'
41
45
  | 'toggleComment'
46
+ | 'toggleBlockComment'
47
+ | 'joinLines'
48
+ | 'trimTrailingWhitespace'
42
49
  | 'insertLineBelow'
43
50
  | 'insertLineAbove'
44
51
  | 'indent'
45
52
  | 'outdent'
53
+ | 'fold'
54
+ | 'unfold'
55
+ | 'foldAll'
56
+ | 'unfoldAll'
46
57
  | 'undo'
47
58
  | 'redo'
48
59
  | 'lineStart'
@@ -53,8 +64,8 @@ export type EditorCommand =
53
64
  | 'selectToLineEnd'
54
65
  | 'selectToDocumentStart'
55
66
  | 'selectToDocumentEnd'
56
- | 'selectWord'
57
67
  | 'selectLine'
68
+ | 'goToLine'
58
69
  | 'escape';
59
70
 
60
71
  /**
@@ -67,6 +78,9 @@ export type EditorCommand =
67
78
  */
68
79
  export const EDITOR_KEY_BINDINGS: readonly KeyBinding<EditorCommand>[] = [
69
80
  { command: 'find', label: 'Find', mac: { code: 'KeyF', meta: true }, other: { code: 'KeyF', ctrl: true } },
81
+ // ⌘G is the convention (VS Code, Sublime, JetBrains); the browser's own "find
82
+ // next" is not a thing a document editor should defer to.
83
+ { command: 'goToLine', label: 'Go to line', mac: { code: 'KeyG', meta: true }, other: { code: 'KeyG', ctrl: true } },
70
84
  { command: 'replace', label: 'Replace', mac: { code: 'KeyF', meta: true, alt: true }, other: { code: 'KeyH', ctrl: true } },
71
85
  { command: 'nextMatch', label: 'Next match', mac: { code: 'F3' }, other: { code: 'F3' } },
72
86
  { command: 'previousMatch', label: 'Previous match', mac: { code: 'F3', shift: true }, other: { code: 'F3', shift: true } },
@@ -78,8 +92,15 @@ export const EDITOR_KEY_BINDINGS: readonly KeyBinding<EditorCommand>[] = [
78
92
  { command: 'toggleWordWrap', label: 'Toggle word wrap', mac: { code: 'KeyZ', alt: true }, other: { code: 'KeyZ', alt: true } },
79
93
 
80
94
  { command: 'selectNextOccurrence', label: 'Add selection to next find match', mac: { code: 'KeyD', meta: true }, other: { code: 'KeyD', ctrl: true } },
95
+ // `⌘L` expands the selection by LINE, which is the one line-selection gesture a
96
+ // browser does not already own (⌘L is the address bar in a browser tab, but this
97
+ // panel is not one — and the chord is what every editor uses for it).
98
+ { command: 'selectLine', label: 'Select line', mac: { code: 'KeyL', meta: true }, other: { code: 'KeyL', ctrl: true } },
81
99
  { command: 'selectAllOccurrences', label: 'Select all occurrences of current selection', mac: { code: 'KeyL', meta: true, shift: true }, other: { code: 'KeyL', ctrl: true, shift: true } },
82
100
  { command: 'insertCursorBelow', label: 'Insert cursor below', mac: { code: 'KeyD', meta: true, shift: true }, other: { code: 'KeyD', ctrl: true, shift: true } },
101
+ // The pair, so the palette lists both or neither: `addCursorBelow` had a row and
102
+ // this one was reachable only through CM6's own `defaultKeymap`.
103
+ { command: 'insertCursorAbove', label: 'Insert cursor above', mac: { code: 'KeyD', meta: true, alt: true }, other: { code: 'KeyD', ctrl: true, alt: true } },
83
104
 
84
105
  { command: 'moveLineUp', label: 'Move line up', mac: { code: 'ArrowUp', alt: true }, other: { code: 'ArrowUp', alt: true } },
85
106
  { command: 'moveLineDown', label: 'Move line down', mac: { code: 'ArrowDown', alt: true }, other: { code: 'ArrowDown', alt: true } },
@@ -91,12 +112,25 @@ export const EDITOR_KEY_BINDINGS: readonly KeyBinding<EditorCommand>[] = [
91
112
  // `Slash` is a physical key: on a US layout that is `/`, elsewhere it is
92
113
  // wherever the user's own layout puts it.
93
114
  { command: 'toggleComment', label: 'Toggle line comment', mac: { code: 'Slash', meta: true }, other: { code: 'Slash', ctrl: true } },
115
+ // The BLOCK form, which is a different command and not a variant of the line one:
116
+ // a language whose only syntax is a line comment (Python, YAML, shell) has nothing
117
+ // for it to do, and CM6 answers `false` there — an inert chord, which is honest.
118
+ { command: 'toggleBlockComment', label: 'Toggle block comment', mac: { code: 'Slash', meta: true, shift: true }, other: { code: 'Slash', ctrl: true, shift: true } },
119
+ { command: 'joinLines', label: 'Join lines', mac: { code: 'KeyJ', meta: true, alt: true }, other: { code: 'KeyJ', ctrl: true, alt: true } },
120
+ { command: 'trimTrailingWhitespace', label: 'Trim trailing whitespace', mac: { code: 'KeyX', meta: true, alt: true }, other: { code: 'KeyX', ctrl: true, alt: true } },
94
121
 
95
122
  { command: 'insertLineBelow', label: 'Insert line below', mac: { code: 'Enter', meta: true }, other: { code: 'Enter', ctrl: true } },
96
123
  { command: 'insertLineAbove', label: 'Insert line above', mac: { code: 'Enter', meta: true, shift: true }, other: { code: 'Enter', ctrl: true, shift: true } },
97
124
 
98
125
  { command: 'indent', label: 'Indent line', mac: { code: 'BracketRight', meta: true }, other: { code: 'BracketRight', ctrl: true } },
99
126
  { command: 'outdent', label: 'Outdent line', mac: { code: 'BracketLeft', meta: true }, other: { code: 'BracketLeft', ctrl: true } },
127
+ // The fold chords are CodeMirror's own (`foldKeymap`), kept because they are
128
+ // the convention every editor uses. `fold`/`unfold` carry `Shift` on
129
+ // Windows/Linux and `Alt` on macOS — the chords VS Code and CM6 both bind.
130
+ { command: 'fold', label: 'Fold block', mac: { code: 'BracketLeft', meta: true, alt: true }, other: { code: 'BracketLeft', ctrl: true, shift: true } },
131
+ { command: 'unfold', label: 'Unfold block', mac: { code: 'BracketRight', meta: true, alt: true }, other: { code: 'BracketRight', ctrl: true, shift: true } },
132
+ { command: 'foldAll', label: 'Fold all blocks', mac: { code: 'BracketLeft', ctrl: true, alt: true }, other: { code: 'BracketLeft', ctrl: true, alt: true } },
133
+ { command: 'unfoldAll', label: 'Unfold all blocks', mac: { code: 'BracketRight', ctrl: true, alt: true }, other: { code: 'BracketRight', ctrl: true, alt: true } },
100
134
 
101
135
  { command: 'undo', label: 'Undo', mac: { code: 'KeyZ', meta: true }, other: { code: 'KeyZ', ctrl: true } },
102
136
  {
@@ -123,6 +157,9 @@ export const EDITOR_KEY_BINDINGS: readonly KeyBinding<EditorCommand>[] = [
123
157
  */
124
158
  export const FIND_BAR_COMMANDS: readonly EditorCommand[] = [
125
159
  'find',
160
+ // The dialog lives in the panel, not the find bar, but it is dispatched the same
161
+ // way — one place a chord becomes an action.
162
+ 'goToLine',
126
163
  'replace',
127
164
  'nextMatch',
128
165
  'previousMatch',
@@ -47,11 +47,34 @@ describe('buildPaletteEntries', () => {
47
47
  });
48
48
 
49
49
  test('a command the keymap does not bind is not listed', () => {
50
- // `selectWord` has no binding by design; listing it would promise a chord.
50
+ // `escape` is dispatched by the panel's capture handler, never by a chord, so
51
+ // listing it would promise a shortcut nothing listens for.
51
52
  const commands = buildPaletteEntries(true).map((entry) => entry.command);
52
- expect(commands).not.toContain('selectWord');
53
53
  expect(commands).not.toContain('escape');
54
54
  });
55
+
56
+ test('every palette command has a binding — the reason `selectWord` is gone', () => {
57
+ // It was implemented and unreachable for two releases: no chord, and a test that
58
+ // asserted its absence from the palette. Deleting it is what made that state
59
+ // impossible to return to.
60
+ const commands = buildPaletteEntries(true).map((entry) => entry.command);
61
+ expect(commands).toContain('selectLine');
62
+ expect(commands).toContain('insertCursorAbove');
63
+ expect(commands).toContain('goToLine');
64
+ });
65
+
66
+ test('folding is listed, with the chord that actually fires', () => {
67
+ const entries = buildPaletteEntries(true);
68
+ const fold = entries.find((entry) => entry.command === 'fold');
69
+ const unfold = entries.find((entry) => entry.command === 'unfold');
70
+
71
+ expect(fold?.label).toBe('Fold block');
72
+ expect(fold?.chord).toBe('⌥⌘[');
73
+ expect(unfold?.chord).toBe('⌥⌘]');
74
+ // And the other platform's own spelling, from the same stroke.
75
+ const other = buildPaletteEntries(false).find((entry) => entry.command === 'fold');
76
+ expect(other?.chord).toBe('Ctrl+Shift+[');
77
+ });
55
78
  });
56
79
 
57
80
  describe('filterPaletteEntries', () => {
@@ -29,11 +29,17 @@ export interface PaletteEntry {
29
29
  */
30
30
  export const PALETTE_ORDER: readonly EditorCommand[] = [
31
31
  'find',
32
+ 'goToLine',
32
33
  'replace',
33
34
  'selectNextOccurrence',
34
35
  'selectAllOccurrences',
35
36
  'insertCursorBelow',
37
+ 'insertCursorAbove',
38
+ 'selectLine',
36
39
  'toggleComment',
40
+ 'toggleBlockComment',
41
+ 'joinLines',
42
+ 'trimTrailingWhitespace',
37
43
  'moveLineUp',
38
44
  'moveLineDown',
39
45
  'copyLineUp',
@@ -43,6 +49,10 @@ export const PALETTE_ORDER: readonly EditorCommand[] = [
43
49
  'insertLineAbove',
44
50
  'indent',
45
51
  'outdent',
52
+ 'fold',
53
+ 'unfold',
54
+ 'foldAll',
55
+ 'unfoldAll',
46
56
  'toggleWordWrap',
47
57
  'toggleCaseSensitive',
48
58
  'toggleWholeWord',
@@ -0,0 +1,225 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Which legacy stream mode backs each Shiki language id.
8
+ *
9
+ * The code surface highlights with Shiki and, since this table, ALSO parses with
10
+ * a `StreamLanguage` — which is what makes bracket matching token-aware. There
11
+ * is no lezer grammar here on purpose: measured, a lezer parser costs 39 KB gzip
12
+ * for JavaScript alone, covers 24 of the 59 languages this app names, and is
13
+ * WRONG about brackets until its lazy parse catches up (3 wrong pairs at mount
14
+ * on a 176-line file, and 2 still wrong on a 337-line one after a full parse). A
15
+ * stream mode is ~1 KB, covers 38 of the 59, and is correct at mount because its
16
+ * tree is built from the token stream with no parse worker.
17
+ *
18
+ * Two rules govern this table.
19
+ *
20
+ * **It is keyed by Shiki id, not by mode name.** `getLanguageFromPath` already
21
+ * answers a Shiki id for every extension, and that id is what the surface has in
22
+ * hand. A second naming scheme would mean two places to keep in step.
23
+ *
24
+ * **An id absent here keeps the textual matcher.** That is the honest state for
25
+ * the ids with no mode (php, graphql, nix, svelte, …): a wrong pair inside a
26
+ * string is better than no pairs at all, and `bracketMatching()` still answers
27
+ * every ordinary case. `TEXTUAL_ONLY_LANGS` names them so the gap is a decision
28
+ * rather than an omission, and a test asserts the two sets cover every language
29
+ * `shiki-langs` knows.
30
+ *
31
+ * ## Why the loaders are literal, one `import` per entry
32
+ *
33
+ * A template-literal specifier (`import(\`…/mode/${name}\`)`) builds fine but
34
+ * NEVER RESOLVES at runtime in the dev server: Bun rewrites it to
35
+ * `hmr.dynamicImport('@codemirror/legacy-modes/mode/${ref.module}')` with the
36
+ * placeholder unsubstituted, so the mode silently failed to load and the surface
37
+ * stayed on the textual matcher — measured in the browser, with no console error.
38
+ * The repo's proven pattern is `LANG_LOADERS`, one literal specifier per entry,
39
+ * which is what this mirrors.
40
+ *
41
+ * They are lazy for the same reason: all 38 modes in one bundle is +85 KB gzip,
42
+ * and a tab opened on a README should pay for none of it.
43
+ */
44
+
45
+ /** One stream mode: which module, and which export inside it. */
46
+ export interface StreamModeRef {
47
+ /** The module's specifier, as written in the loader table. */
48
+ module: string;
49
+ /** The export to take from it — several modules ship more than one mode. */
50
+ export: string;
51
+ }
52
+
53
+ /**
54
+ * The mode module for each Shiki id, as a lazy literal import.
55
+ *
56
+ * Every entry was checked against the installed `@codemirror/legacy-modes`: the
57
+ * module exists, and the export named in `STREAM_MODE_EXPORTS` is a real mode
58
+ * object (a test resolves all of them).
59
+ */
60
+ export const STREAM_MODE_LOADERS: Record<string, () => Promise<unknown>> = {
61
+ // JavaScript family — one module ships four modes.
62
+ typescript: () => import('@codemirror/legacy-modes/mode/javascript'),
63
+ tsx: () => import('@codemirror/legacy-modes/mode/javascript'),
64
+ javascript: () => import('@codemirror/legacy-modes/mode/javascript'),
65
+ jsx: () => import('@codemirror/legacy-modes/mode/javascript'),
66
+ json5: () => import('@codemirror/legacy-modes/mode/javascript'),
67
+ json: () => import('@codemirror/legacy-modes/mode/javascript'),
68
+
69
+ // Data and config
70
+ yaml: () => import('@codemirror/legacy-modes/mode/yaml'),
71
+ toml: () => import('@codemirror/legacy-modes/mode/toml'),
72
+ ini: () => import('@codemirror/legacy-modes/mode/properties'),
73
+ properties: () => import('@codemirror/legacy-modes/mode/properties'),
74
+ hcl: () => import('@codemirror/legacy-modes/mode/properties'),
75
+
76
+ // Markup and styles
77
+ css: () => import('@codemirror/legacy-modes/mode/css'),
78
+ less: () => import('@codemirror/legacy-modes/mode/css'),
79
+ scss: () => import('@codemirror/legacy-modes/mode/css'),
80
+ sass: () => import('@codemirror/legacy-modes/mode/sass'),
81
+ stylus: () => import('@codemirror/legacy-modes/mode/stylus'),
82
+ xml: () => import('@codemirror/legacy-modes/mode/xml'),
83
+
84
+ // Shell and scripting
85
+ bash: () => import('@codemirror/legacy-modes/mode/shell'),
86
+ python: () => import('@codemirror/legacy-modes/mode/python'),
87
+ ruby: () => import('@codemirror/legacy-modes/mode/ruby'),
88
+ perl: () => import('@codemirror/legacy-modes/mode/perl'),
89
+ lua: () => import('@codemirror/legacy-modes/mode/lua'),
90
+ powershell: () => import('@codemirror/legacy-modes/mode/powershell'),
91
+
92
+ // Compiled and systems
93
+ go: () => import('@codemirror/legacy-modes/mode/go'),
94
+ rust: () => import('@codemirror/legacy-modes/mode/rust'),
95
+ c: () => import('@codemirror/legacy-modes/mode/clike'),
96
+ cpp: () => import('@codemirror/legacy-modes/mode/clike'),
97
+ csharp: () => import('@codemirror/legacy-modes/mode/clike'),
98
+ java: () => import('@codemirror/legacy-modes/mode/clike'),
99
+ kotlin: () => import('@codemirror/legacy-modes/mode/clike'),
100
+ scala: () => import('@codemirror/legacy-modes/mode/clike'),
101
+ dart: () => import('@codemirror/legacy-modes/mode/clike'),
102
+ 'objective-c': () => import('@codemirror/legacy-modes/mode/clike'),
103
+ swift: () => import('@codemirror/legacy-modes/mode/swift'),
104
+
105
+ // Functional
106
+ haskell: () => import('@codemirror/legacy-modes/mode/haskell'),
107
+ elixir: () => import('@codemirror/legacy-modes/mode/erlang'),
108
+ erlang: () => import('@codemirror/legacy-modes/mode/erlang'),
109
+ clojure: () => import('@codemirror/legacy-modes/mode/clojure'),
110
+ scheme: () => import('@codemirror/legacy-modes/mode/scheme'),
111
+ racket: () => import('@codemirror/legacy-modes/mode/scheme'),
112
+ ocaml: () => import('@codemirror/legacy-modes/mode/mllike'),
113
+
114
+ // Other
115
+ r: () => import('@codemirror/legacy-modes/mode/r'),
116
+ julia: () => import('@codemirror/legacy-modes/mode/julia'),
117
+ sql: () => import('@codemirror/legacy-modes/mode/sql'),
118
+ dockerfile: () => import('@codemirror/legacy-modes/mode/dockerfile'),
119
+ protobuf: () => import('@codemirror/legacy-modes/mode/protobuf'),
120
+ makefile: () => import('@codemirror/legacy-modes/mode/cmake'),
121
+ groovy: () => import('@codemirror/legacy-modes/mode/groovy'),
122
+ };
123
+
124
+ /**
125
+ * The export to take from each id's module.
126
+ *
127
+ * Separate from the loaders because several modules ship more than one mode
128
+ * (`javascript` has four, `clike` has fourteen, `sql` has fifteen) and the
129
+ * export name is not derivable from the Shiki id — `objective-c` is
130
+ * `objectiveC`, `scss` is `sCSS`, `dockerfile` is `dockerFile`.
131
+ */
132
+ export const STREAM_MODE_EXPORTS: Record<string, string> = {
133
+ typescript: 'typescript',
134
+ tsx: 'typescript',
135
+ javascript: 'javascript',
136
+ jsx: 'javascript',
137
+ json5: 'json',
138
+ json: 'json',
139
+
140
+ yaml: 'yaml',
141
+ toml: 'toml',
142
+ ini: 'properties',
143
+ properties: 'properties',
144
+ hcl: 'properties',
145
+
146
+ css: 'css',
147
+ less: 'less',
148
+ scss: 'sCSS',
149
+ sass: 'sass',
150
+ stylus: 'stylus',
151
+ xml: 'xml',
152
+
153
+ bash: 'shell',
154
+ python: 'python',
155
+ ruby: 'ruby',
156
+ perl: 'perl',
157
+ lua: 'lua',
158
+ powershell: 'powerShell',
159
+
160
+ go: 'go',
161
+ rust: 'rust',
162
+ c: 'c',
163
+ cpp: 'cpp',
164
+ csharp: 'csharp',
165
+ java: 'java',
166
+ kotlin: 'kotlin',
167
+ scala: 'scala',
168
+ dart: 'dart',
169
+ 'objective-c': 'objectiveC',
170
+ swift: 'swift',
171
+
172
+ haskell: 'haskell',
173
+ elixir: 'erlang',
174
+ erlang: 'erlang',
175
+ clojure: 'clojure',
176
+ scheme: 'scheme',
177
+ racket: 'scheme',
178
+ ocaml: 'oCaml',
179
+
180
+ r: 'r',
181
+ julia: 'julia',
182
+ sql: 'standardSQL',
183
+ dockerfile: 'dockerFile',
184
+ protobuf: 'protobuf',
185
+ makefile: 'cmake',
186
+ groovy: 'groovy',
187
+ };
188
+
189
+ /**
190
+ * Shiki ids this build can NOT make token-aware.
191
+ *
192
+ * Listed rather than left implicit so the gap is a statement: these keep the
193
+ * textual bracket matcher, and a test asserts the two sets together cover every
194
+ * id `shiki-langs` knows — a new language added there without a decision here
195
+ * fails rather than silently falling back.
196
+ */
197
+ export const TEXTUAL_ONLY_LANGS: readonly string[] = [
198
+ 'markdown',
199
+ 'html',
200
+ 'diff',
201
+ 'graphql',
202
+ 'nix',
203
+ 'svelte',
204
+ 'astro',
205
+ 'vue',
206
+ // No mode ships for these, and `clike` is a FACTORY (not a mode), so a
207
+ // language with no dedicated export cannot borrow one.
208
+ 'zig',
209
+ 'solidity',
210
+ 'php',
211
+ 'text',
212
+ ];
213
+
214
+ /** The mode for a Shiki id, or null when this build has none. */
215
+ export function streamModeFor(language: string): StreamModeRef | null {
216
+ const loader = STREAM_MODE_LOADERS[language];
217
+ const exportName = STREAM_MODE_EXPORTS[language];
218
+ if (!loader || !exportName) return null;
219
+ return { module: language, export: exportName };
220
+ }
221
+
222
+ /** The lazy loader for a Shiki id, or null. */
223
+ export function streamModeLoader(language: string): (() => Promise<unknown>) | null {
224
+ return STREAM_MODE_LOADERS[language] ?? null;
225
+ }
@@ -116,7 +116,7 @@ describe('highlightCode', () => {
116
116
 
117
117
  describe('find marks', () => {
118
118
  const code = 'const alpha = 1;\nconst beta = alpha + 2;\n';
119
- const PLAIN = { matchCase: false, wholeWord: false, isRegex: false };
119
+ const PLAIN = { matchCase: false, wholeWord: false, isRegex: false, inSelection: false };
120
120
  /** The text of every mark, in order. A match spanning tokens is several
121
121
  * fragments, so the assertion is on the fragments JOINED. */
122
122
  const marked = (html: string): string[] =>
@@ -31,6 +31,7 @@ import {
31
31
  baseNameOf,
32
32
  parentPathOf,
33
33
  placeEntry,
34
+ rehydrateTree,
34
35
  rekeyCache,
35
36
  rekeyExpansion,
36
37
  renameEntryAt,
@@ -87,6 +88,46 @@ describe('placeEntry', () => {
87
88
  expect(placed.nodes[0].type).toBe('folder');
88
89
  expect(placed.nodes[0].children).toBeUndefined();
89
90
  });
91
+
92
+ test('an entry under a collapsed chain row descends into it', () => {
93
+ // The tree draws `lib/deep` as ONE row, whose children are `lib/deep`'s.
94
+ const tree = [folder('lib/deep', [])];
95
+ const placed = placeEntry(tree, { 'lib/deep': [] }, file('lib/deep/x.ts'));
96
+
97
+ expect(placed.nodes).toHaveLength(1);
98
+ expect(placed.cache['lib/deep']?.map((node) => node.path)).toEqual(['lib/deep/x.ts']);
99
+ });
100
+
101
+ test('an entry beside a chain row unfolds it rather than drawing the folder twice', () => {
102
+ // `lib` holds only `deep`, so the tree draws one row named `lib/deep`. An
103
+ // entry at `lib/other/x.ts` means `lib` now has two children — the row is
104
+ // unfolded into `lib` holding `deep`, and the new chain is inserted under it.
105
+ const tree = [folder('lib/deep', [file('lib/deep/a.ts')])];
106
+ const placed = placeEntry(tree, { 'lib/deep': [file('lib/deep/a.ts')] }, file('lib/other/x.ts'));
107
+
108
+ expect(placed.nodes.map((node) => node.path)).toEqual(['lib']);
109
+ expect(placed.cache.lib?.map((node) => node.path)).toEqual(['lib/deep', 'lib/other']);
110
+ expect(placed.cache['lib/other']?.map((node) => node.path)).toEqual(['lib/other/x.ts']);
111
+ // The chain's own children keep their cache entry, keyed by the path they
112
+ // already had, so an open `lib/deep` stays open.
113
+ expect(placed.cache['lib/deep']?.map((node) => node.path)).toEqual(['lib/deep/a.ts']);
114
+ });
115
+
116
+ test('an entry in a sibling branch unfolds the chain once and lands under it', () => {
117
+ // The tree draws `com/java/app/package` as ONE row. An entry at
118
+ // `com/java/other/deep/x.ts` shares `com/java`, so the row is unfolded and
119
+ // BOTH branches sit inside it — never `com` twice.
120
+ const tree = [folder('com/java/app/package', [file('com/java/app/package/Main.java')])];
121
+ const placed = placeEntry(tree, {}, file('com/java/other/deep/x.ts'));
122
+ const drawn = rehydrateTree(placed.nodes, placed.cache);
123
+
124
+ expect(drawn.map((node) => node.name)).toEqual(['com/java']);
125
+ expect(drawn[0]!.children?.map((node) => node.name)).toEqual(['app/package', 'other/deep']);
126
+ expect(drawn[0]!.children?.[0]!.children?.map((node) => node.path))
127
+ .toEqual(['com/java/app/package/Main.java']);
128
+ expect(drawn[0]!.children?.[1]!.children?.map((node) => node.path))
129
+ .toEqual(['com/java/other/deep/x.ts']);
130
+ });
90
131
  });
91
132
 
92
133
  describe('takeEntry', () => {