@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
@@ -21,8 +21,8 @@
21
21
 
22
22
  import { useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks';
23
23
  import type { ComponentChildren } from 'preact';
24
+ import { createPortal } from 'preact/compat';
24
25
  import { Ellipsis, type LucideIcon } from 'lucide-preact';
25
- import { useOnClickOutside } from '@/client/hooks/ui/on-click-outside';
26
26
  import { toolbarHasOverflow, toolbarVisibleClusters } from '@/shared/lib/ui/toolbar-overflow';
27
27
 
28
28
  /** One row the `⋯` menu offers when its cluster is not on the row. */
@@ -106,8 +106,17 @@ export function ToolbarRow({ clusters, className = '' }: ToolbarRowProps) {
106
106
 
107
107
  const hiddenActions = clusters.filter((_, index) => !visible[index]).flatMap((cluster) => cluster.actions);
108
108
 
109
+ // `flex-1 min-w-0` is what makes `available` mean anything. Without it the row
110
+ // is content-sized (`ml-auto` in a `justify-between` parent), so its width IS
111
+ // the sum of the clusters it currently shows — hiding one shrinks the row,
112
+ // which shrinks `available`, which hides another, and the row settles at a
113
+ // fraction of the space it was given and never grows back when the panel is
114
+ // widened. Measured: a 373px diff panel reported a 204px row at every
115
+ // viewport, so Unified/Split/Full Code lived in `⋯` on a wide screen. `min-w-0`
116
+ // is required with it, or the `flex-shrink-0` clusters set a content-based
117
+ // minimum and the row refuses to be narrower than all of them.
109
118
  return (
110
- <div ref={rowRef} className={`flex flex-nowrap items-center justify-end gap-x-1 overflow-hidden ${className}`}>
119
+ <div ref={rowRef} className={`flex flex-1 min-w-0 flex-nowrap items-center justify-end gap-x-1 overflow-hidden ${className}`}>
111
120
  {clusters.map((cluster, index) =>
112
121
  visible[index] ? (
113
122
  <div key={cluster.id} data-toolbar-cluster="" className="flex items-center flex-shrink-0">
@@ -127,11 +136,44 @@ export function ToolbarRow({ clusters, className = '' }: ToolbarRowProps) {
127
136
  * diff toolbar already learned that a scroll strip with no visible scrollbar
128
137
  * reads as "there is nothing more here" (measured: 361px of content in a 296px
129
138
  * box, with `Stage` entirely outside it).
139
+ *
140
+ * The menu is PORTALLED to `document.body`, and that is not a preference — the
141
+ * row it hangs from is `overflow-hidden` and only one line tall, so an
142
+ * absolutely-positioned menu below the trigger is clipped to nothing. Measured
143
+ * before the portal: the menu laid out at 208×206px and `elementFromPoint` at
144
+ * its own centre answered a `.cm-line` in the diff BEHIND it, so every row was
145
+ * invisible and unclickable while the trigger reported `aria-expanded="true"`.
146
+ * A `fixed` menu inside the row would not help either: `overflow-hidden` clips
147
+ * a fixed descendant too, because the row establishes the containing block.
148
+ *
149
+ * Position comes from the trigger's own viewport rect, clamped against both
150
+ * edges, so a menu on the right-hand toolbar of a narrow panel cannot draw its
151
+ * rows past the window.
130
152
  */
131
153
  function OverflowMenu({ actions }: { actions: ToolbarOverflowAction[] }) {
132
154
  const [open, setOpen] = useState(false);
155
+ const [position, setPosition] = useState<{ top: number; left: number } | null>(null);
133
156
  const rootRef = useRef<HTMLDivElement>(null);
134
- useOnClickOutside(rootRef, () => setOpen(false));
157
+ const menuRef = useRef<HTMLDivElement>(null);
158
+
159
+ // A dismiss handler that knows about BOTH nodes. `useOnClickOutside` takes one
160
+ // ref, and the menu is no longer inside the trigger's subtree — a mousedown on
161
+ // a menu row would read as "outside", close the menu, and the `click` would
162
+ // never reach the button. That is the same dead menu in a new shape.
163
+ useEffect(() => {
164
+ if (!open) return;
165
+ const onPointerDown = (event: globalThis.MouseEvent | globalThis.TouchEvent) => {
166
+ const target = event.target as Node;
167
+ if (rootRef.current?.contains(target) || menuRef.current?.contains(target)) return;
168
+ setOpen(false);
169
+ };
170
+ document.addEventListener('mousedown', onPointerDown);
171
+ document.addEventListener('touchstart', onPointerDown);
172
+ return () => {
173
+ document.removeEventListener('mousedown', onPointerDown);
174
+ document.removeEventListener('touchstart', onPointerDown);
175
+ };
176
+ }, [open]);
135
177
 
136
178
  useEffect(() => {
137
179
  if (!open) return;
@@ -142,6 +184,22 @@ function OverflowMenu({ actions }: { actions: ToolbarOverflowAction[] }) {
142
184
  return () => document.removeEventListener('keydown', onKeyDown);
143
185
  }, [open]);
144
186
 
187
+ // Measured before paint, and re-measured when the row's own size changes: the
188
+ // trigger sits at the row's trailing edge, so a panel drag moves it.
189
+ useLayoutEffect(() => {
190
+ if (!open) return;
191
+ const trigger = rootRef.current?.firstElementChild as HTMLElement | null;
192
+ const menu = menuRef.current;
193
+ if (!trigger || !menu) return;
194
+ const anchor = trigger.getBoundingClientRect();
195
+ const { width, height } = menu.getBoundingClientRect();
196
+ const margin = 8;
197
+ const below = anchor.bottom + 4;
198
+ const top = below + height + margin <= window.innerHeight ? below : Math.max(margin, anchor.top - height - 4);
199
+ const left = Math.max(margin, Math.min(anchor.right - width, window.innerWidth - width - margin));
200
+ setPosition({ top, left });
201
+ }, [open, actions.length]);
202
+
145
203
  return (
146
204
  <div className="relative flex-shrink-0" ref={rootRef}>
147
205
  <button
@@ -150,7 +208,10 @@ function OverflowMenu({ actions }: { actions: ToolbarOverflowAction[] }) {
150
208
  aria-label="More actions"
151
209
  aria-haspopup="menu"
152
210
  aria-expanded={open}
153
- onClick={() => setOpen(!open)}
211
+ onClick={() => {
212
+ setPosition(null);
213
+ setOpen(!open);
214
+ }}
154
215
  className={`flex items-center justify-center p-1.5 rounded transition-colors cursor-pointer ${
155
216
  open ? 'bg-ink/10 text-ink' : 'text-ink/50 hover:text-ink hover:bg-ink/5'
156
217
  }`}
@@ -158,32 +219,42 @@ function OverflowMenu({ actions }: { actions: ToolbarOverflowAction[] }) {
158
219
  <Ellipsis size={14} />
159
220
  </button>
160
221
 
161
- {open && (
162
- <div
163
- role="menu"
164
- className="absolute right-0 top-full mt-1 w-52 bg-paper border border-ink/15 rounded-lg shadow-lg z-50 py-1 text-xs"
165
- >
166
- {actions.map((action) => (
167
- <button
168
- key={action.label}
169
- type="button"
170
- role="menuitem"
171
- disabled={action.disabled}
172
- aria-pressed={action.active}
173
- onClick={() => {
174
- setOpen(false);
175
- action.onSelect();
176
- }}
177
- className={`w-full text-left flex items-center gap-2 px-3 py-1.5 transition-colors disabled:cursor-default disabled:opacity-40 ${
178
- action.active ? 'bg-ink/5 text-ink font-medium' : 'text-ink/75 hover:bg-ink/5 hover:text-ink'
179
- }`}
180
- >
181
- <action.icon size={13} className="flex-shrink-0" />
182
- <span className="truncate">{action.label}</span>
183
- </button>
184
- ))}
185
- </div>
186
- )}
222
+ {open &&
223
+ createPortal(
224
+ <div
225
+ ref={menuRef}
226
+ role="menu"
227
+ style={{
228
+ top: position?.top ?? 0,
229
+ left: position?.left ?? 0,
230
+ // Hidden for the single pre-measure render; the layout effect
231
+ // settles the position before the browser paints.
232
+ visibility: position ? 'visible' : 'hidden',
233
+ }}
234
+ className="fixed z-[80] w-52 bg-paper border border-ink/15 rounded-lg shadow-lg py-1 text-xs"
235
+ >
236
+ {actions.map((action) => (
237
+ <button
238
+ key={action.label}
239
+ type="button"
240
+ role="menuitem"
241
+ disabled={action.disabled}
242
+ aria-pressed={action.active}
243
+ onClick={() => {
244
+ setOpen(false);
245
+ action.onSelect();
246
+ }}
247
+ className={`w-full text-left flex items-center gap-2 px-3 py-1.5 transition-colors disabled:cursor-default disabled:opacity-40 ${
248
+ action.active ? 'bg-ink/5 text-ink font-medium' : 'text-ink/75 hover:bg-ink/5 hover:text-ink'
249
+ }`}
250
+ >
251
+ <action.icon size={13} className="flex-shrink-0" />
252
+ <span className="truncate">{action.label}</span>
253
+ </button>
254
+ ))}
255
+ </div>,
256
+ document.body,
257
+ )}
187
258
  </div>
188
259
  );
189
260
  }
@@ -68,6 +68,11 @@ interface WorkspacePanelsProps {
68
68
  onConvertDiffToEditor: (id: number | string) => void;
69
69
  onOpenFile: (file: any) => void;
70
70
  onRefreshWorkspace: () => void;
71
+ /** The tab strip's menu: reopen a closed tab, copy a path, reveal a file. */
72
+ onReopenClosed?: () => boolean;
73
+ reopenableCount?: () => number;
74
+ onCopyPath?: (tab: import('@/shared/types/fs').OpenedFile) => void;
75
+ onRevealInFiles?: (tab: import('@/shared/types/fs').OpenedFile) => void;
71
76
  /** The outcome of a file dropped on the chat or the editor, for the toasts. */
72
77
  onDropResult?: (result: EditorDropResult) => void;
73
78
  onChangeRightPanel: (panel: string) => void;
@@ -99,6 +104,10 @@ export function WorkspacePanels(props: WorkspacePanelsProps) {
99
104
  onConvertDiffToEditor,
100
105
  onOpenFile,
101
106
  onRefreshWorkspace,
107
+ onReopenClosed,
108
+ reopenableCount,
109
+ onCopyPath,
110
+ onRevealInFiles,
102
111
  onDropResult,
103
112
  onChangeRightPanel,
104
113
  onToggleRightPanel,
@@ -248,6 +257,14 @@ export function WorkspacePanels(props: WorkspacePanelsProps) {
248
257
  onConvertDiffToEditor={onConvertDiffToEditor}
249
258
  refreshKey={refreshKey}
250
259
  onFileSaved={onRefreshWorkspace}
260
+ // Quick open answers workspace-relative paths, so it goes through the
261
+ // same opener every other surface uses — one id scheme per path.
262
+ onOpenPath={(path) => onOpenFile({ path, name: path.split('/').pop() ?? path })}
263
+ rootPath={activeProjectPath ?? null}
264
+ onReopenClosed={onReopenClosed}
265
+ reopenableCount={reopenableCount}
266
+ onCopyPath={onCopyPath}
267
+ onRevealInFiles={onRevealInFiles}
251
268
  />
252
269
  </PanelSuspense>
253
270
  </div>
@@ -5,6 +5,7 @@ import { LeftColumn } from '@/client/components/layout/desktop-layout/LeftColumn
5
5
  import { SettingsModal } from '@/client/components/settings/LazyModal';
6
6
  import { activeProjectForSession, effectiveRootFor } from '@/shared/lib/workspace/active-project';
7
7
  import { useFileTabs } from '@/client/hooks/workspace/file-tabs';
8
+ import type { OpenedFile } from '@/shared/types/fs';
8
9
  import { useSessionState } from '@/client/hooks/workspace/session-state';
9
10
  import { TopNavbar } from '@/client/components/layout/desktop-layout/TopNavbar';
10
11
  import { WorkspacePanels } from '@/client/components/layout/desktop-layout/WorkspacePanels';
@@ -89,9 +90,23 @@ export function DesktopLayout({ sessionId, onSwitchToMobile, appSettings = {} }:
89
90
  setActiveFileId,
90
91
  handleOpenFile,
91
92
  handleCloseFile,
93
+ handleReopenClosed,
94
+ reopenableCount,
92
95
  convertDiffToEditor,
93
96
  } = useFileTabs(activeProjectPath, sessionId || '', handleOpenTab);
94
97
 
98
+ /**
99
+ * The tab menu's two scope-dependent actions.
100
+ *
101
+ * Copy Path needs the tab's own path (which may be a diff's), and Reveal needs the
102
+ * Files panel to expand to it — both live here because the strip has no workspace
103
+ * scope of its own.
104
+ */
105
+ const handleCopyTabPath = useCallback((tab: OpenedFile) => {
106
+ if (!tab.path) return;
107
+ void navigator.clipboard?.writeText(tab.path);
108
+ }, []);
109
+
95
110
  // Three ways the column has content: a file, a chosen takeover, and a
96
111
  // takeover that merely exists. Only the first two OPEN it — installing a
97
112
  // plugin must not push a column onto the screen — but the third is what the
@@ -290,6 +305,9 @@ export function DesktopLayout({ sessionId, onSwitchToMobile, appSettings = {} }:
290
305
  onSetActiveFileId={setActiveFileId}
291
306
  onCloseFile={handleCloseFile}
292
307
  onConvertDiffToEditor={convertDiffToEditor}
308
+ onReopenClosed={handleReopenClosed}
309
+ reopenableCount={reopenableCount}
310
+ onCopyPath={handleCopyTabPath}
293
311
  onOpenFile={handleOpenFile}
294
312
  onRefreshWorkspace={handleRefreshWorkspace}
295
313
  onDropResult={handleDropResult}
@@ -1,4 +1,4 @@
1
- import { useEffect, useRef, useState } from 'preact/hooks';
1
+ import { useRef, useState } from 'preact/hooks';
2
2
  import { AlertTriangle, FileX, Loader2 } from 'lucide-preact';
3
3
  import { MarkdownRenderer } from '@/client/components/common/MarkdownRenderer';
4
4
  import { CodeSurface, type CodeSurfaceHandle } from '@/client/components/common/code-surface';
@@ -10,7 +10,9 @@ import { EditorDropOverlay } from '@/client/components/workspace/editor/EditorDr
10
10
  import { useEditorDrop } from '@/client/hooks/editor/use-editor-drop';
11
11
  import { useScrollRestore } from '@/client/hooks/editor/use-scroll-restore';
12
12
  import { useFileEditor } from '@/client/hooks/editor/use-file-editor';
13
- import { useSearchRevealTarget } from '@/client/hooks/editor/use-search-reveal';
13
+ import { useMobileEditorFind } from '@/client/hooks/editor/use-mobile-editor-find';
14
+ import { FindWidget } from '@/client/components/workspace/editor/FindWidget';
15
+
14
16
  import { useEditorOutlineBridge } from '@/client/hooks/editor/use-editor-outline-bridge';
15
17
  import { MobileOutlineButton } from '@/client/components/mobile/mobile-right-sidebar/OutlineButton';
16
18
  import { useOutlineView } from '@/client/hooks/editor/use-outline-view';
@@ -22,21 +24,12 @@ import {
22
24
  } from '@/shared/lib/code/editor/typography';
23
25
  import { useEditorFontStack } from '@/client/hooks/editor/font';
24
26
  import { useEditorTheme } from '@/client/hooks/editor/theme';
27
+ import { indentUnitFor, useEditorIndent } from '@/client/hooks/editor/indent-settings';
28
+ import { useEditorTyping } from '@/client/hooks/editor/typing-settings';
25
29
  import { MOBILE_SCROLL_POSITIONS_KEY } from '@/shared/lib/workspace/scroll-positions';
26
30
  import { ViewerSurface, hasViewerSurface } from '@/client/components/workspace/editor/viewers/dispatch';
27
31
  import { BINARY_VIEWERS, RENDERED_VIEWERS, VIEWER_LABELS, viewerKindFor } from '@/shared/lib/fs/document-kind';
28
- import type { MobileEditorFile } from '@/client/components/mobile/open-file-payload';
29
-
30
- interface MobileFullEditorProps {
31
- file: MobileEditorFile;
32
- onClose: () => void;
33
- /** The file this editor names is gone from disk. */
34
- missing?: boolean;
35
- /** Fired after a debounced write lands, so the workspace panels can refresh. */
36
- onFileSaved?: () => void;
37
- /** The outcome of a file dropped on this editor, for the host's toast stack. */
38
- onDropResult?: (result: { ok: boolean; message: string }) => void;
39
- }
32
+ import type { MobileFullEditorProps } from '@/client/components/mobile/mobile-right-sidebar/editor-props';
40
33
 
41
34
  export function MobileFullEditor({ file, missing = false, onClose, onFileSaved, onDropResult }: MobileFullEditorProps) {
42
35
  const viewerKind = viewerKindFor(file.path ?? file.name);
@@ -48,9 +41,12 @@ export function MobileFullEditor({ file, missing = false, onClose, onFileSaved,
48
41
  // per-tab memory the desktop pane keeps.
49
42
  const [previewOverrides, setPreviewOverrides] = useState<Record<string, boolean>>({});
50
43
  const [fontSize, setFontSize] = useState(EDITOR_DEFAULT_FONT_SIZE);
44
+
51
45
  const [wordWrap, setWordWrap] = useState(true);
52
46
  const editorFontFamily = useEditorFontStack();
53
47
  const editorTheme = useEditorTheme();
48
+ const editorIndent = useEditorIndent();
49
+ const editorTyping = useEditorTyping();
54
50
 
55
51
  const isMd = viewerKind === 'markdown';
56
52
  // A byte viewer (image, PDF, DOCX, workbook) owns the whole surface and has
@@ -101,26 +97,18 @@ export function MobileFullEditor({ file, missing = false, onClose, onFileSaved,
101
97
  element: isMd && isPreview ? undefined : codeScroller,
102
98
  });
103
99
 
104
- // A search row on the phone opens this full-screen editor, so the hand-off
105
- // has to be served here too: the matched ranges are painted, and the caret is
106
- // placed on the hit once the buffer is on screen.
107
- const reveal = useSearchRevealTarget(
108
- file.path ?? null,
109
- editor.content,
110
- editor.loaded && !editor.loadError,
111
- );
112
100
  const surfaceRef = useRef<CodeSurfaceHandle | null>(null);
113
- const revealMarks = reveal && reveal.matches.length > 0 ? reveal.matches : undefined;
114
- const currentMark = reveal?.currentIndex ?? -1;
115
- const firedRef = useRef<unknown>(null);
116
- useEffect(() => {
117
- if (!reveal || firedRef.current === reveal.request) return;
118
- firedRef.current = reveal.request;
119
- const match = reveal.matches[reveal.currentIndex];
120
- if (!match) return;
121
- surfaceRef.current?.select(match.start, match.end, false);
122
- surfaceRef.current?.revealOffset(match.start);
123
- }, [reveal]);
101
+ // Find, and the search row's hand-off. Both are the desktop's own hooks: a second
102
+ // implementation would be a second answer to "which occurrences count", and the phone
103
+ // was the one surface with no way to search a file at all.
104
+ const { find, revealMarks, currentMark } = useMobileEditorFind({
105
+ path: file.path ?? null,
106
+ content: editor.content,
107
+ documentKey: `${fileKey}\u0000${editor.language}`,
108
+ ready: editor.loaded && !editor.loadError,
109
+ surfaceRef,
110
+ toggleWordWrap: () => setWordWrap((previous) => !previous),
111
+ });
124
112
 
125
113
  const content = editor.content;
126
114
  const lang = editor.language;
@@ -180,6 +168,8 @@ export function MobileFullEditor({ file, missing = false, onClose, onFileSaved,
180
168
  onSave={editor.saveNow}
181
169
  onClose={onClose}
182
170
  onTogglePreview={togglePreview}
171
+ onToggleFind={() => (find.open ? find.close() : find.openFind())}
172
+ findOpen={find.open}
183
173
  onToggleWrap={() => setWordWrap(!wordWrap)}
184
174
  onZoomOut={() => setFontSize(prev => Math.max(EDITOR_MIN_FONT_SIZE, prev - 1))}
185
175
  onZoomIn={() => setFontSize(prev => Math.min(EDITOR_MAX_FONT_SIZE, prev + 1))}
@@ -202,6 +192,16 @@ export function MobileFullEditor({ file, missing = false, onClose, onFileSaved,
202
192
  </div>
203
193
  )}
204
194
 
195
+ {/* Find/replace, as a ROW under the header rather than a floating card: the
196
+ desktop bar is 330px wide, and on a 390px screen a floating card would cover
197
+ the very lines it is searching. `FindWidget` is absolutely positioned in its
198
+ own stylesheet, so it is wrapped in a `relative` box that owns its own row. */}
199
+ {find.open && !byteViewer && (
200
+ <div className="relative shrink-0 h-9 border-b border-ink/10 bg-paper">
201
+ <FindWidget find={find} />
202
+ </div>
203
+ )}
204
+
205
205
  {/* Editor Content Area - Desktop styled: bg-paper text-ink. An image owns
206
206
  its own pan/zoom, so it replaces the scrolling text container rather
207
207
  than living inside it; the same is true of every other byte viewer and
@@ -292,6 +292,8 @@ export function MobileFullEditor({ file, missing = false, onClose, onFileSaved,
292
292
  className="flex-1 min-h-0 text-ink select-text"
293
293
  themeVars={editorTheme.vars}
294
294
  themes={editorTheme.themes}
295
+ indentUnitText={indentUnitFor(editorIndent)}
296
+ typing={editorTyping}
295
297
  padding={12}
296
298
  style={{
297
299
  fontFamily: editorFontFamily,
@@ -1,4 +1,4 @@
1
- import { ArrowLeft, Check, Copy, Download, Eye, EyeOff, Save, WrapText, ZoomIn, ZoomOut } from 'lucide-preact';
1
+ import { ArrowLeft, Check, Copy, Download, Eye, EyeOff, Save, Search, WrapText, ZoomIn, ZoomOut } from 'lucide-preact';
2
2
  import { FileIcon } from '@/client/components/common/file-icon';
3
3
  import { titlebarPaddingLeft, titlebarPaddingRight } from '@/shared/lib/ui/titlebar';
4
4
 
@@ -17,6 +17,10 @@ interface EditorHeaderProps {
17
17
  onSave?: () => void;
18
18
  onClose: () => void;
19
19
  onTogglePreview: () => void;
20
+ /** Find/replace in the file. The phone had no way to search a file at all. */
21
+ onToggleFind: () => void;
22
+ /** The bar is open — the control reflects it. */
23
+ findOpen: boolean;
20
24
  onToggleWrap: () => void;
21
25
  onZoomOut: () => void;
22
26
  onZoomIn: () => void;
@@ -36,6 +40,8 @@ export function EditorHeader({
36
40
  onSave,
37
41
  onClose,
38
42
  onTogglePreview,
43
+ onToggleFind,
44
+ findOpen,
39
45
  onToggleWrap,
40
46
  onZoomOut,
41
47
  onZoomIn,
@@ -87,6 +93,19 @@ export function EditorHeader({
87
93
  </button>
88
94
  )}
89
95
 
96
+ {!byteViewer && (
97
+ <button
98
+ type="button"
99
+ onClick={onToggleFind}
100
+ className={`p-1.5 rounded hover:bg-ink/10 transition-colors cursor-pointer ${findOpen ? 'bg-ink text-canvas' : ''}`}
101
+ title={findOpen ? 'Close find' : 'Find in file'}
102
+ aria-label={findOpen ? 'Close find' : 'Find in file'}
103
+ aria-pressed={findOpen}
104
+ >
105
+ <Search size={15} />
106
+ </button>
107
+ )}
108
+
90
109
  {hasPreview && (
91
110
  <button
92
111
  type="button"
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The phone editor's prop contract.
8
+ *
9
+ * Split out of `FullEditor.tsx` for the repository's per-file ceiling, and it belongs
10
+ * here for the same reason the desktop panel's does: the drawer and its tests name these,
11
+ * and a prop type imported from the component module couples them to the mount.
12
+ */
13
+
14
+ import type { MobileEditorFile } from '@/client/components/mobile/open-file-payload';
15
+
16
+ export interface MobileFullEditorProps {
17
+ file: MobileEditorFile;
18
+ onClose: () => void;
19
+ /** The file this editor names is gone from disk. */
20
+ missing?: boolean;
21
+ /** Fired after a debounced write lands, so the workspace panels can refresh. */
22
+ onFileSaved?: () => void;
23
+ /** The outcome of a file dropped on this editor, for the host's toast stack. */
24
+ onDropResult?: (result: { ok: boolean; message: string }) => void;
25
+ }
@@ -4,6 +4,8 @@ import { resolveThemeId } from '@/shared/lib/theme/catalog';
4
4
  import { ThemeGrid } from '@/client/components/settings/categories/appearance-settings/ThemeGrid';
5
5
  import { EditorFontSection } from '@/client/components/settings/categories/appearance-settings/EditorFontSection';
6
6
  import { EditorThemeSection } from '@/client/components/settings/categories/appearance-settings/EditorThemeSection';
7
+ import { EditorIndentSection } from '@/client/components/settings/categories/appearance-settings/EditorIndentSection';
8
+ import { EditorTypingSection } from '@/client/components/settings/categories/appearance-settings/EditorTypingSection';
7
9
 
8
10
  interface AppearanceSettingsProps {
9
11
  settings: SettingsState;
@@ -28,6 +30,10 @@ export function AppearanceSettings({ settings, onUpdate }: AppearanceSettingsPro
28
30
  <EditorFontSection settings={settings} onUpdate={onUpdate} />
29
31
 
30
32
  <EditorThemeSection settings={settings} onUpdate={onUpdate} />
33
+
34
+ <EditorIndentSection settings={settings} onUpdate={onUpdate} />
35
+
36
+ <EditorTypingSection settings={settings} onUpdate={onUpdate} />
31
37
  </div>
32
38
  );
33
39
  }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Settings → Appearance → Editor indentation.
8
+ *
9
+ * One control, because there is one decision: how wide a level is. "Insert spaces"
10
+ * is not a second preference — it is what the width MEANS, and offering them
11
+ * separately would let a user pick "4 columns, tabs", which is two answers to one
12
+ * question.
13
+ *
14
+ * A change has to reach an editor that is ALREADY open, which rules out reading
15
+ * `appSettings`: that is a boot-time prop the editor only sees again after a reload.
16
+ * The picker therefore broadcasts `EDITOR_INDENT_CHANGED_EVENT` and
17
+ * `useEditorIndent` subscribes — the same shape the font and theme pickers use. The
18
+ * event fires only when the value actually moved, or every unrelated settings
19
+ * toggle would reconfigure every editor's indent compartment.
20
+ */
21
+
22
+ import { readKabmoSetting, writeKabmoSettings } from '@/shared/lib/settings/client';
23
+ import type { SettingsState } from '@/shared/types';
24
+ import {
25
+ DEFAULT_EDITOR_INDENT,
26
+ EDITOR_INDENT_CHANGED_EVENT,
27
+ EDITOR_INDENT_WIDTHS,
28
+ currentEditorIndent,
29
+ type EditorIndentSettings,
30
+ } from '@/client/hooks/editor/indent-settings';
31
+
32
+ interface EditorIndentSectionProps {
33
+ settings: SettingsState;
34
+ /** Kept for the shared section signature; the value is read from the blob. */
35
+ onUpdate: (updater: Partial<SettingsState> | ((previous: SettingsState) => SettingsState)) => void;
36
+ }
37
+
38
+ export function EditorIndentSection({ settings: _settings, onUpdate }: EditorIndentSectionProps) {
39
+ // The stored width, with the same guard `currentEditorIndent` applies: a value
40
+ // outside the offered set (a downgrade, a hand-edited row) must not be shown as a
41
+ // selected option that does not exist.
42
+ const stored = readKabmoSetting<number>('editorIndentWidth');
43
+ const width = typeof stored === 'number' && EDITOR_INDENT_WIDTHS.includes(stored) ? stored : DEFAULT_EDITOR_INDENT.width;
44
+
45
+ const choose = (next: number) => {
46
+ if (next === width) return;
47
+ const value: EditorIndentSettings = { ...currentEditorIndent(), width: next };
48
+ writeKabmoSettings({ editorIndentWidth: next, editorInsertSpaces: true });
49
+ // The row is written through the blob above, which is what every reader resolves;
50
+ // this keeps the modal's own copy in step so the picker reflects the click
51
+ // without a reload.
52
+ onUpdate((previous) => ({ ...previous }));
53
+ // Live: an editor already on screen reconfigures its indent compartment.
54
+ window.dispatchEvent(new CustomEvent<EditorIndentSettings>(EDITOR_INDENT_CHANGED_EVENT, { detail: value }));
55
+ };
56
+
57
+ return (
58
+ <section className="space-y-3">
59
+ <div className="flex items-center justify-between gap-3">
60
+ <div>
61
+ <h4 className="text-xs font-semibold text-ink">Editor indentation</h4>
62
+ <p className="text-[11px] text-ink/50 mt-0.5">
63
+ One level, in spaces. Enter, Tab and the auto-indent rules all use it.
64
+ </p>
65
+ </div>
66
+ <div className="flex items-center gap-1" role="group" aria-label="Indentation width">
67
+ {EDITOR_INDENT_WIDTHS.map((option) => (
68
+ <button
69
+ key={option}
70
+ type="button"
71
+ onClick={() => choose(option)}
72
+ aria-pressed={option === width}
73
+ aria-label={`${option} spaces`}
74
+ className={`px-2.5 py-1 rounded border text-[11px] font-mono transition-colors cursor-pointer ${
75
+ option === width
76
+ ? 'border-ink/40 bg-ink/10 text-ink'
77
+ : 'border-ink/15 text-ink/60 hover:bg-ink/5 hover:text-ink'
78
+ }`}
79
+ >
80
+ {option}
81
+ </button>
82
+ ))}
83
+ </div>
84
+ </div>
85
+ </section>
86
+ );
87
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Settings → Appearance → Editor typing.
8
+ *
9
+ * Two switches, and both are BEHAVIOUR rather than view: they change what typing a
10
+ * character does. That is why they exist at all — a user who does not want an
11
+ * auto-inserted `}` has no way around one, unlike a colour they can ignore.
12
+ *
13
+ * A change reaches an editor that is already open through
14
+ * `EDITOR_TYPING_CHANGED_EVENT`, the same shape the font, theme and indent pickers use:
15
+ * `appSettings` is a boot-time prop, so a value read once would not reach the editor on
16
+ * screen. The event fires only when a value actually moved.
17
+ */
18
+
19
+ import { readKabmoSetting, writeKabmoSettings } from '@/shared/lib/settings/client';
20
+ import type { SettingsState } from '@/shared/types';
21
+ import {
22
+ DEFAULT_EDITOR_TYPING,
23
+ EDITOR_TYPING_CHANGED_EVENT,
24
+ currentEditorTyping,
25
+ } from '@/client/hooks/editor/typing-settings';
26
+
27
+ interface EditorTypingSectionProps {
28
+ settings: SettingsState;
29
+ onUpdate: (updater: Partial<SettingsState> | ((previous: SettingsState) => SettingsState)) => void;
30
+ }
31
+
32
+ /** One switch row. */
33
+ function Toggle({
34
+ label,
35
+ hint,
36
+ checked,
37
+ onChange,
38
+ }: {
39
+ label: string;
40
+ hint: string;
41
+ checked: boolean;
42
+ onChange: (next: boolean) => void;
43
+ }) {
44
+ return (
45
+ <label className="flex items-start justify-between gap-3 cursor-pointer">
46
+ <span className="min-w-0">
47
+ <span className="block text-xs text-ink">{label}</span>
48
+ <span className="block text-[11px] text-ink/50 mt-0.5">{hint}</span>
49
+ </span>
50
+ <input
51
+ type="checkbox"
52
+ checked={checked}
53
+ onChange={(event) => onChange(event.currentTarget.checked)}
54
+ aria-label={label}
55
+ className="mt-0.5 accent-ink flex-shrink-0"
56
+ />
57
+ </label>
58
+ );
59
+ }
60
+
61
+ export function EditorTypingSection({ settings: _settings, onUpdate }: EditorTypingSectionProps) {
62
+ // Read from the blob, which is what every reader resolves; the `onUpdate` below keeps
63
+ // the modal's own copy in step so the switches reflect a click without a reload.
64
+ const stored = currentEditorTyping();
65
+ const autoClose = readKabmoSetting<boolean>('editorAutoCloseBrackets');
66
+ const autocomplete = readKabmoSetting<boolean>('editorAutocomplete');
67
+
68
+ const commit = (patch: { editorAutoCloseBrackets?: boolean; editorAutocomplete?: boolean }) => {
69
+ const next = { ...currentEditorTyping(), ...patch };
70
+ writeKabmoSettings(patch);
71
+ onUpdate((previous) => ({ ...previous }));
72
+ window.dispatchEvent(new CustomEvent(EDITOR_TYPING_CHANGED_EVENT, { detail: next }));
73
+ };
74
+
75
+ return (
76
+ <section className="space-y-3">
77
+ <div>
78
+ <h4 className="text-xs font-semibold text-ink">Editor typing</h4>
79
+ <p className="text-[11px] text-ink/50 mt-0.5">
80
+ Both change what typing does, which is why they are switches rather than always-on.
81
+ </p>
82
+ </div>
83
+ <div className="space-y-2.5 rounded-lg border border-ink/10 p-3">
84
+ <Toggle
85
+ label="Auto-close brackets"
86
+ hint="Typing ( or { inserts the matching closer, and typing it again steps over it."
87
+ checked={typeof autoClose === 'boolean' ? autoClose : DEFAULT_EDITOR_TYPING.autoCloseBrackets}
88
+ onChange={(value) => commit({ editorAutoCloseBrackets: value })}
89
+ />
90
+ <Toggle
91
+ label="Suggest words from the file"
92
+ hint={`Offers identifiers already near the caret (${stored.autocomplete ? 'on' : 'off'}). Words only — this is not a language server.`}
93
+ checked={typeof autocomplete === 'boolean' ? autocomplete : DEFAULT_EDITOR_TYPING.autocomplete}
94
+ onChange={(value) => commit({ editorAutocomplete: value })}
95
+ />
96
+ </div>
97
+ </section>
98
+ );
99
+ }