@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
@@ -1,6 +1,11 @@
1
1
  import { useEffect, useRef, useState } from 'preact/hooks';
2
2
  import { FileIcon } from '@/client/components/common/file-icon';
3
3
  import { ChevronDown, GitCompare, X } from 'lucide-preact';
4
+ import { useDirtyTabs } from '@/client/lib/editor-dirty-tabs';
5
+ import { TabContextMenu } from '@/client/components/workspace/editor/TabContextMenu';
6
+ import { buildTabMenuRows, type TabMenuAction } from '@/client/lib/editor/tab-menu';
7
+ import { splitCandidate } from '@/shared/lib/workspace/split-editor';
8
+ import { PanelRight } from 'lucide-preact';
4
9
  import { useOnClickOutside } from '@/client/hooks/ui/on-click-outside';
5
10
  import { getGitStatusInfo } from '@/shared/lib/fs/git-status';
6
11
  import type { OpenedFile } from '@/shared/types/fs';
@@ -12,13 +17,50 @@ interface EditorTabsProps {
12
17
  onCloseFile: (id: number | string) => void;
13
18
  /** Tab ids whose file no longer exists on disk (see `useMissingFiles`). */
14
19
  missingIds?: ReadonlySet<number | string>;
20
+ /**
21
+ * The tab menu's non-close actions.
22
+ *
23
+ * Kept as callbacks rather than done here: copying a path and revealing a file both
24
+ * need the workspace scope, which the strip does not have.
25
+ */
26
+ onCopyPath?: (tab: OpenedFile) => void;
27
+ onRevealInFiles?: (tab: OpenedFile) => void;
28
+ /** Restore the most recently closed tab; returns false with an empty stack. */
29
+ onReopenClosed?: () => boolean;
30
+ /** How many tabs can still be reopened, so the menu row can be absent when none can. */
31
+ reopenableCount?: () => number;
32
+ /** Split the column to this tab, or change which tab the right pane shows. */
33
+ onSplitTo?: (id: number | string) => void;
34
+ /** Collapse the split. The tabs stay open — a split is a view. */
35
+ onUnsplit?: () => void;
36
+ /** The tab the right pane shows, so `Split right` can be absent for it. */
37
+ splitRightFileId?: number | string | null;
15
38
  }
16
39
 
