dsh-remote-vs 0.25.0 → 0.27.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 +12 -15
- package/README.md +11 -12
- package/THIRD-PARTY-NOTICES.md +193 -0
- package/lib/client.js +7313 -79961
- package/lib/index.js +1529 -964
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/client/CodeEditor.d.ts +22 -0
- package/lib/types/client/OutlinePanel.d.ts +22 -0
- package/lib/types/client/ProcessesSection.d.ts +19 -0
- package/lib/types/client/RemoteExplorer.d.ts +53 -0
- package/lib/types/client/api.d.ts +42 -3
- package/lib/types/client/blame-model.d.ts +77 -0
- package/lib/types/client/changes/review-state.d.ts +19 -0
- package/lib/types/client/connection.d.ts +16 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/outline-model.d.ts +59 -0
- package/lib/types/client/request-gate.d.ts +110 -0
- package/lib/types/client/scm/DiffView.d.ts +45 -7
- package/lib/types/client/scm/actions.d.ts +43 -4
- package/lib/types/client/store.d.ts +71 -0
- package/lib/types/client/vsc/FindWidget.d.ts +6 -0
- package/lib/types/client/vsc/blame.d.ts +19 -0
- package/lib/types/client/vsc/change-marks.d.ts +16 -6
- package/lib/types/client/vsc/editor-keymap.d.ts +35 -1
- package/lib/types/client/vsc/kit.d.ts +11 -2
- package/lib/types/client/vsc/preview-document.d.ts +46 -0
- package/lib/types/client/vsc/preview-model.d.ts +31 -0
- package/lib/types/client/vsc/preview-services.d.ts +24 -0
- package/lib/types/client/vsc/save-shortcut.d.ts +21 -0
- package/lib/types/client/vsc/terminal-theme.d.ts +28 -2
- package/lib/types/forward.d.ts +12 -0
- package/lib/types/fs-ops.d.ts +42 -0
- package/lib/types/git-ops.d.ts +18 -0
- package/lib/types/http.d.ts +2 -0
- package/lib/types/keygen.d.ts +9 -0
- package/lib/types/monitor.d.ts +8 -0
- package/lib/types/notices.d.ts +16 -1
- package/lib/types/p2/helper-rpc.d.ts +45 -0
- package/lib/types/processes.d.ts +43 -0
- package/lib/types/protocol.d.ts +34 -0
- package/lib/types/routes.d.ts +2 -0
- package/lib/types/store.d.ts +7 -0
- package/lib/types/terminal.d.ts +8 -0
- package/lib/types/view-settings.d.ts +5 -0
- package/lib/{worlds-B7gEDBzC.js → worlds-RG8K5eom.js} +113 -15
- package/package.json +3 -1
- package/src/client/CodeEditor.tsx +194 -9
- package/src/client/DirectoryFlow.tsx +16 -0
- package/src/client/DoctorPanel.tsx +70 -7
- package/src/client/EditorPane.tsx +574 -42
- package/src/client/HostsView.tsx +12 -3
- package/src/client/MonitorView.tsx +16 -5
- package/src/client/OutlinePanel.tsx +287 -0
- package/src/client/ProcessesSection.tsx +292 -0
- package/src/client/RemoteDirectoryPicker.tsx +12 -0
- package/src/client/RemoteExplorer.tsx +929 -40
- package/src/client/RemoteRoot.tsx +147 -22
- package/src/client/SearchView.tsx +8 -0
- package/src/client/TerminalSnippets.tsx +83 -8
- package/src/client/api.ts +114 -13
- package/src/client/blame-model.ts +242 -0
- package/src/client/changes/ChangesDock.tsx +188 -6
- package/src/client/changes/changes.css +10 -3
- package/src/client/changes/review-state.ts +34 -0
- package/src/client/connection.ts +29 -0
- package/src/client/downloads.ts +49 -4
- package/src/client/i18n.ts +276 -8
- package/src/client/index.tsx +4 -0
- package/src/client/outline-model.ts +775 -0
- package/src/client/request-gate.ts +221 -0
- package/src/client/scm/CommitPane.tsx +20 -2
- package/src/client/scm/DiffView.tsx +343 -117
- package/src/client/scm/HistoryPanel.tsx +61 -3
- package/src/client/scm/RepoPicker.tsx +1 -1
- package/src/client/scm/ScmPanel.tsx +391 -87
- package/src/client/scm/actions.ts +150 -14
- package/src/client/store.tsx +426 -14
- package/src/client/ui.tsx +4 -0
- package/src/client/vsc/FindWidget.tsx +24 -9
- package/src/client/vsc/blame.ts +147 -0
- package/src/client/vsc/breadcrumb.tsx +91 -3
- package/src/client/vsc/change-marks.ts +93 -44
- package/src/client/vsc/editor-keymap.ts +59 -1
- package/src/client/vsc/file-icons.tsx +17 -3
- package/src/client/vsc/kit.tsx +29 -20
- package/src/client/vsc/preview-document.tsx +323 -0
- package/src/client/vsc/preview-model.ts +216 -0
- package/src/client/vsc/preview-services.ts +118 -0
- package/src/client/vsc/save-shortcut.ts +47 -1
- package/src/client/vsc/terminal-theme.ts +44 -18
- package/src/client/vsc/vsc.css +6509 -5458
- package/src/forward.ts +47 -9
- package/src/fs-ops.ts +124 -4
- package/src/git-ops.ts +54 -3
- package/src/http.ts +35 -4
- package/src/keygen.ts +55 -4
- package/src/monitor.ts +13 -0
- package/src/notices.ts +23 -1
- package/src/p2/helper-rpc.ts +113 -7
- package/src/p2/worlds.ts +14 -1
- package/src/processes.ts +177 -0
- package/src/protocol.ts +37 -0
- package/src/routes.ts +330 -43
- package/src/sftp.ts +51 -14
- package/src/store.ts +10 -0
- package/src/terminal.ts +73 -26
- package/src/view-settings.ts +50 -10
- package/lib/types/client/Dialog.d.ts +0 -14
- package/src/client/Dialog.tsx +0 -76
|
@@ -28,14 +28,21 @@ import { isConnectionFailure, useConnectionStatus } from './connection.ts'
|
|
|
28
28
|
import { sameLocalDir } from './composer.ts'
|
|
29
29
|
import { editorViewStateOf, pruneEditorViewStates, registerLiveEditor, rememberEditorViewState } from './live-editor.ts'
|
|
30
30
|
import { useRemoteChatTarget } from './use-remote-chat-target.ts'
|
|
31
|
-
import { useExplorer, gotoChange, markChangeStale, undoChange, type EditorTab } from './store.tsx'
|
|
31
|
+
import { useExplorer, gotoChange, markChangeStale, repoRelative, undoChange, type EditorTab } from './store.tsx'
|
|
32
32
|
import { DiffView } from './scm/DiffView.tsx'
|
|
33
|
+
import { loadBlame, loadFileHistory } from './scm/actions.ts'
|
|
34
|
+
import { isCommittedBlame, planBlameWindow, type BlameLine, type FileHistoryCommit } from './blame-model.ts'
|
|
33
35
|
import { Btn } from './ui.tsx'
|
|
34
|
-
import {
|
|
36
|
+
import { MarkdownText } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
35
37
|
import { langLabel, langFromPath } from './vsc/tokenize.ts'
|
|
36
|
-
import { installSaveShortcut } from './vsc/save-shortcut.ts'
|
|
38
|
+
import { FOREIGN_TARGET, installSaveShortcut, isModalLayerOpen } from './vsc/save-shortcut.ts'
|
|
39
|
+
import { OutlinePanel } from './OutlinePanel.tsx'
|
|
40
|
+
import type { OutlineEntry } from './outline-model.ts'
|
|
37
41
|
import { Breadcrumb } from './vsc/breadcrumb.tsx'
|
|
38
42
|
import { ImagePreview } from './vsc/image-preview.tsx'
|
|
43
|
+
import { hasTextSource, isBytePreview, previewKindLabel, previewKindOf, type PreviewKind } from './vsc/preview-model.ts'
|
|
44
|
+
import { BytePreview, SvgPreview, TablePreview } from './vsc/preview-document.tsx'
|
|
45
|
+
import { isDarkScheme, subscribeColorScheme } from './theme.ts'
|
|
39
46
|
import {
|
|
40
47
|
editorSettingsSnapshot,
|
|
41
48
|
stepFontSize,
|
|
@@ -66,6 +73,48 @@ import {
|
|
|
66
73
|
/** How many hunks of a conflict diff are rendered before the rest is summarised. */
|
|
67
74
|
const CONFLICT_DIFF_HUNKS = 20
|
|
68
75
|
|
|
76
|
+
/**
|
|
77
|
+
* 「大纲」是否可用:一个真正的文本文件 tab,读完且没读错,不是二进制/图片。
|
|
78
|
+
*
|
|
79
|
+
* 预览模式(markdown/HTML)也排除:那时 CodeMirror 被 CSS 隐藏,跳过去虽然改了
|
|
80
|
+
* 选区,屏幕上却什么也看不到 —— 一个看起来没反应的按钮比没有按钮更糟。
|
|
81
|
+
*/
|
|
82
|
+
function outlineAvailable(tab: EditorTab | undefined): tab is EditorTab {
|
|
83
|
+
if (tab === undefined || tab.kind !== 'file') return false
|
|
84
|
+
if (tab.image || tab.binary || tab.loading || tab.error !== undefined) return false
|
|
85
|
+
return !(tab.preview && hasTextSource(previewKindOf(tab.fullPath)))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const BLAME_PREF_KEY = 'dsh-remote-vs.editor.blame'
|
|
89
|
+
const EMPTY_BLAME: ReadonlyMap<number, BlameLine> = new Map()
|
|
90
|
+
|
|
91
|
+
/** Inline blame is on by default, but the choice survives a reload. */
|
|
92
|
+
function readBlamePreference(): boolean {
|
|
93
|
+
try {
|
|
94
|
+
return localStorage.getItem(BLAME_PREF_KEY) !== '0'
|
|
95
|
+
} catch {
|
|
96
|
+
return true
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function writeBlamePreference(value: boolean): void {
|
|
101
|
+
try {
|
|
102
|
+
localStorage.setItem(BLAME_PREF_KEY, value ? '1' : '0')
|
|
103
|
+
} catch {
|
|
104
|
+
// Private mode: the preference simply does not persist.
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Number of lines a loaded buffer has (the last empty line still counts). */
|
|
109
|
+
function lineCountOf(text: string): number {
|
|
110
|
+
if (text === '') return 1
|
|
111
|
+
let count = 1
|
|
112
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
113
|
+
if (text.charCodeAt(index) === 10) count += 1
|
|
114
|
+
}
|
|
115
|
+
return count
|
|
116
|
+
}
|
|
117
|
+
|
|
69
118
|
/**
|
|
70
119
|
* Reject a remote call that never answers.
|
|
71
120
|
*
|
|
@@ -318,6 +367,10 @@ function StatusBar(props: {
|
|
|
318
367
|
export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
319
368
|
const store = useExplorer()
|
|
320
369
|
const { t, tabs, activeTab, alias } = store
|
|
370
|
+
// Commands run in `repoRoot`, not in the workspace root: a repository that
|
|
371
|
+
// lives in a subdirectory (`repoSubdir`) would otherwise get a workspace-
|
|
372
|
+
// relative path and fail with `no such path`.
|
|
373
|
+
const repoRel = activeTab === undefined ? '' : repoRelative(store.repoRoot, activeTab.fullPath)
|
|
321
374
|
const settings = useEditorSettings()
|
|
322
375
|
/**
|
|
323
376
|
* Which chrome this mount renders. Derived from the store's EFFECTIVE surface
|
|
@@ -354,6 +407,17 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
354
407
|
const connection = useConnectionStatus()
|
|
355
408
|
const offline = connection?.state === 'error'
|
|
356
409
|
|
|
410
|
+
/**
|
|
411
|
+
* The tab strip's roving focus stops, by tab id.
|
|
412
|
+
*
|
|
413
|
+
* The strip is ONE Tab stop (WAI-ARIA tabs): ←/→ and Home/End move the
|
|
414
|
+
* selection inside it, and only the active tab carries `tabIndex={0}`. A map
|
|
415
|
+
* (not refs on the elements) because the strip is rebuilt from the store on
|
|
416
|
+
* every render, and a keydown must be able to focus a SIBLING that is not the
|
|
417
|
+
* one it fired on.
|
|
418
|
+
*/
|
|
419
|
+
const tabElements = useRef(new Map<string, HTMLDivElement>())
|
|
420
|
+
|
|
357
421
|
// Image data URL cache, keyed by path (remote reads are not free). Bounded —
|
|
358
422
|
// see `rememberRecent` / `dropOversized`.
|
|
359
423
|
const [images, setImages] = useState<Record<string, string>>({})
|
|
@@ -373,6 +437,160 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
373
437
|
useEffect(() => {
|
|
374
438
|
setCaret(undefined)
|
|
375
439
|
}, [activeTab?.id])
|
|
440
|
+
|
|
441
|
+
// --- inline blame + per-file history -------------------------------------
|
|
442
|
+
const [blameOn, setBlameOn] = useState<boolean>(readBlamePreference)
|
|
443
|
+
const [blameRows, setBlameRows] = useState<ReadonlyMap<number, BlameLine>>(EMPTY_BLAME)
|
|
444
|
+
const [blameViewport, setBlameViewport] = useState<{ from: number; to: number } | undefined>(undefined)
|
|
445
|
+
const [blameError, setBlameError] = useState<string | undefined>(undefined)
|
|
446
|
+
const blameTicket = useRef(0)
|
|
447
|
+
const blameRequested = useRef(new Set<string>())
|
|
448
|
+
const blameFailed = useRef('')
|
|
449
|
+
const blameViewportTimer = useRef<number | undefined>(undefined)
|
|
450
|
+
const [fileHistoryOpen, setFileHistoryOpen] = useState(false)
|
|
451
|
+
const [fileHistoryRows, setFileHistoryRows] = useState<FileHistoryCommit[]>([])
|
|
452
|
+
const [fileHistoryLoading, setFileHistoryLoading] = useState(false)
|
|
453
|
+
const [fileHistoryError, setFileHistoryError] = useState<string | undefined>(undefined)
|
|
454
|
+
|
|
455
|
+
// A new buffer (or an edited one) invalidates both windows and their line
|
|
456
|
+
// numbers; the next viewport report starts a fresh read.
|
|
457
|
+
useEffect(() => {
|
|
458
|
+
blameTicket.current += 1
|
|
459
|
+
blameRequested.current.clear()
|
|
460
|
+
blameFailed.current = ''
|
|
461
|
+
setBlameViewport(undefined)
|
|
462
|
+
setBlameRows(EMPTY_BLAME)
|
|
463
|
+
setBlameError(undefined)
|
|
464
|
+
setFileHistoryOpen(false)
|
|
465
|
+
setFileHistoryRows([])
|
|
466
|
+
setFileHistoryError(undefined)
|
|
467
|
+
}, [activeTab?.id, activeTab?.dirty, activeTab?.reloadNonce])
|
|
468
|
+
|
|
469
|
+
const toggleBlame = useCallback(() => {
|
|
470
|
+
setBlameOn(current => {
|
|
471
|
+
const next = !current
|
|
472
|
+
writeBlamePreference(next)
|
|
473
|
+
return next
|
|
474
|
+
})
|
|
475
|
+
}, [])
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* One `-L` read per uncovered viewport window.
|
|
479
|
+
*
|
|
480
|
+
* `blameRequested` is the cheap "this exact window was already asked for"
|
|
481
|
+
* guard; it is cleared on a buffer/dirty change, and a failed read deletes its
|
|
482
|
+
* key so a later scroll can retry it. Only one request may be in flight —
|
|
483
|
+
* CodeMirror scroll events are frequent and the exec channel is shared.
|
|
484
|
+
*/
|
|
485
|
+
useEffect(() => {
|
|
486
|
+
const tab = activeTab
|
|
487
|
+
if (
|
|
488
|
+
!blameOn || tab === undefined || tab.kind !== 'file' || tab.loading || tab.dirty || tab.binary || tab.truncated || tab.preview
|
|
489
|
+
|| isBytePreview(previewKindOf(tab.fullPath))
|
|
490
|
+
|| alias === '' || store.repoRoot === undefined || repoRel === '' || blameViewport === undefined
|
|
491
|
+
) {
|
|
492
|
+
setBlameRows(EMPTY_BLAME)
|
|
493
|
+
return
|
|
494
|
+
}
|
|
495
|
+
const total = lineCountOf(tab.text)
|
|
496
|
+
const failureKey = `${tab.id}:${tab.reloadNonce ?? 0}:${repoRel}:${blameOn ? '1' : '0'}`
|
|
497
|
+
if (blameFailed.current === failureKey) return
|
|
498
|
+
const window = planBlameWindow(
|
|
499
|
+
blameViewport.from,
|
|
500
|
+
blameViewport.to,
|
|
501
|
+
total,
|
|
502
|
+
new Set(blameRows.keys()),
|
|
503
|
+
)
|
|
504
|
+
if (window === undefined) return
|
|
505
|
+
const { from, to } = window
|
|
506
|
+
const key = `${tab.id}:${tab.reloadNonce ?? 0}:${from}:${to}`
|
|
507
|
+
if (blameRequested.current.has(key)) return
|
|
508
|
+
blameRequested.current.add(key)
|
|
509
|
+
const ticket = ++blameTicket.current
|
|
510
|
+
const controller = new AbortController()
|
|
511
|
+
void loadBlame(alias, store.repoRoot, repoRel, from, to, { signal: controller.signal })
|
|
512
|
+
.then((rows) => {
|
|
513
|
+
if (ticket !== blameTicket.current) return
|
|
514
|
+
setBlameRows((previous) => {
|
|
515
|
+
const next = new Map(previous)
|
|
516
|
+
for (const row of rows) next.set(row.line, row)
|
|
517
|
+
return next
|
|
518
|
+
})
|
|
519
|
+
setBlameError(undefined)
|
|
520
|
+
})
|
|
521
|
+
.catch((error: unknown) => {
|
|
522
|
+
blameRequested.current.delete(key)
|
|
523
|
+
if (controller.signal.aborted) return
|
|
524
|
+
if (ticket !== blameTicket.current) return
|
|
525
|
+
blameFailed.current = failureKey
|
|
526
|
+
setBlameError(error instanceof Error ? error.message : String(error))
|
|
527
|
+
})
|
|
528
|
+
return () => { controller.abort() }
|
|
529
|
+
}, [
|
|
530
|
+
activeTab?.id,
|
|
531
|
+
activeTab?.dirty,
|
|
532
|
+
activeTab?.reloadNonce,
|
|
533
|
+
blameOn,
|
|
534
|
+
blameRows,
|
|
535
|
+
blameViewport?.from,
|
|
536
|
+
blameViewport?.to,
|
|
537
|
+
alias,
|
|
538
|
+
repoRel,
|
|
539
|
+
store.repoRoot,
|
|
540
|
+
])
|
|
541
|
+
|
|
542
|
+
const onEditorViewport = useCallback((first: number, last: number) => {
|
|
543
|
+
if (blameViewportTimer.current !== undefined) window.clearTimeout(blameViewportTimer.current)
|
|
544
|
+
blameViewportTimer.current = window.setTimeout(() => {
|
|
545
|
+
blameViewportTimer.current = undefined
|
|
546
|
+
setBlameViewport(previous => (
|
|
547
|
+
previous !== undefined && previous.from === first && previous.to === last
|
|
548
|
+
? previous
|
|
549
|
+
: { from: first, to: last }
|
|
550
|
+
))
|
|
551
|
+
}, 140)
|
|
552
|
+
}, [])
|
|
553
|
+
useEffect(() => () => {
|
|
554
|
+
if (blameViewportTimer.current !== undefined) window.clearTimeout(blameViewportTimer.current)
|
|
555
|
+
}, [])
|
|
556
|
+
|
|
557
|
+
useEffect(() => {
|
|
558
|
+
const tab = activeTab
|
|
559
|
+
if (!fileHistoryOpen || tab === undefined || tab.kind !== 'file' || alias === '' || store.repoRoot === undefined || repoRel === '') {
|
|
560
|
+
setFileHistoryRows([])
|
|
561
|
+
setFileHistoryError(undefined)
|
|
562
|
+
setFileHistoryLoading(false)
|
|
563
|
+
return
|
|
564
|
+
}
|
|
565
|
+
let cancelled = false
|
|
566
|
+
setFileHistoryLoading(true)
|
|
567
|
+
setFileHistoryError(undefined)
|
|
568
|
+
void loadFileHistory(alias, store.repoRoot, repoRel, 100)
|
|
569
|
+
.then((rows) => {
|
|
570
|
+
if (cancelled) return
|
|
571
|
+
setFileHistoryRows(rows)
|
|
572
|
+
setFileHistoryLoading(false)
|
|
573
|
+
})
|
|
574
|
+
.catch((error: unknown) => {
|
|
575
|
+
if (cancelled) return
|
|
576
|
+
setFileHistoryError(error instanceof Error ? error.message : String(error))
|
|
577
|
+
setFileHistoryLoading(false)
|
|
578
|
+
})
|
|
579
|
+
return () => { cancelled = true }
|
|
580
|
+
}, [fileHistoryOpen, activeTab?.id, activeTab?.dirty, alias, repoRel, store.repoRoot])
|
|
581
|
+
|
|
582
|
+
useEffect(() => {
|
|
583
|
+
if (!fileHistoryOpen) return
|
|
584
|
+
const onKeyDown = (event: KeyboardEvent): void => {
|
|
585
|
+
if (event.key !== 'Escape') return
|
|
586
|
+
event.preventDefault()
|
|
587
|
+
event.stopPropagation()
|
|
588
|
+
setFileHistoryOpen(false)
|
|
589
|
+
}
|
|
590
|
+
window.addEventListener('keydown', onKeyDown, true)
|
|
591
|
+
return () => window.removeEventListener('keydown', onKeyDown, true)
|
|
592
|
+
}, [fileHistoryOpen])
|
|
593
|
+
|
|
376
594
|
/**
|
|
377
595
|
* The "see the difference" payload of a refused save.
|
|
378
596
|
*
|
|
@@ -465,28 +683,79 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
465
683
|
await store.reloadTab(tab.id)
|
|
466
684
|
}
|
|
467
685
|
|
|
686
|
+
/**
|
|
687
|
+
* The preview inputs as STABLE primitives, not the tab object.
|
|
688
|
+
*
|
|
689
|
+
* `patchTab` builds a fresh tab object for every change (`dirty`, `saving`,
|
|
690
|
+
* `activeHunk`, `reloadNonce`…) while leaving `text` and the render-mode flags
|
|
691
|
+
* alone. Keying the two preview memos below on the tab therefore re-parsed a
|
|
692
|
+
* whole Markdown/HTML document whenever the user saved, jumped to a change or
|
|
693
|
+
* toggled a dot — a parse per action, for text that had not moved. A string's
|
|
694
|
+
* identity is stable while its contents are, so `text` + the flags is the key
|
|
695
|
+
* that actually means "the preview source changed".
|
|
696
|
+
*/
|
|
697
|
+
const previewText = activeTab?.text
|
|
698
|
+
const previewIsHtml = activeTab?.html === true
|
|
699
|
+
const previewIsMarkdown = activeTab?.markdown === true
|
|
700
|
+
const previewVisible = activeTab?.preview === true
|
|
701
|
+
const previewKind: PreviewKind = activeTab?.kind === 'file' ? previewKindOf(activeTab.fullPath) : 'text'
|
|
702
|
+
const bytePreview = isBytePreview(previewKind)
|
|
703
|
+
|
|
704
|
+
const darkScheme = useSyncExternalStore(subscribeColorScheme, isDarkScheme)
|
|
705
|
+
|
|
468
706
|
const htmlDoc = useMemo(() => {
|
|
469
|
-
if (
|
|
470
|
-
|
|
471
|
-
|
|
707
|
+
if (!previewIsHtml) return ''
|
|
708
|
+
const dark = darkScheme
|
|
709
|
+
const csp = [
|
|
710
|
+
"default-src 'none'",
|
|
711
|
+
"style-src 'unsafe-inline'",
|
|
712
|
+
'img-src data: blob:',
|
|
713
|
+
'font-src data:',
|
|
714
|
+
'media-src data: blob:',
|
|
715
|
+
"form-action 'none'",
|
|
716
|
+
"base-uri 'none'",
|
|
717
|
+
].join('; ')
|
|
718
|
+
return [
|
|
719
|
+
'<!doctype html><meta charset="utf-8">',
|
|
720
|
+
`<meta http-equiv="Content-Security-Policy" content="${csp}">`,
|
|
721
|
+
'<style>',
|
|
722
|
+
`:root{color-scheme:${dark ? 'dark' : 'light'}}`,
|
|
723
|
+
`html,body{background:${dark ? '#1e1e1e' : '#ffffff'};color:${dark ? '#d4d4d4' : '#1f1f1f'}}`,
|
|
724
|
+
'body{margin:14px;font:14px/1.65 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;overflow-wrap:break-word}',
|
|
725
|
+
'img,video,canvas{max-width:100%;height:auto}',
|
|
726
|
+
'table{border-collapse:collapse}',
|
|
727
|
+
`td,th{border:1px solid ${dark ? 'rgba(255,255,255,.14)' : 'rgba(0,0,0,.12)'};padding:4px 8px}`,
|
|
728
|
+
'pre{overflow:auto}',
|
|
729
|
+
'</style>',
|
|
730
|
+
previewText ?? '',
|
|
731
|
+
].join('')
|
|
732
|
+
}, [previewIsHtml, previewText, darkScheme])
|
|
733
|
+
|
|
734
|
+
/** Stable labels identity: the platform renderer keys its cache on it. */
|
|
735
|
+
const markdownLabels = useMemo(() => ({
|
|
736
|
+
code: {
|
|
737
|
+
copyLabel: t('preview.copyCode'),
|
|
738
|
+
copiedLabel: t('preview.copied'),
|
|
739
|
+
},
|
|
740
|
+
footnotes: t('preview.footnotes'),
|
|
741
|
+
}), [t])
|
|
472
742
|
|
|
473
743
|
/**
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
* re-parsed the whole document into a fresh element tree on EVERY store
|
|
478
|
-
* publish: this component subscribes to the store, so opening another file,
|
|
479
|
-
* saving, a git refresh or switching a panel all paid for a parse of text
|
|
480
|
-
* that had not changed. `renderMarkdown` is a pure function of the text, and
|
|
481
|
-
* a tab's identity changes when its text does (`updateTab`/`reloadTab` patch
|
|
482
|
-
* the tab), so the tab is what Memo compares — the same key the `htmlDoc`
|
|
483
|
-
* memo above uses. The markdown/preview guards keep the parse from happening
|
|
484
|
-
* at all for a file that is being read in source mode.
|
|
744
|
+
* Markdown preview through the host's platform renderer (the same one the
|
|
745
|
+
* chat uses): GFM tables, code highlighting and footnotes come for free and
|
|
746
|
+
* raw HTML in a remote document is not inserted into the app DOM.
|
|
485
747
|
*/
|
|
486
748
|
const markdownPreview = useMemo(() => {
|
|
487
|
-
if (
|
|
488
|
-
return
|
|
489
|
-
|
|
749
|
+
if (!previewIsMarkdown || !previewVisible || previewText === undefined) return null
|
|
750
|
+
return (
|
|
751
|
+
<div className="rvs-preview-scroll">
|
|
752
|
+
{activeTab?.truncated === true && <div className="rvs-preview-banner">{t('preview.truncated')}</div>}
|
|
753
|
+
<div className="rvs-preview-markdown rvs-markdown" data-preview-path={activeTab?.fullPath ?? ''}>
|
|
754
|
+
<MarkdownText text={previewText} labels={markdownLabels} variant="body" />
|
|
755
|
+
</div>
|
|
756
|
+
</div>
|
|
757
|
+
)
|
|
758
|
+
}, [previewIsMarkdown, previewVisible, previewText, markdownLabels, activeTab?.fullPath, activeTab?.truncated, t])
|
|
490
759
|
|
|
491
760
|
/**
|
|
492
761
|
* The status bar's indent hint, derived from the loaded text.
|
|
@@ -747,11 +1016,114 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
747
1016
|
const tab = saveShortcutTabRef.current
|
|
748
1017
|
// Working-tree diffs are `DiffView`'s own onSave contract; previews have no
|
|
749
1018
|
// buffer at all. `saveActive` would misreport both.
|
|
750
|
-
if (tab === undefined || tab.kind !== 'file' || tab.image || tab.binary) return undefined
|
|
1019
|
+
if (tab === undefined || tab.kind !== 'file' || tab.image || tab.binary || isBytePreview(previewKindOf(tab.fullPath))) return undefined
|
|
751
1020
|
return () => { void saveActiveRef.current() }
|
|
752
1021
|
})
|
|
753
1022
|
}, [props.visible])
|
|
754
1023
|
|
|
1024
|
+
// --- 符号大纲(Ctrl+Shift+O)---------------------------------------------
|
|
1025
|
+
/**
|
|
1026
|
+
* 打开中的大纲。
|
|
1027
|
+
*
|
|
1028
|
+
* 存的是「打开那一刻的实时缓冲区全文」,而不是 `tabId` + 每次渲染再去读 ——
|
|
1029
|
+
* 面板打开期间焦点在筛选框里,缓冲区不可能再变,所以一份快照足够;把全文放进
|
|
1030
|
+
* state 也让 `OutlinePanel` 的 `useMemo` 有稳定输入(不会每帧重扫文件)。
|
|
1031
|
+
*
|
|
1032
|
+
* `tabId` 留在里面是为了自检:换 tab 时旧大纲不能继续挂在屏幕上的新文件上。
|
|
1033
|
+
*/
|
|
1034
|
+
const [outline, setOutline] = useState<{ tabId: string; path: string; text: string } | undefined>(undefined)
|
|
1035
|
+
|
|
1036
|
+
// 换 tab / 重载后旧大纲的行号已经不属于屏幕上的文件了:直接关掉,绝不猜。
|
|
1037
|
+
useEffect(() => {
|
|
1038
|
+
setOutline(undefined)
|
|
1039
|
+
}, [activeTab?.id, activeTab?.reloadNonce])
|
|
1040
|
+
// Hiding this surface (panel switch, rail tab, float window) must take the
|
|
1041
|
+
// portal down with it: the mask is `position: fixed` and would otherwise stay
|
|
1042
|
+
// painted over whatever surface replaced this one.
|
|
1043
|
+
useEffect(() => {
|
|
1044
|
+
if (!props.visible) setOutline(undefined)
|
|
1045
|
+
}, [props.visible])
|
|
1046
|
+
|
|
1047
|
+
const openOutline = useCallback(() => {
|
|
1048
|
+
const tab = saveShortcutTabRef.current
|
|
1049
|
+
if (!outlineAvailable(tab)) return
|
|
1050
|
+
// 实时 buffer 优先:`tab.text` 是加载时的字节,输入从来没有回写进去
|
|
1051
|
+
// (见下方 editor host 的注释)。dirty 文件只有这里能拿到正确内容。
|
|
1052
|
+
setOutline({ tabId: tab.id, path: tab.fullPath, text: editorRef.current?.getContent() ?? tab.text })
|
|
1053
|
+
}, [])
|
|
1054
|
+
const closeOutline = useCallback(() => { setOutline(undefined) }, [])
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* 跳转:复用现有的「选中行区间 + 滚到中央 + 点灯」,1-based 行号。
|
|
1058
|
+
*
|
|
1059
|
+
* 跳转放到下一个 task:浮层卸载时会把焦点还给打开它的按钮(portal 的常规
|
|
1060
|
+
* 做法,见 QuickOpen),先 `revealRange` 再卸载的话,焦点会被那一步抢回去,
|
|
1061
|
+
* 用户接着敲的字就落空了。等卸载稳定后再把焦点交给编辑器。
|
|
1062
|
+
*/
|
|
1063
|
+
const jumpToOutline = useCallback((entry: OutlineEntry) => {
|
|
1064
|
+
setOutline(undefined)
|
|
1065
|
+
window.setTimeout(() => { editorRef.current?.revealRange(entry.line, entry.line) }, 0)
|
|
1066
|
+
}, [])
|
|
1067
|
+
|
|
1068
|
+
// window 监听用 ref 取最新值:effect 只为可见性重装,不随每次渲染重装。
|
|
1069
|
+
const openOutlineRef = useRef(openOutline)
|
|
1070
|
+
openOutlineRef.current = openOutline
|
|
1071
|
+
const closeOutlineRef = useRef(closeOutline)
|
|
1072
|
+
closeOutlineRef.current = closeOutline
|
|
1073
|
+
const outlineOpenRef = useRef(false)
|
|
1074
|
+
outlineOpenRef.current = outline !== undefined
|
|
1075
|
+
|
|
1076
|
+
/**
|
|
1077
|
+
* Ctrl/Cmd+Shift+O:转到符号。
|
|
1078
|
+
*
|
|
1079
|
+
* 用 window 冒泡监听而不是 CodeMirror keymap:和 Ctrl+S 同理 —— 点过 tab 条、
|
|
1080
|
+
* 信息栏或侧栏之后光标已经不在编辑器里,keymap 根本不会触发。只在这个座位可见
|
|
1081
|
+
* 时安装(多个 EditorPane 可能同时挂载,隐藏的那个不该抢键)。
|
|
1082
|
+
*
|
|
1083
|
+
* 不抢别人的键:
|
|
1084
|
+
* - 终端:xterm 已经把 ^O 发给远端 shell(readline 的 operate-and-get-next),
|
|
1085
|
+
* 再开浮层就是一次按键两个动作;
|
|
1086
|
+
* - 其他输入框(聊天输入、对话框输入)与任何模态层(宿主审批、右键菜单)都保留
|
|
1087
|
+
* 这个键;
|
|
1088
|
+
* - 不满足条件时**不** preventDefault:浏览器自己的 Ctrl+Shift+O 在别处仍是它
|
|
1089
|
+
* 的(我们只接管自己确实要处理的那一次按键)。
|
|
1090
|
+
*/
|
|
1091
|
+
useEffect(() => {
|
|
1092
|
+
if (!props.visible) return
|
|
1093
|
+
const onKey = (event: KeyboardEvent): void => {
|
|
1094
|
+
// Another owner (host shortcut, an outer handler) already claimed this
|
|
1095
|
+
// key: bubble phase must yield, same contract as save-shortcut.ts.
|
|
1096
|
+
if (event.defaultPrevented) return
|
|
1097
|
+
const ctrlShiftO = (event.ctrlKey || event.metaKey) && event.shiftKey && !event.altKey
|
|
1098
|
+
const altO = event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey
|
|
1099
|
+
if (!ctrlShiftO && !altO) return
|
|
1100
|
+
if (event.key.toLowerCase() !== 'o') return
|
|
1101
|
+
// 按住不放不该让浮层闪;输入法组字期间这也不是一个命令。
|
|
1102
|
+
if (event.repeat || event.isComposing === true) return
|
|
1103
|
+
// 自己开着:再按一次关闭(与 Ctrl+P 的「再按一次退出」同一习惯)。
|
|
1104
|
+
if (outlineOpenRef.current) {
|
|
1105
|
+
event.preventDefault()
|
|
1106
|
+
closeOutlineRef.current()
|
|
1107
|
+
return
|
|
1108
|
+
}
|
|
1109
|
+
if (isModalLayerOpen()) return
|
|
1110
|
+
const focused = document.activeElement
|
|
1111
|
+
if (focused instanceof HTMLElement && focused.closest('.xterm') !== null) return
|
|
1112
|
+
// CodeMirror 的 `.cm-content` 是 contenteditable,天然在 FOREIGN_TARGET 里:
|
|
1113
|
+
// 只放过**本插件编辑器**里那一份(`.rvs-editor-host` 的子树),宿主自己的
|
|
1114
|
+
// 聊天输入同样是 CodeMirror —— 在别人的编辑器里抢键和在别人的输入框里抢键
|
|
1115
|
+
// 是同一件事。
|
|
1116
|
+
if (focused instanceof HTMLElement
|
|
1117
|
+
&& focused.closest(FOREIGN_TARGET) !== null
|
|
1118
|
+
&& focused.closest('.rvs-editor-host') === null) return
|
|
1119
|
+
if (!outlineAvailable(saveShortcutTabRef.current)) return
|
|
1120
|
+
event.preventDefault()
|
|
1121
|
+
openOutlineRef.current()
|
|
1122
|
+
}
|
|
1123
|
+
window.addEventListener('keydown', onKey)
|
|
1124
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
1125
|
+
}, [props.visible])
|
|
1126
|
+
|
|
755
1127
|
if (tabs.length === 0) {
|
|
756
1128
|
if (center) {
|
|
757
1129
|
return (
|
|
@@ -792,7 +1164,9 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
792
1164
|
const displayPath = activeTab?.fullPath ?? ''
|
|
793
1165
|
const language = isDiff
|
|
794
1166
|
? 'Diff'
|
|
795
|
-
: activeTab?.image === true
|
|
1167
|
+
: activeTab?.image === true
|
|
1168
|
+
? 'Image'
|
|
1169
|
+
: previewKindLabel(previewKind) ?? langLabel(langFromPath(activeTab?.rel ?? ''))
|
|
796
1170
|
const activeImageKey = activeTab === undefined ? undefined : imageCacheKey(activeTab)
|
|
797
1171
|
const imageSrc = activeTab !== undefined && activeTab.image && activeImageKey !== undefined
|
|
798
1172
|
? images[activeImageKey]
|
|
@@ -800,21 +1174,28 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
800
1174
|
const imageFailure = activeTab !== undefined && activeTab.image && activeImageKey !== undefined
|
|
801
1175
|
? imageError[activeImageKey]
|
|
802
1176
|
: undefined
|
|
1177
|
+
const caretBlame = caret === undefined ? undefined : blameRows.get(caret.line)
|
|
803
1178
|
|
|
804
1179
|
return (
|
|
805
|
-
<div className="rvs-pane grow rvs-edge" style={fontStyle}>
|
|
1180
|
+
<div className="rvs-pane grow rvs-edge" style={{ ...(fontStyle ?? {}), position: 'relative' }}>
|
|
806
1181
|
{/* Tab strip: switch / close / dirty dot / diff glyph. Middle-click closes
|
|
807
1182
|
too — the muscle memory shared with VS Code and browsers. */}
|
|
808
1183
|
<div className="rvs-etabs" role="tablist" aria-label={t('editor.tabsLabel')}>
|
|
809
|
-
{tabs.map(tab => {
|
|
1184
|
+
{tabs.map((tab, index) => {
|
|
810
1185
|
const active = tab.id === store.activeTabId
|
|
811
1186
|
const tabIsDiff = tab.kind === 'diff'
|
|
812
1187
|
return (
|
|
813
1188
|
<div
|
|
814
1189
|
key={tab.id}
|
|
815
1190
|
role="tab"
|
|
816
|
-
|
|
1191
|
+
// Roving tabindex (WAI-ARIA tabs): the strip is one Tab stop, so
|
|
1192
|
+
// the panel's other controls are not separated by N tab stops.
|
|
1193
|
+
tabIndex={active ? 0 : -1}
|
|
817
1194
|
aria-selected={active}
|
|
1195
|
+
ref={(element) => {
|
|
1196
|
+
if (element === null) tabElements.current.delete(tab.id)
|
|
1197
|
+
else tabElements.current.set(tab.id, element)
|
|
1198
|
+
}}
|
|
818
1199
|
className={`rvs-etab${active ? ' active' : ''}${tabIsDiff ? ' rvs-etab-diff' : ''}`}
|
|
819
1200
|
title={tabIsDiff ? `${tab.rel}${t('editor.diffSuffix')}` : tab.fullPath}
|
|
820
1201
|
onClick={() => store.activateTab(tab.id)}
|
|
@@ -829,7 +1210,26 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
829
1210
|
if (event.key === 'Enter' || event.key === ' ') {
|
|
830
1211
|
event.preventDefault()
|
|
831
1212
|
store.activateTab(tab.id)
|
|
1213
|
+
return
|
|
832
1214
|
}
|
|
1215
|
+
// WAI-ARIA tabs keyboard model (audit I-16): arrows walk the
|
|
1216
|
+
// strip, Home/End jump to its edges, wrapping at both ends, and
|
|
1217
|
+
// the selection follows focus — the tabs are the cheap file
|
|
1218
|
+
// switcher, so requiring Enter afterwards would only add a step.
|
|
1219
|
+
const step = event.key === 'ArrowRight'
|
|
1220
|
+
? 1
|
|
1221
|
+
: event.key === 'ArrowLeft' ? -1 : undefined
|
|
1222
|
+
if (step === undefined && event.key !== 'Home' && event.key !== 'End') return
|
|
1223
|
+
event.preventDefault()
|
|
1224
|
+
const next = event.key === 'Home'
|
|
1225
|
+
? 0
|
|
1226
|
+
: event.key === 'End'
|
|
1227
|
+
? tabs.length - 1
|
|
1228
|
+
: (index + (step ?? 0) + tabs.length) % tabs.length
|
|
1229
|
+
const target = tabs[next]
|
|
1230
|
+
if (target === undefined) return
|
|
1231
|
+
store.activateTab(target.id)
|
|
1232
|
+
tabElements.current.get(target.id)?.focus()
|
|
833
1233
|
}}
|
|
834
1234
|
>
|
|
835
1235
|
<span className="rvs-etab-glyph">{tabIcon(tab)}</span>
|
|
@@ -870,7 +1270,7 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
870
1270
|
)
|
|
871
1271
|
: <span className="rvs-einfo-path" title={displayPath}>{displayPath}</span>}
|
|
872
1272
|
<span className="rvs-einfo-actions">
|
|
873
|
-
{activeTab.kind === 'file' && (
|
|
1273
|
+
{activeTab.kind === 'file' && hasTextSource(previewKind) && (
|
|
874
1274
|
<Segmented<'preview' | 'source'>
|
|
875
1275
|
value={activeTab.preview ? 'preview' : 'source'}
|
|
876
1276
|
onChange={(next) => store.updateTab(activeTab.id, { preview: next === 'preview' })}
|
|
@@ -895,7 +1295,7 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
895
1295
|
so the stamp says WHICH code is running, and the token count
|
|
896
1296
|
says whether the grammar actually produced colored tokens. */}
|
|
897
1297
|
<span className="rvs-build" title={`dsh-remote-vs build ${__RVS_BUILD__}`}>{__RVS_BUILD__}</span>
|
|
898
|
-
{tokenCount !== undefined && (
|
|
1298
|
+
{tokenCount !== undefined && !bytePreview && (
|
|
899
1299
|
<span className="rvs-build" title={t('editor.tokenCount')}>tok {tokenCount}</span>
|
|
900
1300
|
)}
|
|
901
1301
|
{activeTab.kind === 'file' && (
|
|
@@ -904,19 +1304,34 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
904
1304
|
both the class and the label, while the project's own
|
|
905
1305
|
review checklist forbids nested ternaries. One lookup per
|
|
906
1306
|
concern instead. */}
|
|
907
|
-
|
|
908
|
-
{
|
|
909
|
-
|
|
1307
|
+
{!bytePreview && !activeTab.image && (
|
|
1308
|
+
<span className={`rvs-status ${tabStatusClass(activeTab)}`}>
|
|
1309
|
+
{t(tabStatusKey(activeTab))}
|
|
1310
|
+
</span>
|
|
1311
|
+
)}
|
|
910
1312
|
<IconButton title={t('editor.reloadFile')} onClick={() => { void reloadWithGuard(activeTab) }} disabled={offline || activeTab.loading}>
|
|
911
1313
|
<IconRefresh size={13} />
|
|
912
1314
|
</IconButton>
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
1315
|
+
{!bytePreview && !activeTab.image && (
|
|
1316
|
+
<IconButton
|
|
1317
|
+
title={`${t('editor.save')} (Ctrl+S)`}
|
|
1318
|
+
onClick={() => { void saveActive() }}
|
|
1319
|
+
disabled={offline || activeTab.loading || activeTab.binary || activeTab.truncated || !activeTab.dirty}
|
|
1320
|
+
>
|
|
1321
|
+
<IconSave size={13} />
|
|
1322
|
+
</IconButton>
|
|
1323
|
+
)}
|
|
1324
|
+
{/* 大纲:只对文本文件出现。`≡` 是行内字形(与 blame 的 `B`、
|
|
1325
|
+
浮窗的图标同一套做法),不额外引一个图标组件。 */}
|
|
1326
|
+
{!activeTab.image && !activeTab.binary && !isBytePreview(previewKind) && (
|
|
1327
|
+
<IconButton
|
|
1328
|
+
title={`${t('editor.outline')} (Ctrl+Shift+O)`}
|
|
1329
|
+
onClick={openOutline}
|
|
1330
|
+
disabled={!outlineAvailable(activeTab)}
|
|
1331
|
+
>
|
|
1332
|
+
<span className="rvs-glyph-text">≡</span>
|
|
1333
|
+
</IconButton>
|
|
1334
|
+
)}
|
|
920
1335
|
</>
|
|
921
1336
|
)}
|
|
922
1337
|
{activeTab.kind === 'diff' && (
|
|
@@ -938,7 +1353,7 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
938
1353
|
)}
|
|
939
1354
|
</>
|
|
940
1355
|
)}
|
|
941
|
-
{activeTab.kind === 'file' && !activeTab.image && !activeTab.binary && (
|
|
1356
|
+
{activeTab.kind === 'file' && !activeTab.image && !activeTab.binary && !bytePreview && (
|
|
942
1357
|
<IconButton
|
|
943
1358
|
title={t('editor.wrap')}
|
|
944
1359
|
onClick={() => updateEditorSettings({ wrap: !settings.wrap })}
|
|
@@ -946,11 +1361,37 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
946
1361
|
<IconWrap size={13} />
|
|
947
1362
|
</IconButton>
|
|
948
1363
|
)}
|
|
1364
|
+
{activeTab.kind === 'file' && !activeTab.image && !activeTab.binary && !isBytePreview(previewKind) && repoRel !== '' && (
|
|
1365
|
+
<>
|
|
1366
|
+
<IconButton
|
|
1367
|
+
title={blameError === undefined ? t('editor.blameToggle') : `${t('editor.blameToggle')}: ${blameError}`}
|
|
1368
|
+
className={blameOn ? 'rvs-hbtn-on' : undefined}
|
|
1369
|
+
onClick={toggleBlame}
|
|
1370
|
+
>
|
|
1371
|
+
<span className="rvs-glyph-text">B</span>
|
|
1372
|
+
</IconButton>
|
|
1373
|
+
<IconButton
|
|
1374
|
+
title={t('editor.fileHistory')}
|
|
1375
|
+
className={fileHistoryOpen ? 'rvs-hbtn-on' : undefined}
|
|
1376
|
+
onClick={() => { setFileHistoryOpen(open => !open) }}
|
|
1377
|
+
>
|
|
1378
|
+
<IconDiff size={13} />
|
|
1379
|
+
</IconButton>
|
|
1380
|
+
{blameOn && caretBlame !== undefined && isCommittedBlame(caretBlame.hash) && (
|
|
1381
|
+
<IconButton
|
|
1382
|
+
title={t('editor.blameOpenCaret')}
|
|
1383
|
+
onClick={() => { store.focusCommit(caretBlame.hash) }}
|
|
1384
|
+
>
|
|
1385
|
+
<span className="rvs-glyph-text">↗</span>
|
|
1386
|
+
</IconButton>
|
|
1387
|
+
)}
|
|
1388
|
+
</>
|
|
1389
|
+
)}
|
|
949
1390
|
<span className="rvs-einfo-actions-divider" aria-hidden="true" />
|
|
950
1391
|
{/* The floating window owns its OWN Ctrl+wheel zoom (a property of
|
|
951
1392
|
that window, persisted per window): the shared preference is not
|
|
952
1393
|
what paints there, so these two would look dead inside it. */}
|
|
953
|
-
{variant !== 'float' && (
|
|
1394
|
+
{variant !== 'float' && !bytePreview && !activeTab.image && activeTab.kind !== 'diff' && (
|
|
954
1395
|
<>
|
|
955
1396
|
<IconButton
|
|
956
1397
|
title={t('editor.fontSmaller')}
|
|
@@ -990,6 +1431,65 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
990
1431
|
</span>
|
|
991
1432
|
</div>
|
|
992
1433
|
|
|
1434
|
+
{fileHistoryOpen && activeTab.kind === 'file' && (
|
|
1435
|
+
<div className="rvs-file-history" role="dialog" aria-label={t('editor.fileHistory')}>
|
|
1436
|
+
<div className="rvs-file-history-head">
|
|
1437
|
+
<span className="rvs-file-history-title">{t('editor.fileHistory')}</span>
|
|
1438
|
+
<span className="rvs-file-history-path" title={repoRel}>{repoRel}</span>
|
|
1439
|
+
<button
|
|
1440
|
+
type="button"
|
|
1441
|
+
className="rvs-file-history-close"
|
|
1442
|
+
title={t('common.close')}
|
|
1443
|
+
aria-label={t('common.close')}
|
|
1444
|
+
onClick={() => { setFileHistoryOpen(false) }}
|
|
1445
|
+
>
|
|
1446
|
+
<IconClose size={11} />
|
|
1447
|
+
</button>
|
|
1448
|
+
</div>
|
|
1449
|
+
{fileHistoryLoading && <div className="rvs-file-history-note">{t('common.loading')}</div>}
|
|
1450
|
+
{!fileHistoryLoading && fileHistoryError !== undefined && (
|
|
1451
|
+
<div className="rvs-file-history-note error">{fileHistoryError}</div>
|
|
1452
|
+
)}
|
|
1453
|
+
{!fileHistoryLoading && fileHistoryError === undefined && fileHistoryRows.length === 0 && (
|
|
1454
|
+
<div className="rvs-file-history-note">{t('editor.fileHistoryEmpty')}</div>
|
|
1455
|
+
)}
|
|
1456
|
+
{!fileHistoryLoading && fileHistoryError === undefined && fileHistoryRows.length > 0 && (
|
|
1457
|
+
<div className="rvs-file-history-list">
|
|
1458
|
+
{fileHistoryRows.map(commit => (
|
|
1459
|
+
<button
|
|
1460
|
+
type="button"
|
|
1461
|
+
key={commit.hash}
|
|
1462
|
+
className="rvs-file-history-row"
|
|
1463
|
+
onClick={() => {
|
|
1464
|
+
setFileHistoryOpen(false)
|
|
1465
|
+
store.openCommitFile(commit.hash, commit.path, commit.origPath)
|
|
1466
|
+
}}
|
|
1467
|
+
>
|
|
1468
|
+
<span className="rvs-file-history-hash">{commit.hash.slice(0, 7)}</span>
|
|
1469
|
+
<span className="rvs-file-history-subject" title={commit.subject}>{commit.subject}</span>
|
|
1470
|
+
<span className="rvs-file-history-meta">
|
|
1471
|
+
{commit.author} · {new Date(commit.date * 1000).toLocaleDateString()}
|
|
1472
|
+
</span>
|
|
1473
|
+
</button>
|
|
1474
|
+
))}
|
|
1475
|
+
</div>
|
|
1476
|
+
)}
|
|
1477
|
+
</div>
|
|
1478
|
+
)}
|
|
1479
|
+
|
|
1480
|
+
{/* 大纲浮层:portal 到 <body>,所以放在 JSX 的哪一层都不影响定位;
|
|
1481
|
+
放在信息栏旁边只是让它和触发它的按钮读在一起。`tabId` 判定是最后
|
|
1482
|
+
一道闸:换 tab 之后旧大纲绝不挂在新文件上。 */}
|
|
1483
|
+
{outline !== undefined && outline.tabId === activeTab.id && (
|
|
1484
|
+
<OutlinePanel
|
|
1485
|
+
t={t}
|
|
1486
|
+
path={outline.path}
|
|
1487
|
+
text={outline.text}
|
|
1488
|
+
onPick={jumpToOutline}
|
|
1489
|
+
onClose={closeOutline}
|
|
1490
|
+
/>
|
|
1491
|
+
)}
|
|
1492
|
+
|
|
993
1493
|
<div className="rvs-body" ref={bodyRef}>
|
|
994
1494
|
{/*
|
|
995
1495
|
A REFUSED save: the remote file moved on, so nothing was written.
|
|
@@ -1106,6 +1606,32 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
1106
1606
|
<div>{imageFailure ?? t('common.loading')}</div>
|
|
1107
1607
|
</div>
|
|
1108
1608
|
)}
|
|
1609
|
+
{!activeTab.image && isBytePreview(previewKind) && (
|
|
1610
|
+
<BytePreview
|
|
1611
|
+
alias={alias}
|
|
1612
|
+
path={activeTab.fullPath}
|
|
1613
|
+
sessionId={chatEnabled ? chat.sessionId : undefined}
|
|
1614
|
+
kind={previewKind}
|
|
1615
|
+
revision={activeTab.reloadNonce ?? 0}
|
|
1616
|
+
t={t}
|
|
1617
|
+
/>
|
|
1618
|
+
)}
|
|
1619
|
+
{!activeTab.image && !activeTab.binary && activeTab.preview && previewKind === 'svg' && (
|
|
1620
|
+
<SvgPreview
|
|
1621
|
+
path={activeTab.rel}
|
|
1622
|
+
text={previewText ?? ''}
|
|
1623
|
+
truncated={activeTab.truncated}
|
|
1624
|
+
t={t}
|
|
1625
|
+
/>
|
|
1626
|
+
)}
|
|
1627
|
+
{!activeTab.image && !activeTab.binary && activeTab.preview && previewKind === 'table' && (
|
|
1628
|
+
<TablePreview
|
|
1629
|
+
path={activeTab.rel}
|
|
1630
|
+
text={previewText ?? ''}
|
|
1631
|
+
truncated={activeTab.truncated}
|
|
1632
|
+
t={t}
|
|
1633
|
+
/>
|
|
1634
|
+
)}
|
|
1109
1635
|
{!activeTab.image && activeTab.binary && (
|
|
1110
1636
|
<div className="rvs-editor-notice">
|
|
1111
1637
|
<div className="rvs-editor-notice-title">{t('editor.binaryTitle')}</div>
|
|
@@ -1115,7 +1641,10 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
1115
1641
|
)}
|
|
1116
1642
|
{!activeTab.image && !activeTab.binary && activeTab.markdown && activeTab.preview && markdownPreview}
|
|
1117
1643
|
{!activeTab.image && !activeTab.binary && activeTab.html && activeTab.preview && (
|
|
1118
|
-
<
|
|
1644
|
+
<div className="rvs-preview-frame-wrap">
|
|
1645
|
+
{activeTab.truncated && <div className="rvs-preview-banner">{t('preview.truncated')}</div>}
|
|
1646
|
+
<iframe className="rvs-html-frame" title={activeTab.rel} sandbox="" srcDoc={htmlDoc} />
|
|
1647
|
+
</div>
|
|
1119
1648
|
)}
|
|
1120
1649
|
{/* The editor host stays MOUNTED and is hidden with CSS in
|
|
1121
1650
|
preview mode. Unmounting it (the old behaviour) rebuilt the
|
|
@@ -1126,9 +1655,9 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
1126
1655
|
caret across preview/source switches, and sibling surfaces
|
|
1127
1656
|
(the image/HTML previews) end up in the same DOM positions
|
|
1128
1657
|
as before, so their own remount behaviour is unchanged. */}
|
|
1129
|
-
{!activeTab.image && !activeTab.binary && (
|
|
1658
|
+
{!activeTab.image && !activeTab.binary && !isBytePreview(previewKind) && (
|
|
1130
1659
|
<div
|
|
1131
|
-
className={`rvs-editor-host${activeTab.preview && (
|
|
1660
|
+
className={`rvs-editor-host${activeTab.preview && hasTextSource(previewKind) ? ' rvs-hidden' : ''}`}
|
|
1132
1661
|
>
|
|
1133
1662
|
{activeTab.truncated && <div className="rvs-banner warn">{t('editor.truncated')}</div>}
|
|
1134
1663
|
<CodeEditor
|
|
@@ -1149,6 +1678,9 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
1149
1678
|
{...(activeTab.line === undefined ? {} : { revealLine: activeTab.line })}
|
|
1150
1679
|
{...(activeTab.lineNonce === undefined ? {} : { revealNonce: activeTab.lineNonce })}
|
|
1151
1680
|
{...(activeTab.changeSet === undefined ? {} : { changeSet: activeTab.changeSet })}
|
|
1681
|
+
blame={blameOn ? blameRows : undefined}
|
|
1682
|
+
onOpenBlame={(entry) => { store.focusCommit(entry.hash) }}
|
|
1683
|
+
onViewport={onEditorViewport}
|
|
1152
1684
|
{...(activeTab.revealHunkLine === undefined ? {} : { revealHunkLine: activeTab.revealHunkLine })}
|
|
1153
1685
|
{...(activeTab.revealHunkNonce === undefined ? {} : { revealHunkNonce: activeTab.revealHunkNonce })}
|
|
1154
1686
|
{...(editorViewStateOf(activeTab.id) === undefined
|