dsh-remote-vs 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +49 -15
- package/README.md +40 -14
- package/lib/client.js +45978 -43338
- package/lib/index.js +388 -90
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/client/CodeEditor.d.ts +17 -0
- package/lib/types/client/EditorPane.d.ts +16 -5
- package/lib/types/client/FloatingPlaceholder.d.ts +16 -5
- package/lib/types/client/RemoteEditorView.d.ts +13 -10
- package/lib/types/client/RemoteRoot.d.ts +5 -5
- package/lib/types/client/SettingsHosts.d.ts +3 -0
- package/lib/types/client/TerminalSnippets.d.ts +36 -0
- package/lib/types/client/TerminalView.d.ts +1 -1
- package/lib/types/client/XTerm.d.ts +33 -0
- package/lib/types/client/api.d.ts +4 -1
- package/lib/types/client/auto-open-remote.d.ts +41 -0
- package/lib/types/client/editor-capability.d.ts +27 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/store.d.ts +59 -4
- package/lib/types/client/terminal-input.d.ts +23 -0
- package/lib/types/client/terminal-snippets.d.ts +86 -0
- package/lib/types/client/use-remote-chat-target.d.ts +2 -0
- package/lib/types/client/view-settings.d.ts +40 -0
- package/lib/types/client/vsc/breadcrumb.d.ts +30 -0
- package/lib/types/client/vsc/editor-caret.d.ts +32 -0
- package/lib/types/client/vsc/editor-langs.d.ts +9 -0
- package/lib/types/client/vsc/editor-settings.d.ts +55 -0
- package/lib/types/client/vsc/image-preview.d.ts +36 -0
- package/lib/types/client/vsc/kit.d.ts +2 -0
- package/lib/types/client/vsc/terminal-clipboard.d.ts +15 -0
- package/lib/types/client/vsc/terminal-line.d.ts +25 -0
- package/lib/types/client/vsc/terminal-links.d.ts +62 -0
- package/lib/types/client/vsc/terminal-theme.d.ts +22 -0
- package/lib/types/client/vsc/terminal-writer.d.ts +52 -0
- package/lib/types/paths.d.ts +9 -0
- package/lib/types/pool.d.ts +25 -0
- package/lib/types/protocol.d.ts +35 -0
- package/lib/types/routes.d.ts +7 -0
- package/lib/types/terminal.d.ts +25 -1
- package/lib/types/view-settings.d.ts +26 -0
- package/lib/{worlds-DXdP4SMn.js → worlds-B7gEDBzC.js} +13 -1
- package/package.json +36 -36
- package/src/client/CodeEditor.tsx +54 -2
- package/src/client/EditorPane.tsx +485 -107
- package/src/client/FloatingPlaceholder.tsx +34 -5
- package/src/client/RemoteEditorView.tsx +14 -11
- package/src/client/RemoteRoot.tsx +20 -125
- package/src/client/SettingsHosts.tsx +81 -3
- package/src/client/TerminalSnippets.tsx +357 -0
- package/src/client/TerminalView.tsx +50 -1
- package/src/client/XTerm.tsx +228 -58
- package/src/client/api.ts +7 -0
- package/src/client/auto-open-remote.ts +439 -0
- package/src/client/editor-capability.ts +42 -0
- package/src/client/i18n.ts +158 -6
- package/src/client/index.tsx +30 -6
- package/src/client/store.tsx +165 -13
- package/src/client/terminal-input.ts +44 -0
- package/src/client/terminal-snippets.ts +216 -0
- package/src/client/use-remote-chat-target.ts +1 -1
- package/src/client/view-settings.ts +99 -0
- package/src/client/vsc/breadcrumb.tsx +251 -0
- package/src/client/vsc/editor-caret.ts +30 -0
- package/src/client/vsc/editor-langs.ts +20 -0
- package/src/client/vsc/editor-settings.ts +146 -0
- package/src/client/vsc/editor-theme.ts +4 -5
- package/src/client/vsc/image-preview.tsx +110 -0
- package/src/client/vsc/kit.tsx +20 -1
- package/src/client/vsc/terminal-clipboard.ts +19 -0
- package/src/client/vsc/terminal-line.ts +101 -0
- package/src/client/vsc/terminal-links.ts +166 -0
- package/src/client/vsc/terminal-theme.ts +71 -0
- package/src/client/vsc/terminal-writer.ts +112 -0
- package/src/client/vsc/vsc.css +687 -48
- package/src/index.ts +6 -0
- package/src/paths.ts +13 -0
- package/src/pool.ts +99 -27
- package/src/protocol.ts +45 -0
- package/src/routes.ts +47 -0
- package/src/terminal.ts +160 -6
- package/src/view-settings.ts +133 -0
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The editor area: one tab strip for code files, previews and diffs, an info
|
|
3
|
-
* row, and the
|
|
3
|
+
* row, the body, and (in the full-width conversation-view variant) a status bar.
|
|
4
4
|
*
|
|
5
|
-
* The
|
|
6
|
-
*
|
|
7
|
-
* every
|
|
8
|
-
*
|
|
5
|
+
* The chrome follows the local sidebar plugin's editor (same tab strip, info
|
|
6
|
+
* row, empty states, status bar, image preview and editor background tokens),
|
|
7
|
+
* while every remote-only capability stays exactly where it was: the remote
|
|
8
|
+
* read/write routes, the save-conflict banner and its on-demand difference, the
|
|
9
|
+
* diff tabs, markdown/HTML previews, session change marks and the offline
|
|
10
|
+
* read-only degradation.
|
|
11
|
+
*
|
|
12
|
+
* Three variants share this component, chosen from the store's effective
|
|
13
|
+
* surface — never from a prop, so a surface can never mount two live buffers:
|
|
14
|
+
* - `sidebar`: the docked pane — a FULL-COLUMN rail page and the default seat
|
|
15
|
+
* (opening a file switches the rail to it; closing the last file switches
|
|
16
|
+
* back to the directory);
|
|
17
|
+
* - `center`: the conversation-view tab next to 对话 / 轨迹 (optional, full
|
|
18
|
+
* width, breadcrumb + status bar);
|
|
19
|
+
* - `float`: the frame-wide floating window (its own font zoom applies).
|
|
9
20
|
*/
|
|
10
|
-
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
|
21
|
+
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore, type CSSProperties, type ReactNode } from 'react'
|
|
11
22
|
import { api, fileReadTimeoutMs } from './api.ts'
|
|
12
23
|
import { clientDeadlineFor } from '../timeouts.ts'
|
|
13
24
|
import { diffText, type TextHunk } from '../changes/text-diff.ts'
|
|
14
|
-
import { CodeEditor, type CodeEditorHandle, type CodeEditorViewState } from './CodeEditor.tsx'
|
|
25
|
+
import { CodeEditor, type CodeEditorCaret, type CodeEditorHandle, type CodeEditorViewState } from './CodeEditor.tsx'
|
|
15
26
|
import { ConnectionStatusChip } from './ConnectionStatus.tsx'
|
|
16
27
|
import { isConnectionFailure, useConnectionStatus } from './connection.ts'
|
|
17
28
|
import { sameLocalDir } from './composer.ts'
|
|
@@ -23,12 +34,27 @@ import { Btn } from './ui.tsx'
|
|
|
23
34
|
import { renderMarkdown } from './vsc/markdown.tsx'
|
|
24
35
|
import { langLabel, langFromPath } from './vsc/tokenize.ts'
|
|
25
36
|
import { installSaveShortcut } from './vsc/save-shortcut.ts'
|
|
37
|
+
import { Breadcrumb } from './vsc/breadcrumb.tsx'
|
|
38
|
+
import { ImagePreview } from './vsc/image-preview.tsx'
|
|
39
|
+
import {
|
|
40
|
+
editorSettingsSnapshot,
|
|
41
|
+
stepFontSize,
|
|
42
|
+
subscribeEditorSettings,
|
|
43
|
+
updateEditorSettings,
|
|
44
|
+
type EditorSettings,
|
|
45
|
+
} from './vsc/editor-settings.ts'
|
|
46
|
+
import { detectIndentLabel } from './vsc/editor-langs.ts'
|
|
26
47
|
import {
|
|
27
48
|
IconButton,
|
|
28
49
|
IconClose,
|
|
50
|
+
IconCode,
|
|
51
|
+
IconCollapse,
|
|
29
52
|
IconDiff,
|
|
53
|
+
IconExpand,
|
|
54
|
+
IconFloat,
|
|
30
55
|
IconRefresh,
|
|
31
56
|
IconSave,
|
|
57
|
+
IconWrap,
|
|
32
58
|
MiniSpinner,
|
|
33
59
|
Segmented,
|
|
34
60
|
baseName,
|
|
@@ -112,7 +138,7 @@ function undoActionLabel(t: (key: string) => string, kind: 'add' | 'mod' | 'del'
|
|
|
112
138
|
|
|
113
139
|
/** Tab icon: diffs, images and text files each get their own glyph. */
|
|
114
140
|
function tabIcon(tab: { kind: string; image: boolean }): ReactNode {
|
|
115
|
-
if (tab.kind === 'diff') return <IconDiff size={
|
|
141
|
+
if (tab.kind === 'diff') return <IconDiff size={11} />
|
|
116
142
|
if (tab.image) return <span>▣</span>
|
|
117
143
|
return <span>▪</span>
|
|
118
144
|
}
|
|
@@ -172,9 +198,143 @@ function dropOversized(prev: Record<string, string>, keep: string | undefined):
|
|
|
172
198
|
return next
|
|
173
199
|
}
|
|
174
200
|
|
|
201
|
+
/**
|
|
202
|
+
* Cache key of one image PREVIEW: the path PLUS the tab's reload nonce.
|
|
203
|
+
*
|
|
204
|
+
* The base64 payload is a snapshot of one read. Keying by path alone kept
|
|
205
|
+
* painting the old bytes after a reload (and after a reconnect's background
|
|
206
|
+
* re-read of an inactive tab, which has no cache-clearing effect running); the
|
|
207
|
+
* nonce changes with every successful re-read, so a stale entry is simply never
|
|
208
|
+
* looked up again and ages out of the bounded cache.
|
|
209
|
+
*/
|
|
210
|
+
function imageCacheKey(tab: { fullPath: string; reloadNonce?: number }): string {
|
|
211
|
+
return `${tab.fullPath}@${tab.reloadNonce ?? 0}`
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Which chrome variant this mount renders (see the file header). */
|
|
215
|
+
type EditorVariant = 'sidebar' | 'center' | 'float'
|
|
216
|
+
|
|
217
|
+
/** React binding for the shared editor view preferences. */
|
|
218
|
+
function useEditorSettings(): EditorSettings {
|
|
219
|
+
return useSyncExternalStore(subscribeEditorSettings, editorSettingsSnapshot, editorSettingsSnapshot)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** One status-bar entry. */
|
|
223
|
+
function StatusItem(props: { title?: string; error?: boolean; children: ReactNode; onClick?: () => void }): ReactNode {
|
|
224
|
+
const className = `rvs-status-item${props.error === true ? ' rvs-status-error' : ''}`
|
|
225
|
+
if (props.onClick === undefined) {
|
|
226
|
+
return <span className={className} title={props.title}>{props.children}</span>
|
|
227
|
+
}
|
|
228
|
+
return (
|
|
229
|
+
<button type="button" className={`${className} rvs-status-btn`} title={props.title} onClick={props.onClick}>
|
|
230
|
+
{props.children}
|
|
231
|
+
</button>
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Bottom status bar (full-width variant only, like the sidebar plugin).
|
|
237
|
+
*
|
|
238
|
+
* Left is "where am I" (language, line:column, selection size, indent); right is
|
|
239
|
+
* "how is it shown" (wrap, font size, save state) plus the file encoding. Wrap
|
|
240
|
+
* and font size are CLICKABLE on purpose: those are the two display switches a
|
|
241
|
+
* reader changes often, and making them hunt through a menu would be worse.
|
|
242
|
+
*/
|
|
243
|
+
function StatusBar(props: {
|
|
244
|
+
t: (key: string) => string
|
|
245
|
+
diff: boolean
|
|
246
|
+
caret: CodeEditorCaret | undefined
|
|
247
|
+
language: string
|
|
248
|
+
indent: string | undefined
|
|
249
|
+
wrap: boolean
|
|
250
|
+
fontSize: number
|
|
251
|
+
readOnly: boolean
|
|
252
|
+
dirty: boolean
|
|
253
|
+
loading: boolean
|
|
254
|
+
saving: boolean
|
|
255
|
+
error: string | undefined
|
|
256
|
+
}): ReactNode {
|
|
257
|
+
const caret = props.caret
|
|
258
|
+
const t = props.t
|
|
259
|
+
const saveLabel = props.loading
|
|
260
|
+
? t('common.loading')
|
|
261
|
+
: props.saving
|
|
262
|
+
? t('editor.statusSaving')
|
|
263
|
+
: props.dirty
|
|
264
|
+
? t('editor.unsaved')
|
|
265
|
+
: t('editor.statusClean')
|
|
266
|
+
return (
|
|
267
|
+
<div className="rvs-statusbar">
|
|
268
|
+
<div className="rvs-status-left">
|
|
269
|
+
{props.diff ? (
|
|
270
|
+
<>
|
|
271
|
+
<StatusItem title={t('editor.diffTitle')}>{t('editor.diffTitle')}</StatusItem>
|
|
272
|
+
<StatusItem title={t('editor.diffReadOnlyTitle')}>{t('editor.statusReadOnly')}</StatusItem>
|
|
273
|
+
</>
|
|
274
|
+
) : (
|
|
275
|
+
<>
|
|
276
|
+
<StatusItem title={t('editor.statusLanguage')}>{props.language}</StatusItem>
|
|
277
|
+
<StatusItem title={t('editor.statusPosition')}>
|
|
278
|
+
{t('editor.statusPositionValue')
|
|
279
|
+
.replace('{line}', String(caret?.line ?? 1))
|
|
280
|
+
.replace('{column}', String(caret?.column ?? 1))}
|
|
281
|
+
</StatusItem>
|
|
282
|
+
{caret !== undefined && caret.selected > 0 && (
|
|
283
|
+
<StatusItem title={t('editor.statusSelected')}>
|
|
284
|
+
{t('editor.statusSelectedValue').replace('{count}', String(caret.selected))}
|
|
285
|
+
</StatusItem>
|
|
286
|
+
)}
|
|
287
|
+
{props.indent !== undefined && <StatusItem title={t('editor.statusIndent')}>{props.indent}</StatusItem>}
|
|
288
|
+
</>
|
|
289
|
+
)}
|
|
290
|
+
</div>
|
|
291
|
+
<div className="rvs-status-right">
|
|
292
|
+
{props.error !== undefined && (
|
|
293
|
+
<StatusItem title={props.error} error>
|
|
294
|
+
{t('editor.statusError')}
|
|
295
|
+
</StatusItem>
|
|
296
|
+
)}
|
|
297
|
+
{props.diff ? null : (
|
|
298
|
+
<>
|
|
299
|
+
{props.readOnly && (
|
|
300
|
+
<StatusItem title={t('editor.statusReadOnlyTitle')}>{t('editor.statusReadOnly')}</StatusItem>
|
|
301
|
+
)}
|
|
302
|
+
<StatusItem
|
|
303
|
+
title={t('editor.statusWrapToggle')}
|
|
304
|
+
onClick={() => updateEditorSettings({ wrap: !props.wrap })}
|
|
305
|
+
>
|
|
306
|
+
{props.wrap ? t('editor.statusWrapOn') : t('editor.statusWrapOff')}
|
|
307
|
+
</StatusItem>
|
|
308
|
+
<StatusItem title={t('editor.statusFont')}>{`${props.fontSize}px`}</StatusItem>
|
|
309
|
+
<StatusItem title={t('editor.statusSaved')}>{saveLabel}</StatusItem>
|
|
310
|
+
</>
|
|
311
|
+
)}
|
|
312
|
+
<StatusItem title={t('editor.statusEncoding')}>UTF-8</StatusItem>
|
|
313
|
+
</div>
|
|
314
|
+
</div>
|
|
315
|
+
)
|
|
316
|
+
}
|
|
317
|
+
|
|
175
318
|
export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
176
319
|
const store = useExplorer()
|
|
177
320
|
const { t, tabs, activeTab, alias } = store
|
|
321
|
+
const settings = useEditorSettings()
|
|
322
|
+
/**
|
|
323
|
+
* Which chrome this mount renders. Derived from the store's EFFECTIVE surface
|
|
324
|
+
* (float wins over the base mount), never from a prop: the same component is
|
|
325
|
+
* mounted by the sidebar, the conversation view and the floating window, and
|
|
326
|
+
* exactly one of them may own the live buffer.
|
|
327
|
+
*/
|
|
328
|
+
const variant: EditorVariant = store.editorSurface === 'center'
|
|
329
|
+
? 'center'
|
|
330
|
+
: store.editorSurface === 'float' ? 'float' : 'sidebar'
|
|
331
|
+
const center = variant === 'center'
|
|
332
|
+
// The floating window owns its own Ctrl+wheel zoom (a property of the window,
|
|
333
|
+
// see FloatingEditorWindow), so the shared preference is set on the other two
|
|
334
|
+
// surfaces only.
|
|
335
|
+
const fontStyle = variant === 'float'
|
|
336
|
+
? undefined
|
|
337
|
+
: ({ '--rvs-editor-font-size': `${settings.fontSize}px` } as CSSProperties)
|
|
178
338
|
// Jump targets of the file on screen; empty when it carries no change data.
|
|
179
339
|
const changeHunks = activeTab?.changeSet?.hunks ?? []
|
|
180
340
|
const chat = useRemoteChatTarget(store.ctx)
|
|
@@ -208,6 +368,11 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
208
368
|
useEffect(() => {
|
|
209
369
|
setTokenCount(undefined)
|
|
210
370
|
}, [activeTab?.id])
|
|
371
|
+
/** Caret readout for the status bar; reset when the file changes. */
|
|
372
|
+
const [caret, setCaret] = useState<CodeEditorCaret | undefined>(undefined)
|
|
373
|
+
useEffect(() => {
|
|
374
|
+
setCaret(undefined)
|
|
375
|
+
}, [activeTab?.id])
|
|
211
376
|
/**
|
|
212
377
|
* The "see the difference" payload of a refused save.
|
|
213
378
|
*
|
|
@@ -231,20 +396,27 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
231
396
|
// (see the editor host below), so it cannot be gated wholesale.
|
|
232
397
|
if (props.visible === false) return
|
|
233
398
|
if (tab === undefined || !tab.image || alias === '') return
|
|
234
|
-
|
|
399
|
+
// A capped read has no decodable payload: skip the read entirely so a
|
|
400
|
+
// partial base64 never becomes a cached (undecodable) data URL. The
|
|
401
|
+
// "too large" notice is rendered from `truncated` instead.
|
|
402
|
+
if (tab.truncated) return
|
|
403
|
+
// Keyed by path + reload nonce, so a re-read shows the new bytes and a
|
|
404
|
+
// truncated read never caches a partial payload (see `imageCacheKey`).
|
|
405
|
+
const key = imageCacheKey(tab)
|
|
406
|
+
if (images[key] !== undefined || imageError[key] !== undefined) return
|
|
235
407
|
let cancelled = false
|
|
236
408
|
void (async () => {
|
|
237
409
|
try {
|
|
238
410
|
const read = await api.fileOp.read(alias, tab.fullPath)
|
|
239
411
|
if (cancelled) return
|
|
240
412
|
if (read.base64 === undefined) {
|
|
241
|
-
setImageError(prev => rememberRecent(prev,
|
|
413
|
+
setImageError(prev => rememberRecent(prev, key, t('editor.imageFailed')))
|
|
242
414
|
return
|
|
243
415
|
}
|
|
244
|
-
setImages(prev => rememberRecent(prev,
|
|
416
|
+
setImages(prev => rememberRecent(prev, key, `data:${mimeFor(tab.fullPath)};base64,${read.base64}`))
|
|
245
417
|
} catch (error) {
|
|
246
418
|
if (!cancelled) {
|
|
247
|
-
setImageError(prev => rememberRecent(prev,
|
|
419
|
+
setImageError(prev => rememberRecent(prev, key, error instanceof Error ? error.message : String(error)))
|
|
248
420
|
}
|
|
249
421
|
}
|
|
250
422
|
})()
|
|
@@ -257,8 +429,8 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
257
429
|
* instead of parking them until the page is reloaded.
|
|
258
430
|
*/
|
|
259
431
|
useEffect(() => {
|
|
260
|
-
setImages(prev => dropOversized(prev, activeTab
|
|
261
|
-
}, [activeTab?.fullPath])
|
|
432
|
+
setImages(prev => dropOversized(prev, activeTab === undefined ? undefined : imageCacheKey(activeTab)))
|
|
433
|
+
}, [activeTab?.fullPath, activeTab?.reloadNonce])
|
|
262
434
|
|
|
263
435
|
const closeWithGuard = async (tab: EditorTab): Promise<void> => {
|
|
264
436
|
if (tab.dirty) {
|
|
@@ -316,9 +488,23 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
316
488
|
return renderMarkdown(activeTab.text)
|
|
317
489
|
}, [activeTab])
|
|
318
490
|
|
|
491
|
+
/**
|
|
492
|
+
* The status bar's indent hint, derived from the loaded text.
|
|
493
|
+
*
|
|
494
|
+
* Memoised on the tab: the status bar re-renders on every caret move, and
|
|
495
|
+
* scanning 200 lines per arrow key would be free in theory and wasteful in
|
|
496
|
+
* practice.
|
|
497
|
+
*/
|
|
498
|
+
const indentLabel = useMemo(() => {
|
|
499
|
+
if (activeTab === undefined || activeTab.kind !== 'file' || activeTab.binary) return undefined
|
|
500
|
+
return detectIndentLabel(activeTab.text)
|
|
501
|
+
}, [activeTab])
|
|
502
|
+
|
|
319
503
|
// The editor owns the live buffer; the save path pulls it imperatively
|
|
320
504
|
// instead of mirroring every keystroke into React state.
|
|
321
505
|
const editorRef = useRef<CodeEditorHandle>(null)
|
|
506
|
+
/** Editor body container: anchors the Ctrl+wheel zoom listener. */
|
|
507
|
+
const bodyRef = useRef<HTMLDivElement>(null)
|
|
322
508
|
|
|
323
509
|
/**
|
|
324
510
|
* Scroll + caret per tab, so re-selecting a tab returns to where it was.
|
|
@@ -407,6 +593,30 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
407
593
|
return registerLiveEditor(activeTab.id, () => editorRef.current)
|
|
408
594
|
}, [editorMounted, activeTab?.id])
|
|
409
595
|
|
|
596
|
+
/**
|
|
597
|
+
* Ctrl/Cmd + wheel changes the editor font size (same feel as the floating
|
|
598
|
+
* window's zoom).
|
|
599
|
+
*
|
|
600
|
+
* A native listener, not React's `onWheel`: React attaches its wheel handler
|
|
601
|
+
* as passive at the root, so `preventDefault()` is ignored and the page
|
|
602
|
+
* zooms instead. Scoped to the editor body, so the tree/terminal keep their
|
|
603
|
+
* own gestures.
|
|
604
|
+
*/
|
|
605
|
+
useEffect(() => {
|
|
606
|
+
const element = bodyRef.current
|
|
607
|
+
if (element === null) return
|
|
608
|
+
const onWheel = (event: WheelEvent): void => {
|
|
609
|
+
if (!(event.ctrlKey || event.metaKey)) return
|
|
610
|
+
event.preventDefault()
|
|
611
|
+
const direction = event.deltaY < 0 ? 1 : -1
|
|
612
|
+
updateEditorSettings({ fontSize: stepFontSize(editorSettingsSnapshot().fontSize, direction) })
|
|
613
|
+
}
|
|
614
|
+
element.addEventListener('wheel', onWheel, { passive: false })
|
|
615
|
+
return () => element.removeEventListener('wheel', onWheel)
|
|
616
|
+
// Re-attach when the body container appears (it does not exist in the empty
|
|
617
|
+
// state) so the first opened file still gets the zoom.
|
|
618
|
+
}, [tabs.length])
|
|
619
|
+
|
|
410
620
|
const saveActive = async (): Promise<void> => {
|
|
411
621
|
const tab = activeTab
|
|
412
622
|
if (tab === undefined) return
|
|
@@ -543,112 +753,244 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
543
753
|
}, [props.visible])
|
|
544
754
|
|
|
545
755
|
if (tabs.length === 0) {
|
|
756
|
+
if (center) {
|
|
757
|
+
return (
|
|
758
|
+
<div className="rvs-pane grow rvs-edge">
|
|
759
|
+
<div className="rvs-editor-empty">
|
|
760
|
+
<div className="rvs-editor-empty-glyph" aria-hidden="true">✎</div>
|
|
761
|
+
<div className="rvs-editor-empty-title">{t('editor.centerEmptyTitle')}</div>
|
|
762
|
+
<div className="rvs-editor-empty-hint">{t('editor.centerEmptyHint')}</div>
|
|
763
|
+
<div className="rvs-editor-empty-hint" style={{ opacity: 0.7 }}>{t('editor.emptyShortcuts')}</div>
|
|
764
|
+
</div>
|
|
765
|
+
</div>
|
|
766
|
+
)
|
|
767
|
+
}
|
|
546
768
|
return (
|
|
547
769
|
<div className="rvs-pane grow rvs-edge">
|
|
548
770
|
<div className="rvs-empty">
|
|
549
|
-
{t('editor.
|
|
550
|
-
<div
|
|
551
|
-
<span className="rvs-kbd">Ctrl</span> + <span className="rvs-kbd">S</span> {t('editor.saveHint')}
|
|
552
|
-
</div>
|
|
771
|
+
<div className="rvs-empty-title">{t('editor.dockEmptyTitle')}</div>
|
|
772
|
+
<div className="rvs-empty-hint">{t('editor.dockEmptyHint')}</div>
|
|
553
773
|
</div>
|
|
554
774
|
</div>
|
|
555
775
|
)
|
|
556
776
|
}
|
|
557
777
|
|
|
778
|
+
const isDiff = activeTab?.kind === 'diff'
|
|
779
|
+
/**
|
|
780
|
+
* Whether the "switch to content editing" action makes sense for this diff.
|
|
781
|
+
*
|
|
782
|
+
* A commit drill-down compares historical blobs; opening TODAY's file from it
|
|
783
|
+
* would read as editing the commit. A deletion has no content to edit (the
|
|
784
|
+
* read would just fail), and a binary diff has nothing an editor can show.
|
|
785
|
+
*/
|
|
786
|
+
const canSwitchToEdit = activeTab !== undefined
|
|
787
|
+
&& activeTab.kind === 'diff'
|
|
788
|
+
&& activeTab.ref === undefined
|
|
789
|
+
&& activeTab.diff !== undefined
|
|
790
|
+
&& !activeTab.diff.unsupported
|
|
791
|
+
&& !(activeTab.diff.newText === '' && activeTab.diff.oldText !== '')
|
|
792
|
+
const displayPath = activeTab?.fullPath ?? ''
|
|
793
|
+
const language = isDiff
|
|
794
|
+
? 'Diff'
|
|
795
|
+
: activeTab?.image === true ? 'Image' : langLabel(langFromPath(activeTab?.rel ?? ''))
|
|
796
|
+
const activeImageKey = activeTab === undefined ? undefined : imageCacheKey(activeTab)
|
|
797
|
+
const imageSrc = activeTab !== undefined && activeTab.image && activeImageKey !== undefined
|
|
798
|
+
? images[activeImageKey]
|
|
799
|
+
: undefined
|
|
800
|
+
const imageFailure = activeTab !== undefined && activeTab.image && activeImageKey !== undefined
|
|
801
|
+
? imageError[activeImageKey]
|
|
802
|
+
: undefined
|
|
803
|
+
|
|
558
804
|
return (
|
|
559
|
-
<div className="rvs-pane grow rvs-edge">
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
{
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
805
|
+
<div className="rvs-pane grow rvs-edge" style={fontStyle}>
|
|
806
|
+
{/* Tab strip: switch / close / dirty dot / diff glyph. Middle-click closes
|
|
807
|
+
too — the muscle memory shared with VS Code and browsers. */}
|
|
808
|
+
<div className="rvs-etabs" role="tablist" aria-label={t('editor.tabsLabel')}>
|
|
809
|
+
{tabs.map(tab => {
|
|
810
|
+
const active = tab.id === store.activeTabId
|
|
811
|
+
const tabIsDiff = tab.kind === 'diff'
|
|
812
|
+
return (
|
|
813
|
+
<div
|
|
814
|
+
key={tab.id}
|
|
815
|
+
role="tab"
|
|
816
|
+
tabIndex={0}
|
|
817
|
+
aria-selected={active}
|
|
818
|
+
className={`rvs-etab${active ? ' active' : ''}${tabIsDiff ? ' rvs-etab-diff' : ''}`}
|
|
819
|
+
title={tabIsDiff ? `${tab.rel}${t('editor.diffSuffix')}` : tab.fullPath}
|
|
820
|
+
onClick={() => store.activateTab(tab.id)}
|
|
821
|
+
onAuxClick={(event) => {
|
|
822
|
+
if (event.button !== 1) return
|
|
823
|
+
event.preventDefault()
|
|
824
|
+
void closeWithGuard(tab)
|
|
825
|
+
}}
|
|
826
|
+
onKeyDown={(event) => {
|
|
827
|
+
// An IME composition owns Enter/Space (the candidate list).
|
|
828
|
+
if (event.nativeEvent.isComposing) return
|
|
829
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
830
|
+
event.preventDefault()
|
|
831
|
+
store.activateTab(tab.id)
|
|
832
|
+
}
|
|
833
|
+
}}
|
|
585
834
|
>
|
|
586
|
-
<
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
835
|
+
<span className="rvs-etab-glyph">{tabIcon(tab)}</span>
|
|
836
|
+
<span className="rvs-etab-name">
|
|
837
|
+
{baseName(tab.rel)}
|
|
838
|
+
{tabIsDiff && <span style={{ opacity: .6 }}>{t('editor.diffSuffix')}</span>}
|
|
839
|
+
</span>
|
|
840
|
+
{tab.dirty && <span className="rvs-etab-dot" title={t('editor.unsaved')} />}
|
|
841
|
+
<button
|
|
842
|
+
type="button"
|
|
843
|
+
className="rvs-etab-close"
|
|
844
|
+
title={t('common.close')}
|
|
845
|
+
aria-label={t('common.close')}
|
|
846
|
+
onClick={(event) => { event.stopPropagation(); void closeWithGuard(tab) }}
|
|
847
|
+
>
|
|
848
|
+
<IconClose size={11} />
|
|
849
|
+
</button>
|
|
850
|
+
</div>
|
|
851
|
+
)
|
|
852
|
+
})}
|
|
590
853
|
</div>
|
|
854
|
+
|
|
591
855
|
{activeTab !== undefined && (
|
|
592
856
|
<>
|
|
857
|
+
{/* Info row: breadcrumb in the full-width variant (sibling picker),
|
|
858
|
+
single path line in the docked one. */}
|
|
593
859
|
<div className="rvs-einfo">
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
{
|
|
602
|
-
{
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
{tokenCount !== undefined && (
|
|
622
|
-
<span className="rvs-build" title={t('editor.tokenCount')}>tok {tokenCount}</span>
|
|
623
|
-
)}
|
|
624
|
-
{activeTab.kind === 'file' && (
|
|
625
|
-
<>
|
|
626
|
-
{/* The status chip used to be a four-deep nested ternary in
|
|
627
|
-
both the class and the label, while the project's own
|
|
628
|
-
review checklist forbids nested ternaries. One lookup per
|
|
629
|
-
concern instead. */}
|
|
630
|
-
<span className={`rvs-status ${tabStatusClass(activeTab)}`}>
|
|
631
|
-
{t(tabStatusKey(activeTab))}
|
|
860
|
+
{center && activeTab.kind === 'file'
|
|
861
|
+
? (
|
|
862
|
+
<Breadcrumb
|
|
863
|
+
t={t}
|
|
864
|
+
alias={alias}
|
|
865
|
+
root={store.root}
|
|
866
|
+
rootName={store.workspace?.name ?? ''}
|
|
867
|
+
path={displayPath}
|
|
868
|
+
onOpen={(fullPath) => { store.openFile(fullPath) }}
|
|
869
|
+
/>
|
|
870
|
+
)
|
|
871
|
+
: <span className="rvs-einfo-path" title={displayPath}>{displayPath}</span>}
|
|
872
|
+
<span className="rvs-einfo-actions">
|
|
873
|
+
{activeTab.kind === 'file' && (activeTab.markdown || activeTab.html) && (
|
|
874
|
+
<Segmented<'preview' | 'source'>
|
|
875
|
+
value={activeTab.preview ? 'preview' : 'source'}
|
|
876
|
+
onChange={(next) => store.updateTab(activeTab.id, { preview: next === 'preview' })}
|
|
877
|
+
options={[
|
|
878
|
+
{ id: 'preview', label: t('editor.preview') },
|
|
879
|
+
{ id: 'source', label: t('editor.source') },
|
|
880
|
+
]}
|
|
881
|
+
/>
|
|
882
|
+
)}
|
|
883
|
+
{activeTab.kind === 'diff' && (
|
|
884
|
+
<span style={{ color: 'var(--rvs-fg3)' }}>
|
|
885
|
+
{activeTab.staged && activeTab.ref === undefined ? t('scm.stagedReadonly') : ''}
|
|
886
|
+
{activeTab.ref !== undefined ? `${t('scm.commitDiff')} ${activeTab.ref.slice(0, 7)}` : ''}
|
|
632
887
|
</span>
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
888
|
+
)}
|
|
889
|
+
<span style={{ color: 'var(--rvs-fg3)' }}>{language}</span>
|
|
890
|
+
{/* Connection health sits where the build stamp does: it is the
|
|
891
|
+
surface the user is looking at while they work. */}
|
|
892
|
+
<ConnectionStatusChip compact />
|
|
893
|
+
{/* Build stamp + token count (see tsdown `define.__RVS_BUILD__`).
|
|
894
|
+
The GUI serves plugin bundles captured when `dsh web` started,
|
|
895
|
+
so the stamp says WHICH code is running, and the token count
|
|
896
|
+
says whether the grammar actually produced colored tokens. */}
|
|
897
|
+
<span className="rvs-build" title={`dsh-remote-vs build ${__RVS_BUILD__}`}>{__RVS_BUILD__}</span>
|
|
898
|
+
{tokenCount !== undefined && (
|
|
899
|
+
<span className="rvs-build" title={t('editor.tokenCount')}>tok {tokenCount}</span>
|
|
900
|
+
)}
|
|
901
|
+
{activeTab.kind === 'file' && (
|
|
902
|
+
<>
|
|
903
|
+
{/* The status chip used to be a four-deep nested ternary in
|
|
904
|
+
both the class and the label, while the project's own
|
|
905
|
+
review checklist forbids nested ternaries. One lookup per
|
|
906
|
+
concern instead. */}
|
|
907
|
+
<span className={`rvs-status ${tabStatusClass(activeTab)}`}>
|
|
908
|
+
{t(tabStatusKey(activeTab))}
|
|
909
|
+
</span>
|
|
910
|
+
<IconButton title={t('editor.reloadFile')} onClick={() => { void reloadWithGuard(activeTab) }} disabled={offline || activeTab.loading}>
|
|
911
|
+
<IconRefresh size={13} />
|
|
912
|
+
</IconButton>
|
|
913
|
+
<IconButton
|
|
914
|
+
title={`${t('editor.save')} (Ctrl+S)`}
|
|
915
|
+
onClick={() => { void saveActive() }}
|
|
916
|
+
disabled={offline || activeTab.loading || activeTab.binary || activeTab.truncated || !activeTab.dirty}
|
|
917
|
+
>
|
|
918
|
+
<IconSave size={13} />
|
|
919
|
+
</IconButton>
|
|
920
|
+
</>
|
|
921
|
+
)}
|
|
922
|
+
{activeTab.kind === 'diff' && (
|
|
923
|
+
<>
|
|
924
|
+
<IconButton title={t('scm.reloadDiff')} onClick={() => { void reloadWithGuard(activeTab) }} disabled={offline}>
|
|
925
|
+
<IconRefresh size={13} />
|
|
926
|
+
</IconButton>
|
|
927
|
+
{/* A diff is a view of a file, not a place to edit: this opens
|
|
928
|
+
the same path as a normal content tab, next to where the
|
|
929
|
+
save button lives for file tabs. Commit drills (historical
|
|
930
|
+
blobs), deletions and binary diffs are left out. */}
|
|
931
|
+
{canSwitchToEdit && (
|
|
932
|
+
<IconButton
|
|
933
|
+
title={t('editor.switchToEdit')}
|
|
934
|
+
onClick={() => { store.openFile(activeTab.fullPath) }}
|
|
935
|
+
>
|
|
936
|
+
<IconCode size={13} />
|
|
937
|
+
</IconButton>
|
|
938
|
+
)}
|
|
939
|
+
</>
|
|
940
|
+
)}
|
|
941
|
+
{activeTab.kind === 'file' && !activeTab.image && !activeTab.binary && (
|
|
636
942
|
<IconButton
|
|
637
|
-
title={
|
|
638
|
-
onClick={() => {
|
|
639
|
-
disabled={offline || activeTab.loading || activeTab.binary || activeTab.truncated || !activeTab.dirty}
|
|
943
|
+
title={t('editor.wrap')}
|
|
944
|
+
onClick={() => updateEditorSettings({ wrap: !settings.wrap })}
|
|
640
945
|
>
|
|
641
|
-
<
|
|
946
|
+
<IconWrap size={13} />
|
|
642
947
|
</IconButton>
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
948
|
+
)}
|
|
949
|
+
<span className="rvs-einfo-actions-divider" aria-hidden="true" />
|
|
950
|
+
{/* The floating window owns its OWN Ctrl+wheel zoom (a property of
|
|
951
|
+
that window, persisted per window): the shared preference is not
|
|
952
|
+
what paints there, so these two would look dead inside it. */}
|
|
953
|
+
{variant !== 'float' && (
|
|
954
|
+
<>
|
|
955
|
+
<IconButton
|
|
956
|
+
title={t('editor.fontSmaller')}
|
|
957
|
+
onClick={() => updateEditorSettings({ fontSize: stepFontSize(settings.fontSize, -1) })}
|
|
958
|
+
>
|
|
959
|
+
<span className="rvs-font-glyph">A−</span>
|
|
960
|
+
</IconButton>
|
|
961
|
+
<IconButton
|
|
962
|
+
title={t('editor.fontLarger')}
|
|
963
|
+
onClick={() => updateEditorSettings({ fontSize: stepFontSize(settings.fontSize, 1) })}
|
|
964
|
+
>
|
|
965
|
+
<span className="rvs-font-glyph">A+</span>
|
|
966
|
+
</IconButton>
|
|
967
|
+
</>
|
|
968
|
+
)}
|
|
969
|
+
{variant !== 'float' && (
|
|
970
|
+
<IconButton title={t('float.title')} onClick={() => { store.openFloatingEditor() }}>
|
|
971
|
+
<IconFloat size={13} />
|
|
972
|
+
</IconButton>
|
|
973
|
+
)}
|
|
974
|
+
{/* Same editor, another surface. One instance only: flipping the
|
|
975
|
+
store's surface unmounts this mount and the target one takes
|
|
976
|
+
the same buffer over (see the file header). */}
|
|
977
|
+
{variant === 'center'
|
|
978
|
+
? (
|
|
979
|
+
<IconButton title={t('editor.dockToSidebar')} onClick={() => { store.dockEditorSidebar() }}>
|
|
980
|
+
<IconCollapse size={13} />
|
|
981
|
+
</IconButton>
|
|
982
|
+
)
|
|
983
|
+
: variant === 'sidebar'
|
|
984
|
+
? (
|
|
985
|
+
<IconButton title={t('editor.openInCenter')} onClick={() => { store.openEditorInCenter() }}>
|
|
986
|
+
<IconExpand size={13} />
|
|
987
|
+
</IconButton>
|
|
988
|
+
)
|
|
989
|
+
: null}
|
|
990
|
+
</span>
|
|
650
991
|
</div>
|
|
651
|
-
|
|
992
|
+
|
|
993
|
+
<div className="rvs-body" ref={bodyRef}>
|
|
652
994
|
{/*
|
|
653
995
|
A REFUSED save: the remote file moved on, so nothing was written.
|
|
654
996
|
This sits above the buffer (not in a toast) because it is a
|
|
@@ -747,14 +1089,30 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
747
1089
|
)}
|
|
748
1090
|
{!activeTab.loading && activeTab.error === undefined && activeTab.kind === 'file' && (
|
|
749
1091
|
<>
|
|
750
|
-
{
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
1092
|
+
{/* A capped read has no decodable payload: the preview component
|
|
1093
|
+
turns that into a "too large" notice instead of the browser's
|
|
1094
|
+
broken-image icon, so it is mounted for every image tab. */}
|
|
1095
|
+
{activeTab.image && (imageSrc !== undefined || activeTab.truncated) && (
|
|
1096
|
+
<ImagePreview
|
|
1097
|
+
src={imageSrc ?? ''}
|
|
1098
|
+
path={activeTab.rel}
|
|
1099
|
+
size={activeTab.remoteSize ?? 0}
|
|
1100
|
+
{...(activeTab.truncated ? { truncated: true } : {})}
|
|
1101
|
+
t={t}
|
|
1102
|
+
/>
|
|
1103
|
+
)}
|
|
1104
|
+
{activeTab.image && imageSrc === undefined && !activeTab.truncated && (
|
|
1105
|
+
<div className="rvs-editor-notice">
|
|
1106
|
+
<div>{imageFailure ?? t('common.loading')}</div>
|
|
1107
|
+
</div>
|
|
1108
|
+
)}
|
|
1109
|
+
{!activeTab.image && activeTab.binary && (
|
|
1110
|
+
<div className="rvs-editor-notice">
|
|
1111
|
+
<div className="rvs-editor-notice-title">{t('editor.binaryTitle')}</div>
|
|
1112
|
+
<div>{activeTab.rel}</div>
|
|
1113
|
+
<div>{t('editor.binary')}</div>
|
|
755
1114
|
</div>
|
|
756
1115
|
)}
|
|
757
|
-
{!activeTab.image && activeTab.binary && <div className="rvs-empty">{t('editor.binary')}</div>}
|
|
758
1116
|
{!activeTab.image && !activeTab.binary && activeTab.markdown && activeTab.preview && markdownPreview}
|
|
759
1117
|
{!activeTab.image && !activeTab.binary && activeTab.html && activeTab.preview && (
|
|
760
1118
|
<iframe className="rvs-html-frame" title={activeTab.rel} sandbox="allow-same-origin" srcDoc={htmlDoc} />
|
|
@@ -782,6 +1140,7 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
782
1140
|
tabId={activeTab.id}
|
|
783
1141
|
readOnly={activeTab.truncated || offline}
|
|
784
1142
|
visible={props.visible}
|
|
1143
|
+
wrap={settings.wrap}
|
|
785
1144
|
ctx={store.ctx}
|
|
786
1145
|
sessionId={chat.sessionId}
|
|
787
1146
|
remoteRoot={store.repoRoot ?? store.root}
|
|
@@ -796,6 +1155,7 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
796
1155
|
? {}
|
|
797
1156
|
: { viewState: editorViewStateOf(activeTab.id) })}
|
|
798
1157
|
onTokens={setTokenCount}
|
|
1158
|
+
onCaretChange={setCaret}
|
|
799
1159
|
onViewState={rememberViewState}
|
|
800
1160
|
onStepHunk={(dir) => { gotoChange(activeTab.id, dir) }}
|
|
801
1161
|
onChangeStale={() => { markChangeStale(activeTab.id) }}
|
|
@@ -810,6 +1170,24 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
810
1170
|
</>
|
|
811
1171
|
)}
|
|
812
1172
|
</div>
|
|
1173
|
+
|
|
1174
|
+
{/* Status bar: full-width variant only, matching the reference editor. */}
|
|
1175
|
+
{center && (
|
|
1176
|
+
<StatusBar
|
|
1177
|
+
t={t}
|
|
1178
|
+
diff={isDiff}
|
|
1179
|
+
caret={caret}
|
|
1180
|
+
language={language}
|
|
1181
|
+
indent={indentLabel}
|
|
1182
|
+
wrap={settings.wrap}
|
|
1183
|
+
fontSize={settings.fontSize}
|
|
1184
|
+
readOnly={activeTab.kind === 'file' && (activeTab.binary || activeTab.truncated || offline)}
|
|
1185
|
+
dirty={activeTab.dirty}
|
|
1186
|
+
loading={activeTab.loading}
|
|
1187
|
+
saving={activeTab.saving}
|
|
1188
|
+
error={activeTab.error}
|
|
1189
|
+
/>
|
|
1190
|
+
)}
|
|
813
1191
|
</>
|
|
814
1192
|
)}
|
|
815
1193
|
</div>
|