17
- export function EditorTabs({ openedFiles, activeFileId, onSelectFile, onCloseFile, missingIds }: EditorTabsProps) {
40
+ export function EditorTabs({
41
+ openedFiles,
42
+ activeFileId,
43
+ onSelectFile,
44
+ onCloseFile,
45
+ missingIds,
46
+ onCopyPath,
47
+ onRevealInFiles,
48
+ onReopenClosed,
49
+ reopenableCount,
50
+ onSplitTo,
51
+ onUnsplit,
52
+ splitRightFileId = null,
53
+ }: EditorTabsProps) {
54
+ // Which tabs hold edits that are not on disk. The dot replaces the close `×`
55
+ // while the tab is dirty — the VS Code convention, and the reason it costs no
56
+ // extra column: a second mark beside the × would narrow the name on every tab.
57
+ const dirtyIds = useDirtyTabs();
18
58
  const tabsContainerRef = useRef<HTMLDivElement>(null);
19
59
  const dropdownRef = useRef<HTMLDivElement>(null);
20
60
  const [maxVisibleTabs, setMaxVisibleTabs] = useState(5);
21
61
  const [showDropdown, setShowDropdown] = useState(false);
62
+ /** The tab the context menu was opened on, with its viewport position. */
63
+ const [menu, setMenu] = useState<{ tab: OpenedFile; x: number; y: number } | null>(null);
22
64
 
23
65
  useOnClickOutside(dropdownRef, () => setShowDropdown(false));
24
66
 
@@ -37,6 +79,8 @@ export function EditorTabs({ openedFiles, activeFileId, onSelectFile, onCloseFil
37
79
  return () => observer.disconnect();
38
80
  }, []);
39
81
 
82
+ const candidate = splitCandidate(activeFileId, openedFiles.map((file) => file.id));
83
+
40
84
  let visibleTabs: OpenedFile[] = [];
41
85
  let hiddenTabs: OpenedFile[] = [];
42
86
 
@@ -72,6 +116,10 @@ export function EditorTabs({ openedFiles, activeFileId, onSelectFile, onCloseFil
72
116
  <div
73
117
  key={file.id}
74
118
  onClick={() => onSelectFile(file.id)}
119
+ onContextMenu={(event) => {
120
+ event.preventDefault();
121
+ setMenu({ tab: file, x: event.clientX, y: event.clientY });
122
+ }}
75
123
  className={`flex items-center space-x-1.5 px-3 py-1.5 cursor-pointer border-r border-ink/10 min-w-[120px] max-w-[210px] group ${
76
124
  isActive ? 'bg-paper border-t-2 border-t-ink text-ink' : 'bg-transparent border-t-2 border-t-transparent text-ink/60 hover:bg-paper/50'
77
125
  }`}
@@ -91,22 +139,102 @@ export function EditorTabs({ openedFiles, activeFileId, onSelectFile, onCloseFil
91
139
  {statusInfo.charStatus}
92
140
  </span>
93
141
  )}
94
- <div
95
- className={`p-0.5 rounded hover:bg-ink/10 touch-visible ${isActive ? 'opacity-100' : 'opacity-0 group-hover:opacity-100'}`}
96
- onClick={(e) => {
97
- e.stopPropagation();
98
- onCloseFile(file.id);
99
- }}
100
- >
101
- <X size={12} />
102
- </div>
142
+ <TabCloseButton
143
+ dirty={dirtyIds.has(file.id)}
144
+ active={isActive}
145
+ label={`Close ${file.name}`}
146
+ onClose={() => onCloseFile(file.id)}
147
+ />
103
148
  </div>
104
149
  );
105
150
  })}
106
151
  </div>
107
152
 
153
+ {menu ? (
154
+ <TabContextMenu
155
+ x={menu.x}
156
+ y={menu.y}
157
+ rows={buildTabMenuRows({
158
+ tab: menu.tab,
159
+ openedFiles,
160
+ dirtyIds,
161
+ reopenable: reopenableCount?.() ?? 0,
162
+ activeFileId,
163
+ splitRightFileId,
164
+ })}
165
+ onAction={(action: TabMenuAction) => {
166
+ const tab = menu.tab;
167
+ switch (action) {
168
+ case 'close':
169
+ onCloseFile(tab.id);
170
+ return;
171
+ case 'close-others':
172
+ // Newest-first so the ACTIVE tab survives as the last one standing:
173
+ // closing others one by one leaves whichever id is not closed, and
174
+ // `onCloseFile` re-targets the active tab on every call.
175
+ for (const file of [...openedFiles].reverse()) {
176
+ if (file.id !== tab.id) onCloseFile(file.id);
177
+ }
178
+ onSelectFile(tab.id);
179
+ return;
180
+ case 'close-all':
181
+ for (const file of [...openedFiles].reverse()) onCloseFile(file.id);
182
+ return;
183
+ case 'close-saved':
184
+ // The dirty ones stay — the only reading that cannot lose an edit.
185
+ for (const file of [...openedFiles].reverse()) {
186
+ if (!dirtyIds.has(file.id)) onCloseFile(file.id);
187
+ }
188
+ return;
189
+ case 'copy-path':
190
+ onCopyPath?.(tab);
191
+ return;
192
+ case 'reveal-in-files':
193
+ onRevealInFiles?.(tab);
194
+ return;
195
+ case 'reopen-closed':
196
+ onReopenClosed?.();
197
+ return;
198
+ case 'split-right':
199
+ onSplitTo?.(tab.id);
200
+ return;
201
+ case 'unsplit':
202
+ onUnsplit?.();
203
+ return;
204
+ }
205
+ }}
206
+ onClose={() => setMenu(null)}
207
+ />
208
+ ) : null}
209
+
210
+ {/* The split control. It is NOT inside the overflow conditional: the strip folds every
211
+ non-active tab at panel width, so a split reachable only by right-clicking ANOTHER
212
+ tab would be unreachable exactly when the panel is narrow. It splits to the newest
213
+ other tab, which is the one the user just opened. */}
214
+ <div className="ml-auto flex items-center">
215
+ <button
216
+ type="button"
217
+ onClick={() => (splitRightFileId !== null ? onUnsplit?.() : onSplitTo?.(candidate as number | string))}
218
+ disabled={splitRightFileId === null && candidate === null}
219
+ aria-pressed={splitRightFileId !== null}
220
+ aria-label="Split editor"
221
+ title={
222
+ splitRightFileId !== null
223
+ ? 'Close the split pane (the tab stays open)'
224
+ : candidate === null
225
+ ? 'Open another file to split the editor'
226
+ : 'Split the editor and show the newest other file'
227
+ }
228
+ className={`p-1.5 mx-1 rounded transition-colors cursor-pointer disabled:opacity-30 disabled:cursor-default ${
229
+ splitRightFileId !== null ? 'bg-ink/10 text-ink' : 'text-ink/60 hover:bg-ink/10'
230
+ }`}
231
+ >
232
+ <PanelRight size={14} />
233
+ </button>
234
+ </div>
235
+
108
236
  {hiddenTabs.length > 0 && (
109
- <div className="relative flex items-center ml-auto bg-ink/10" ref={dropdownRef}>
237
+ <div className="relative flex items-center bg-ink/10" ref={dropdownRef}>
110
238
  <button
111
239
  className={`p-1.5 mx-1 rounded hover:bg-ink/10 text-ink/60 ${showDropdown ? 'bg-ink/10 text-ink' : ''}`}
112
240
  onClick={() => setShowDropdown(!showDropdown)}
@@ -137,16 +265,15 @@ export function EditorTabs({ openedFiles, activeFileId, onSelectFile, onCloseFil
137
265
  <FileIcon name={file.name} size={14} className={isMissing ? 'text-error' : 'opacity-60'} />
138
266
  )}
139
267
  <span className={`text-xs font-mono truncate flex-1 ${isMissing ? 'text-error line-through' : 'text-ink/80'}`}>{file.name}</span>
140
- <div
141
- className="touch-visible p-0.5 rounded hover:bg-ink/10 opacity-0 group-hover:opacity-100"
142
- onClick={(e) => {
143
- e.stopPropagation();
268
+ <TabCloseButton
269
+ dirty={dirtyIds.has(file.id)}
270
+ active={false}
271
+ label={`Close ${file.name}`}
272
+ onClose={() => {
144
273
  onCloseFile(file.id);
145
274
  if (hiddenTabs.length === 1) setShowDropdown(false);
146
275
  }}
147
- >
148
- <X size={12} className="text-ink/60" />
149
- </div>
276
+ />
150
277
  </div>
151
278
  );
152
279
  })}
@@ -157,3 +284,53 @@ export function EditorTabs({ openedFiles, activeFileId, onSelectFile, onCloseFil
157
284
  </div>
158
285
  );
159
286
  }
287
+
288
+ /**
289
+ * A tab's trailing control: a dot while the tab is dirty, the `×` otherwise.
290
+ *
291
+ * One control, two meanings, because a dirty tab's primary action is still
292
+ * "close" — the dot says what closing would cost, and the pointer reveals the
293
+ * affordance. Two controls side by side would narrow the file name on every tab
294
+ * for a mark most tabs never show.
295
+ *
296
+ * The dot is a `<span>`, not an icon: it is drawn with `rounded-full bg-current`
297
+ * so it inherits the tab's own ink (active vs inactive) with no second colour.
298
+ */
299
+ function TabCloseButton({
300
+ dirty,
301
+ active,
302
+ label,
303
+ onClose,
304
+ }: {
305
+ dirty: boolean;
306
+ active: boolean;
307
+ label: string;
308
+ onClose: () => void;
309
+ }) {
310
+ return (
311
+ <div
312
+ role="button"
313
+ tabIndex={-1}
314
+ aria-label={label}
315
+ title={dirty ? `${label} — unsaved changes` : label}
316
+ className={`p-0.5 rounded hover:bg-ink/10 touch-visible ${active || dirty ? 'opacity-100' : 'opacity-0 group-hover:opacity-100'}`}
317
+ onClick={(event) => {
318
+ // The row itself selects the tab; a close must not also open it.
319
+ event.stopPropagation();
320
+ onClose();
321
+ }}
322
+ >
323
+ {dirty ? (
324
+ <span
325
+ className="block w-2 h-2 rounded-full bg-current mx-0.5"
326
+ data-tab-dirty=""
327
+ // The dot is decoration over a control that already names the state in
328
+ // its title and aria-label.
329
+ aria-hidden="true"
330
+ />
331
+ ) : (
332
+ <X size={12} />
333
+ )}
334
+ </div>
335
+ );
336
+ }
@@ -1,20 +1,13 @@
1
1
  import {
2
2
  AlertCircle,
3
3
  Check,
4
- Copy,
5
- Download,
6
- Eye,
7
- EyeOff,
8
4
  Maximize,
9
5
  Minimize,
10
6
  Save,
11
- Search,
12
- WrapText,
13
- ZoomIn,
14
- ZoomOut,
15
7
  } from 'lucide-preact';
16
8
  import { EditorViewButtons, useEditorViewActions } from '@/client/components/common/editor-view-buttons';
17
- import { ToolbarRow, type ToolbarCluster } from '@/client/components/common/toolbar-row';
9
+ import { ToolbarRow } from '@/client/components/common/toolbar-row';
10
+ import { ACTION_CLASS, buildEditorClusters } from '@/client/components/workspace/editor/toolbar-clusters';
18
11
 
19
12
  export type EditorSaveStatus = 'idle' | 'saving' | 'saved' | 'error' | 'needs-permission';
20
13
 
@@ -60,18 +53,30 @@ interface EditorToolbarProps {
60
53
  onZoomOut: () => void;
61
54
  onCopy: () => void;
62
55
  onDownload: () => void;
56
+ /**
57
+ * Throw the buffer away and take the file from disk.
58
+ *
59
+ * Destructive, so it is never pinned and never in the row: a mis-click on a
60
+ * toolbar of icon-only buttons must not be able to lose an edit.
61
+ */
62
+ onRevert: () => void;
63
+ /** Enabled only for a buffer with edits — reverting a clean one does nothing. */
64
+ canRevert: boolean;
65
+ /** Write the buffer to a NEW path; the original tab stays open. */
66
+ onSaveAs: () => void;
63
67
  onToggleMaximize: () => void;
64
68
  }
65
69
 
66
70
  /**
67
- * Shared icon-button shell. Every action here is icon-only, so each one carries
68
- * a `title` (the tooltip) and an `aria-label` (the accessible name) — a bare
69
- * `<svg onClick>` is unreachable by keyboard and unlabeled to a screen reader.
70
- * `p-1.5` also gives the 14px glyph a ~26px hit target.
71
+ * The editor's toolbar: one row of clusters, with the overflow rule in
72
+ * `toolbar-clusters.tsx`.
73
+ *
74
+ * This component owns the STATUS each control draws (the save icon's four faces,
75
+ * the copy confirmation) and the labels they carry; the cluster table owns what
76
+ * exists, in which order, and what a narrow panel must not bury. Splitting it
77
+ * there is what keeps this file under the repository's line ceiling as controls
78
+ * are added.
71
79
  */
72
- const ACTION_CLASS =
73
- 'flex items-center justify-center p-1.5 rounded transition-colors cursor-pointer disabled:cursor-default disabled:opacity-50';
74
-
75
80
  export function EditorToolbar({
76
81
  path,
77
82
  saveStatus,
@@ -93,6 +98,9 @@ export function EditorToolbar({
93
98
  onZoomOut,
94
99
  onCopy,
95
100
  onDownload,
101
+ onRevert,
102
+ canRevert,
103
+ onSaveAs,
96
104
  onToggleMaximize,
97
105
  }: EditorToolbarProps) {
98
106
  const saveTitle =
@@ -134,31 +142,6 @@ export function EditorToolbar({
134
142
  </button>
135
143
  );
136
144
 
137
- const copyLabel = copied ? 'Copied' : byteViewer ? 'Copy image' : 'Copy content';
138
- const copyButton = (
139
- <button
140
- type="button"
141
- onClick={onCopy}
142
- className={`${ACTION_CLASS} hover:bg-ink/5 hover:text-ink`}
143
- title={copyLabel}
144
- aria-label={copyLabel}
145
- >
146
- {copied ? <Check size={14} className="text-success" /> : <Copy size={14} />}
147
- </button>
148
- );
149
-
150
- const downloadButton = (
151
- <button
152
- type="button"
153
- onClick={onDownload}
154
- className={`${ACTION_CLASS} hover:bg-ink/5 hover:text-ink`}
155
- title="Download file"
156
- aria-label="Download file"
157
- >
158
- <Download size={14} />
159
- </button>
160
- );
161
-
162
145
  const maximizeLabel = isMaximized ? 'Exit full screen' : 'Full screen';
163
146
  const maximizeButton = (
164
147
  <button
@@ -174,146 +157,36 @@ export function EditorToolbar({
174
157
  );
175
158
 
176
159
  const viewModeActions = useEditorViewActions();
177
- const findLabel = 'Find and replace';
178
- const wordWrapLabel = wordWrap ? 'Word wrap on' : 'Word wrap off';
179
- const previewLabel = isPreview ? 'Show source' : 'Show preview';
180
-
181
- /**
182
- * The controls, as clusters that hide as a unit.
183
- *
184
- * ORDER is the hiding order, most important first: the row keeps the width
185
- * modes and full screen (the controls this panel is FOR), then copy/download,
186
- * and the reading aids (find, wrap, zoom, preview) move into the `⋯` menu on a
187
- * narrow panel. Grouping is the existing one — zoom is a pair, copy/download is
188
- * a pair, the modes are a pair — because splitting a pair leaves half of it on
189
- * the row.
190
- */
191
- const clusters: ToolbarCluster[] = [];
192
-
193
- if (!byteViewer) {
194
- clusters.push({
195
- id: 'save',
196
- // The primary action of the panel: a menu row must never be the only way
197
- // to save a file.
198
- pinned: true,
199
- actions: [{ label: 'Save file', icon: Save, onSelect: onSave, disabled: saveDisabled }],
200
- children: saveButton,
201
- });
202
- }
203
- if (hasPreview) {
204
- clusters.push({
205
- id: 'preview',
206
- actions: [{ label: previewLabel, icon: isPreview ? EyeOff : Eye, onSelect: onTogglePreview, active: isPreview }],
207
- children: (
208
- <button
209
- type="button"
210
- onClick={onTogglePreview}
211
- className={`${ACTION_CLASS} hover:bg-ink/5 ${isPreview ? 'text-ink' : 'hover:text-ink'}`}
212
- title={previewLabel}
213
- aria-label={previewLabel}
214
- aria-pressed={isPreview}
215
- >
216
- {isPreview ? <EyeOff size={14} /> : <Eye size={14} />}
217
- </button>
218
- ),
219
- });
220
- }
221
- if (!byteViewer) {
222
- clusters.push({
223
- id: 'find',
224
- actions: [{ label: findLabel, icon: Search, onSelect: onToggleFind, active: findOpen }],
225
- children: (
226
- <button
227
- type="button"
228
- onClick={onToggleFind}
229
- className={`${ACTION_CLASS} hover:bg-ink/5 ${findOpen ? 'text-ink' : 'hover:text-ink'}`}
230
- title={`${findLabel} (Ctrl+F)`}
231
- aria-label={findLabel}
232
- aria-pressed={findOpen}
233
- >
234
- <Search size={14} />
235
- </button>
236
- ),
237
- });
238
- clusters.push({
239
- id: 'wrap',
240
- actions: [{ label: wordWrapLabel, icon: WrapText, onSelect: onToggleWordWrap, active: wordWrap }],
241
- children: (
242
- <button
243
- type="button"
244
- onClick={onToggleWordWrap}
245
- className={`${ACTION_CLASS} hover:bg-ink/5 ${wordWrap ? 'text-ink' : 'hover:text-ink'}`}
246
- title={wordWrapLabel}
247
- aria-label={wordWrapLabel}
248
- aria-pressed={wordWrap}
249
- >
250
- <WrapText size={14} />
251
- </button>
252
- ),
253
- });
254
- clusters.push({
255
- id: 'zoom',
256
- actions: [
257
- { label: 'Decrease font size', icon: ZoomOut, onSelect: onZoomOut },
258
- { label: 'Increase font size', icon: ZoomIn, onSelect: onZoomIn },
259
- ],
260
- children: (
261
- <>
262
- <button
263
- type="button"
264
- onClick={onZoomOut}
265
- className={`${ACTION_CLASS} hover:bg-ink/5 hover:text-ink`}
266
- title="Decrease font size"
267
- aria-label="Decrease font size"
268
- >
269
- <ZoomOut size={14} />
270
- </button>
271
- <button
272
- type="button"
273
- onClick={onZoomIn}
274
- className={`${ACTION_CLASS} hover:bg-ink/5 hover:text-ink`}
275
- title="Increase font size"
276
- aria-label="Increase font size"
277
- >
278
- <ZoomIn size={14} />
279
- </button>
280
- </>
281
- ),
282
- });
283
- }
284
-
285
- clusters.push({
286
- id: 'copy',
287
- actions: [
288
- { label: copyLabel, icon: Copy, onSelect: onCopy },
289
- { label: 'Download file', icon: Download, onSelect: onDownload },
290
- ],
291
- children: (
292
- <>
293
- {copyButton}
294
- {downloadButton}
295
- </>
296
- ),
297
- });
298
-
299
- // The width modes and full SCREEN are the controls this panel exists for, so
300
- // they are the LAST clusters — the tail is what the menu takes. Three controls
301
- // about one axis, three different glyphs: compact collapses the chat (a
302
- // crossed-out message), full collapses the chat and the sidebar (a closing
303
- // panel edge), and full screen covers the right panel too (a maximise frame).
304
- clusters.push({
305
- id: 'view-modes',
306
- // The two width modes are why this toolbar grew these buttons, and a mode
307
- // reachable only from a menu is a mode half the readers never find.
308
- pinned: true,
309
- actions: viewModeActions,
310
- children: <EditorViewButtons size={14} />,
311
- });
312
- clusters.push({
313
- id: 'maximize',
314
- pinned: true,
315
- actions: [{ label: maximizeLabel, icon: isMaximized ? Minimize : Maximize, onSelect: onToggleMaximize, active: isMaximized }],
316
- children: maximizeButton,
160
+ const clusters = buildEditorClusters({
161
+ byteViewer,
162
+ hasPreview,
163
+ isPreview,
164
+ wordWrap,
165
+ findOpen,
166
+ copied,
167
+ isMaximized,
168
+ saveDisabled,
169
+ canRevert,
170
+ saveButton,
171
+ maximizeButton,
172
+ viewModeButtons: <EditorViewButtons size={14} />,
173
+ viewModeActions,
174
+ previewLabel: isPreview ? 'Show source' : 'Show preview',
175
+ findLabel: 'Find and replace',
176
+ wordWrapLabel: wordWrap ? 'Word wrap on' : 'Word wrap off',
177
+ copyLabel: copied ? 'Copied' : byteViewer ? 'Copy image' : 'Copy content',
178
+ maximizeLabel,
179
+ onTogglePreview,
180
+ onToggleFind,
181
+ onToggleWordWrap,
182
+ onZoomIn,
183
+ onZoomOut,
184
+ onCopy,
185
+ onDownload,
186
+ onRevert,
187
+ onSaveAs,
188
+ onToggleMaximize,
189
+ onSave,
317
190
  });
318
191
 
319
192
  return (