dsh-remote-vs 0.25.0 → 0.26.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 +11 -7
- package/README.md +10 -7
- package/THIRD-PARTY-NOTICES.md +188 -0
- package/lib/client.js +6512 -79961
- package/lib/index.js +1283 -992
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/client/CodeEditor.d.ts +8 -0
- package/lib/types/client/RemoteExplorer.d.ts +53 -0
- package/lib/types/client/api.d.ts +37 -2
- package/lib/types/client/changes/review-state.d.ts +19 -0
- package/lib/types/client/connection.d.ts +16 -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 +31 -3
- package/lib/types/client/store.d.ts +53 -0
- package/lib/types/client/vsc/FindWidget.d.ts +6 -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 -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/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/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 +2 -1
- package/src/client/CodeEditor.tsx +151 -8
- package/src/client/DirectoryFlow.tsx +16 -0
- package/src/client/DoctorPanel.tsx +70 -7
- package/src/client/EditorPane.tsx +63 -14
- package/src/client/HostsView.tsx +12 -3
- 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 +106 -13
- 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 +82 -8
- 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 +23 -2
- package/src/client/scm/RepoPicker.tsx +1 -1
- package/src/client/scm/ScmPanel.tsx +391 -87
- package/src/client/scm/actions.ts +95 -12
- package/src/client/store.tsx +372 -9
- package/src/client/ui.tsx +4 -0
- package/src/client/vsc/FindWidget.tsx +24 -9
- 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 +26 -9
- package/src/client/vsc/save-shortcut.ts +47 -1
- package/src/client/vsc/terminal-theme.ts +44 -18
- package/src/client/vsc/vsc.css +411 -153
- package/src/forward.ts +47 -9
- package/src/fs-ops.ts +124 -4
- package/src/git-ops.ts +20 -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/routes.ts +212 -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
package/src/client/ui.tsx
CHANGED
|
@@ -107,6 +107,10 @@ export function Spinner(props: { size?: number }): ReactNode {
|
|
|
107
107
|
export function Notice(props: { kind: 'info' | 'error'; children: ReactNode }): ReactNode {
|
|
108
108
|
return (
|
|
109
109
|
<div
|
|
110
|
+
// A banner is how a remote failure reaches the user (a refused write, a
|
|
111
|
+
// dead link): announce it. An error asserts; informational copy is polite
|
|
112
|
+
// so it does not interrupt what the user is typing.
|
|
113
|
+
role={props.kind === 'error' ? 'alert' : 'status'}
|
|
110
114
|
style={{
|
|
111
115
|
margin: '8px 0',
|
|
112
116
|
padding: '6px 10px',
|
|
@@ -250,6 +250,12 @@ export function stepFind(view: EditorView, forward: boolean, state?: FindState):
|
|
|
250
250
|
export function FindWidget(props: {
|
|
251
251
|
view: EditorView | undefined
|
|
252
252
|
open: boolean
|
|
253
|
+
/**
|
|
254
|
+
* The page's dictionary translator. Required, not defaulted: the widget has
|
|
255
|
+
* no language of its own, and a silent Chinese fallback is exactly the
|
|
256
|
+
* hardcoded copy this prop replaced.
|
|
257
|
+
*/
|
|
258
|
+
t: (key: string) => string
|
|
253
259
|
/** A selection carried in by Ctrl+F (`id` bumps to re-trigger). */
|
|
254
260
|
seed: { text: string; id: number }
|
|
255
261
|
/**
|
|
@@ -419,11 +425,21 @@ export function FindWidget(props: {
|
|
|
419
425
|
<input
|
|
420
426
|
ref={inputRef}
|
|
421
427
|
className="rvs-find-input"
|
|
422
|
-
placeholder=
|
|
428
|
+
placeholder={props.t('find.placeholder')}
|
|
423
429
|
value={state.query}
|
|
424
430
|
spellCheck={false}
|
|
425
431
|
onChange={(e) => patch({ query: e.target.value })}
|
|
426
432
|
onKeyDown={(e) => {
|
|
433
|
+
// An IME candidate window uses Enter to pick a character and Escape
|
|
434
|
+
// to drop it. Acting on them would seek to a half-composed query or
|
|
435
|
+
// close the widget mid-composition, and preventDefault here can
|
|
436
|
+
// swallow the candidate commit. Stopping propagation first keeps the
|
|
437
|
+
// host's editor/tree shortcuts out of the composing keystroke.
|
|
438
|
+
// `isComposing` is the platform-agnostic signal; `keyCode === 229` is
|
|
439
|
+
// the fallback for engines that dispatch compositionend before this
|
|
440
|
+
// keydown (Chrome), so one Enter cannot seek twice.
|
|
441
|
+
e.stopPropagation()
|
|
442
|
+
if (e.nativeEvent.isComposing === true || e.keyCode === 229) return
|
|
427
443
|
if (e.key === 'Enter') {
|
|
428
444
|
e.preventDefault()
|
|
429
445
|
seek(!e.shiftKey)
|
|
@@ -435,30 +451,29 @@ export function FindWidget(props: {
|
|
|
435
451
|
e.preventDefault()
|
|
436
452
|
e.currentTarget.select()
|
|
437
453
|
}
|
|
438
|
-
e.stopPropagation()
|
|
439
454
|
}}
|
|
440
455
|
/>
|
|
441
456
|
<span className="rvs-toggles">
|
|
442
|
-
{toggle('caseSensitive', '
|
|
443
|
-
{toggle('wholeWord', '
|
|
444
|
-
{toggle('regexp', '
|
|
457
|
+
{toggle('caseSensitive', props.t('find.caseSensitive'))}
|
|
458
|
+
{toggle('wholeWord', props.t('find.wholeWord'))}
|
|
459
|
+
{toggle('regexp', props.t('find.regexp'))}
|
|
445
460
|
</span>
|
|
446
461
|
<span className={count.total === 0 ? 'rvs-find-count none' : 'rvs-find-count'}>
|
|
447
|
-
{state.query === '' ? '' : count.total === 0 ? '
|
|
462
|
+
{state.query === '' ? '' : count.total === 0 ? props.t('find.noResults') : `${count.index || 1}/${count.total}`}
|
|
448
463
|
</span>
|
|
449
464
|
<IconButton
|
|
450
|
-
title=
|
|
465
|
+
title={props.t('find.prev')}
|
|
451
466
|
onClick={() => seek(false)}
|
|
452
467
|
>
|
|
453
468
|
<span style={{ fontSize: 13 }}>↑</span>
|
|
454
469
|
</IconButton>
|
|
455
470
|
<IconButton
|
|
456
|
-
title=
|
|
471
|
+
title={props.t('find.next')}
|
|
457
472
|
onClick={() => seek(true)}
|
|
458
473
|
>
|
|
459
474
|
<span style={{ fontSize: 13 }}>↓</span>
|
|
460
475
|
</IconButton>
|
|
461
|
-
<IconButton title=
|
|
476
|
+
<IconButton title={props.t('find.close')} onClick={props.onClose}>
|
|
462
477
|
<IconClose size={11} />
|
|
463
478
|
</IconButton>
|
|
464
479
|
</div>
|
|
@@ -10,7 +10,15 @@
|
|
|
10
10
|
* Read-only: it only calls `fileOp.list` on the remote. The remote path is the
|
|
11
11
|
* Host's own business — no second validation layer here.
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
useEffect,
|
|
15
|
+
useMemo,
|
|
16
|
+
useRef,
|
|
17
|
+
useState,
|
|
18
|
+
type KeyboardEvent as ReactKeyboardEvent,
|
|
19
|
+
type MouseEvent as ReactMouseEvent,
|
|
20
|
+
type ReactNode,
|
|
21
|
+
} from 'react'
|
|
14
22
|
import { api } from '../api.ts'
|
|
15
23
|
import type { RemoteFileEntry } from '../../protocol.ts'
|
|
16
24
|
|
|
@@ -73,6 +81,14 @@ export function Breadcrumb(props: BreadcrumbProps): ReactNode {
|
|
|
73
81
|
const [error, setError] = useState<string | undefined>(undefined)
|
|
74
82
|
/** Load token: two quick segment clicks must only let the last answer land. */
|
|
75
83
|
const loadSeq = useRef(0)
|
|
84
|
+
/** The menu box, so opening it can hand over the keyboard. */
|
|
85
|
+
const menuRef = useRef<HTMLDivElement>(null)
|
|
86
|
+
/** The crumb that opened the menu; focus goes back here on an Esc dismissal. */
|
|
87
|
+
const openerRef = useRef<HTMLElement | null>(null)
|
|
88
|
+
/** True when the last close was Esc (only then is focus handed back). */
|
|
89
|
+
const restoreFocus = useRef(false)
|
|
90
|
+
/** The first item is focused once per opening, not on every directory reload. */
|
|
91
|
+
const firstItemFocused = useRef(false)
|
|
76
92
|
|
|
77
93
|
const t = props.t
|
|
78
94
|
const root = props.root.replace(/\/+$/, '')
|
|
@@ -138,7 +154,10 @@ export function Breadcrumb(props: BreadcrumbProps): ReactNode {
|
|
|
138
154
|
const onKeyDown = (event: KeyboardEvent): void => {
|
|
139
155
|
// During IME composition Esc cancels the candidate, not the menu.
|
|
140
156
|
if (event.isComposing) return
|
|
141
|
-
if (event.key === 'Escape')
|
|
157
|
+
if (event.key === 'Escape') {
|
|
158
|
+
restoreFocus.current = true
|
|
159
|
+
setMenu(undefined)
|
|
160
|
+
}
|
|
142
161
|
}
|
|
143
162
|
document.addEventListener('mousedown', onMouseDown, true)
|
|
144
163
|
document.addEventListener('keydown', onKeyDown, true)
|
|
@@ -153,6 +172,40 @@ export function Breadcrumb(props: BreadcrumbProps): ReactNode {
|
|
|
153
172
|
setMenu(undefined)
|
|
154
173
|
}, [props.path])
|
|
155
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Menu keyboard model (audit I-12): the menu declared `role="menu"` but had no
|
|
177
|
+
* arrow keys and no initial focus, so a screen reader announced a menu whose
|
|
178
|
+
* items could only be reached with Tab. Opening hands the keyboard to the menu
|
|
179
|
+
* box, and the first item takes it as soon as the (async) listing lands.
|
|
180
|
+
*/
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
if (menu === undefined) return
|
|
183
|
+
firstItemFocused.current = false
|
|
184
|
+
menuRef.current?.focus()
|
|
185
|
+
}, [menu])
|
|
186
|
+
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
if (menu === undefined || loading || error !== undefined || entries.length === 0) return
|
|
189
|
+
if (firstItemFocused.current) return
|
|
190
|
+
const box = menuRef.current
|
|
191
|
+
if (box === null) return
|
|
192
|
+
const active = document.activeElement
|
|
193
|
+
// Never pull focus away from a control the user already reached.
|
|
194
|
+
if (active !== box && box.contains(active)) return
|
|
195
|
+
firstItemFocused.current = true
|
|
196
|
+
box.querySelector<HTMLElement>('.rvs-crumb-menu-item')?.focus()
|
|
197
|
+
}, [menu, loading, error, entries])
|
|
198
|
+
|
|
199
|
+
// Esc is a dismissal, so it gives the keyboard back to the crumb that opened
|
|
200
|
+
// the menu instead of dropping focus on <body>. An outside click keeps focus
|
|
201
|
+
// where the user clicked, and picking an entry moves it on by itself.
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
if (menu !== undefined || !restoreFocus.current) return
|
|
204
|
+
restoreFocus.current = false
|
|
205
|
+
const opener = openerRef.current
|
|
206
|
+
if (opener !== null && document.body.contains(opener)) opener.focus()
|
|
207
|
+
}, [menu])
|
|
208
|
+
|
|
156
209
|
if (!underRoot) {
|
|
157
210
|
return (
|
|
158
211
|
<nav className="rvs-breadcrumb" aria-label={tr(t, 'editor.crumbLabel', '文件路径')}>
|
|
@@ -163,6 +216,7 @@ export function Breadcrumb(props: BreadcrumbProps): ReactNode {
|
|
|
163
216
|
|
|
164
217
|
/** Click a segment: a directory lists itself; the file lists its parent. */
|
|
165
218
|
const clickCrumb = (crumb: Crumb, index: number, event: ReactMouseEvent<HTMLButtonElement>): void => {
|
|
219
|
+
openerRef.current = event.currentTarget
|
|
166
220
|
const isFile = index === crumbs.length - 1
|
|
167
221
|
const dir = isFile ? crumb.path.slice(0, Math.max(0, crumb.path.lastIndexOf('/'))) : crumb.path
|
|
168
222
|
openMenu(dir === '' ? '/' : dir, Math.max(0, event.currentTarget.offsetLeft))
|
|
@@ -175,6 +229,30 @@ export function Breadcrumb(props: BreadcrumbProps): ReactNode {
|
|
|
175
229
|
return parts.length === 0 ? undefined : `/${parts.join('/')}`
|
|
176
230
|
}
|
|
177
231
|
|
|
232
|
+
/** The enabled entries of the open menu, in DOM order. */
|
|
233
|
+
const menuItems = (): HTMLElement[] => {
|
|
234
|
+
const box = menuRef.current
|
|
235
|
+
if (box === null) return []
|
|
236
|
+
return Array.from(box.querySelectorAll<HTMLElement>('.rvs-crumb-menu-item'))
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** ↑/↓/Home/End between entries (Enter/Space is the button's own activation). */
|
|
240
|
+
const onMenuKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>): void => {
|
|
241
|
+
if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp' && event.key !== 'Home' && event.key !== 'End') return
|
|
242
|
+
const items = menuItems()
|
|
243
|
+
if (items.length === 0) return
|
|
244
|
+
event.preventDefault()
|
|
245
|
+
const at = items.indexOf(document.activeElement as HTMLElement)
|
|
246
|
+
const next = event.key === 'Home'
|
|
247
|
+
? 0
|
|
248
|
+
: event.key === 'End'
|
|
249
|
+
? items.length - 1
|
|
250
|
+
: event.key === 'ArrowDown'
|
|
251
|
+
? (at + 1) % items.length
|
|
252
|
+
: (at <= 0 ? items.length - 1 : at - 1)
|
|
253
|
+
items[next]?.focus()
|
|
254
|
+
}
|
|
255
|
+
|
|
178
256
|
return (
|
|
179
257
|
<nav className="rvs-breadcrumb" ref={navRef} aria-label={tr(t, 'editor.crumbLabel', '文件路径')}>
|
|
180
258
|
{crumbs.map((crumb, index) => {
|
|
@@ -199,7 +277,17 @@ export function Breadcrumb(props: BreadcrumbProps): ReactNode {
|
|
|
199
277
|
})}
|
|
200
278
|
|
|
201
279
|
{menu !== undefined && (
|
|
202
|
-
<div
|
|
280
|
+
<div
|
|
281
|
+
ref={menuRef}
|
|
282
|
+
className="rvs-crumb-menu"
|
|
283
|
+
role="menu"
|
|
284
|
+
// A non-modal picker: Ctrl+S stays live while it is open (the editor is
|
|
285
|
+
// still the surface in use). `isModalLayerOpen()` reads this marker.
|
|
286
|
+
data-rvs-nonmodal=""
|
|
287
|
+
tabIndex={-1}
|
|
288
|
+
onKeyDown={onMenuKeyDown}
|
|
289
|
+
style={{ left: menu.left }}
|
|
290
|
+
>
|
|
203
291
|
<div className="rvs-crumb-menu-head">
|
|
204
292
|
<button
|
|
205
293
|
type="button"
|
|
@@ -42,6 +42,14 @@ import {
|
|
|
42
42
|
/** 改动点的三种形态。 */
|
|
43
43
|
export type ChangeKind = 'add' | 'mod' | 'del'
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* 字典翻译函数,由调用方传入(`CodeEditor` 把页面语言解析好的那个 `t` 交下来)。
|
|
47
|
+
*
|
|
48
|
+
* 本模块自己不选语言:同样的 `t` 与同样的数据永远画出同样的 DOM,纯函数性得以
|
|
49
|
+
* 保持;语言变了由调用方重装扩展(`changeMarksExtension(t)`)。
|
|
50
|
+
*/
|
|
51
|
+
export type Translate = (key: string) => string
|
|
52
|
+
|
|
45
53
|
/**
|
|
46
54
|
* 新增/修改行里"真正变化的字符区间":相对所属行的列偏移,**0-based、半开区间**。
|
|
47
55
|
*
|
|
@@ -158,7 +166,6 @@ const KIND_PRIORITY: Record<ChangeKind, number> = { add: 0, mod: 1, del: 2 }
|
|
|
158
166
|
|
|
159
167
|
/** Gutter 符号与说明(三种形态靠符号 + 颜色双重区分)。 */
|
|
160
168
|
const GLYPH: Record<ChangeKind, string> = { add: '+', mod: '●', del: '−' }
|
|
161
|
-
const LABEL: Record<ChangeKind, string> = { add: '新增行', mod: '修改行', del: '删除行' }
|
|
162
169
|
|
|
163
170
|
/** 空标记集。构造一次,避免每次清空都新建一个 RangeSet。 */
|
|
164
171
|
const NO_MARKERS = new RangeSetBuilder<GutterMarker>().finish()
|
|
@@ -184,12 +191,6 @@ function lineDecoration(kind: ChangeKind): Decoration {
|
|
|
184
191
|
*/
|
|
185
192
|
const WORD_ADD = Decoration.mark({ class: 'rvs-change-word-add' })
|
|
186
193
|
|
|
187
|
-
/** 删除 chip 的悬浮说明。与 gutter 的 `LABEL` 一样,是编辑器侧的固定文案。 */
|
|
188
|
-
const CHIP_TITLE = '已删除的内容'
|
|
189
|
-
|
|
190
|
-
/** 整块删除那种胶囊的悬浮说明(后面跟行数)。 */
|
|
191
|
-
const BLOCK_CHIP_TITLE = '已删除的整块内容'
|
|
192
|
-
|
|
193
194
|
/**
|
|
194
195
|
* 被删内容的零宽 widget。
|
|
195
196
|
*
|
|
@@ -201,12 +202,22 @@ class RemovedChipWidget extends WidgetType {
|
|
|
201
202
|
private readonly text: string
|
|
202
203
|
private readonly truncated: boolean
|
|
203
204
|
private readonly count: number
|
|
205
|
+
/**
|
|
206
|
+
* 文案在构造时按调用方的 `t` 解析好,并参与 `eq`:语言变了而 DOM 被复用,
|
|
207
|
+
* tooltip 就会停在旧语言上。
|
|
208
|
+
*/
|
|
209
|
+
private readonly chipTitle: string
|
|
210
|
+
private readonly blockTitle: string
|
|
211
|
+
private readonly removedLines: string
|
|
204
212
|
|
|
205
|
-
constructor(text: string, truncated: boolean, count
|
|
213
|
+
constructor(text: string, truncated: boolean, count: number, t: Translate) {
|
|
206
214
|
super()
|
|
207
215
|
this.text = text
|
|
208
216
|
this.truncated = truncated
|
|
209
217
|
this.count = count
|
|
218
|
+
this.chipTitle = t('changes.deletedChip')
|
|
219
|
+
this.blockTitle = t('changes.deletedBlock')
|
|
220
|
+
this.removedLines = t('changes.deletedLines')
|
|
210
221
|
}
|
|
211
222
|
|
|
212
223
|
eq(other: WidgetType): boolean {
|
|
@@ -214,6 +225,9 @@ class RemovedChipWidget extends WidgetType {
|
|
|
214
225
|
&& other.text === this.text
|
|
215
226
|
&& other.truncated === this.truncated
|
|
216
227
|
&& other.count === this.count
|
|
228
|
+
&& other.chipTitle === this.chipTitle
|
|
229
|
+
&& other.blockTitle === this.blockTitle
|
|
230
|
+
&& other.removedLines === this.removedLines
|
|
217
231
|
}
|
|
218
232
|
|
|
219
233
|
toDOM(): HTMLElement {
|
|
@@ -228,8 +242,12 @@ class RemovedChipWidget extends WidgetType {
|
|
|
228
242
|
*/
|
|
229
243
|
const block = this.count > 1
|
|
230
244
|
chip.className = block ? 'rvs-change-word-del rvs-change-block-del' : 'rvs-change-word-del'
|
|
231
|
-
chip.textContent = block
|
|
232
|
-
|
|
245
|
+
chip.textContent = block
|
|
246
|
+
? this.removedLines.replace('{count}', String(this.count))
|
|
247
|
+
: (this.truncated ? `${this.text}…` : this.text)
|
|
248
|
+
chip.title = block
|
|
249
|
+
? `${this.blockTitle.replace('{count}', String(this.count))}\n${this.text}`
|
|
250
|
+
: this.chipTitle
|
|
233
251
|
chip.setAttribute('aria-label', chip.title)
|
|
234
252
|
return chip
|
|
235
253
|
}
|
|
@@ -240,8 +258,8 @@ class RemovedChipWidget extends WidgetType {
|
|
|
240
258
|
* 区间之前,`RangeSetBuilder` 只接受按 `from` + `startSide` 升序的输入(行装饰
|
|
241
259
|
* `-2e8`、chip `-1e8`、字符区间 `-1`)。
|
|
242
260
|
*/
|
|
243
|
-
function chipDecoration(chip: RemovedChip): Decoration {
|
|
244
|
-
return Decoration.widget({ widget: new RemovedChipWidget(chip.text, chip.truncated, chip.count ?? 0), side: -1 })
|
|
261
|
+
function chipDecoration(chip: RemovedChip, t: Translate): Decoration {
|
|
262
|
+
return Decoration.widget({ widget: new RemovedChipWidget(chip.text, chip.truncated, chip.count ?? 0, t), side: -1 })
|
|
245
263
|
}
|
|
246
264
|
|
|
247
265
|
/** 一行的行内片段:新增字符区间 + 删除 chip。 */
|
|
@@ -312,11 +330,14 @@ function inlineIndexOf(set: ChangeSet | null, doc: Text): Map<number, LineInline
|
|
|
312
330
|
class KindMarker extends GutterMarker {
|
|
313
331
|
readonly kind: ChangeKind
|
|
314
332
|
readonly elementClass: string
|
|
333
|
+
/** 已解析的说明(title 与 aria-label 共用),由工厂按 `t` 传进来。 */
|
|
334
|
+
private readonly label: string
|
|
315
335
|
|
|
316
|
-
constructor(kind: ChangeKind) {
|
|
336
|
+
constructor(kind: ChangeKind, label: string) {
|
|
317
337
|
super()
|
|
318
338
|
this.kind = kind
|
|
319
339
|
this.elementClass = `rvs-change-gutter-${kind}`
|
|
340
|
+
this.label = label
|
|
320
341
|
}
|
|
321
342
|
|
|
322
343
|
eq(other: GutterMarker): boolean {
|
|
@@ -327,17 +348,23 @@ class KindMarker extends GutterMarker {
|
|
|
327
348
|
const span = document.createElement('span')
|
|
328
349
|
span.className = `rvs-change-mark rvs-change-mark-${this.kind}`
|
|
329
350
|
span.textContent = GLYPH[this.kind]
|
|
330
|
-
span.title =
|
|
331
|
-
span.setAttribute('aria-label',
|
|
351
|
+
span.title = this.label
|
|
352
|
+
span.setAttribute('aria-label', this.label)
|
|
332
353
|
return span
|
|
333
354
|
}
|
|
334
355
|
}
|
|
335
356
|
|
|
336
|
-
/**
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
357
|
+
/**
|
|
358
|
+
* 三种 kind 的 gutter 标记(`eq` 让相邻同 kind 的行合并成一条 gutter 色条)。
|
|
359
|
+
*
|
|
360
|
+
* 每次装扩展重建一份:文案按调用方的 `t` 解析,不能再做成模块级常量。
|
|
361
|
+
*/
|
|
362
|
+
function markersFor(t: Translate): Record<ChangeKind, GutterMarker> {
|
|
363
|
+
return {
|
|
364
|
+
add: new KindMarker('add', t('changes.markAdd')),
|
|
365
|
+
mod: new KindMarker('mod', t('changes.markMod')),
|
|
366
|
+
del: new KindMarker('del', t('changes.markDel')),
|
|
367
|
+
}
|
|
341
368
|
}
|
|
342
369
|
|
|
343
370
|
/**
|
|
@@ -485,9 +512,12 @@ function firstSpanFrom(spans: readonly Span[], line: number): number {
|
|
|
485
512
|
class ChangeMarkHighlighter {
|
|
486
513
|
decorations: DecorationSet = Decoration.none
|
|
487
514
|
private readonly view: EditorView
|
|
515
|
+
/** 解析标记文案的翻译函数;由 `changeMarkPlugin(t)` 装进来。 */
|
|
516
|
+
private readonly t: Translate
|
|
488
517
|
|
|
489
|
-
constructor(view: EditorView) {
|
|
518
|
+
constructor(view: EditorView, t: Translate) {
|
|
490
519
|
this.view = view
|
|
520
|
+
this.t = t
|
|
491
521
|
this.rebuild()
|
|
492
522
|
}
|
|
493
523
|
|
|
@@ -527,7 +557,7 @@ class ChangeMarkHighlighter {
|
|
|
527
557
|
// chip 的 `at` 是列偏移,越过行尾的(基线变了)夹到行尾,绝不越界。
|
|
528
558
|
for (const chip of detail.chips) {
|
|
529
559
|
const at = line.from + Math.min(chip.at, line.length)
|
|
530
|
-
pieces.push({ from: at, to: at, decoration: chipDecoration(chip) })
|
|
560
|
+
pieces.push({ from: at, to: at, decoration: chipDecoration(chip, this.t) })
|
|
531
561
|
}
|
|
532
562
|
for (const word of detail.ranges) {
|
|
533
563
|
const from = line.from + Math.min(word.from, line.length)
|
|
@@ -549,13 +579,20 @@ class ChangeMarkHighlighter {
|
|
|
549
579
|
/**
|
|
550
580
|
* 视口内行装饰的 ViewPlugin。
|
|
551
581
|
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
582
|
+
* 用工厂而不是模块级常量:标记与 chip 的文案由调用方的 `t` 解析。仍然导出是为了
|
|
583
|
+
* 让自检脚本能直接读 `view.plugin(changeMarkPlugin(t)).decorations.size` ——
|
|
584
|
+
* "只装饰视口内的行"这件事在 DOM 上看不出来(CodeMirror 本来就让 DOM 只保留可见
|
|
585
|
+
* 行),只有读这份 RangeSet 的条数才有判别力。
|
|
555
586
|
*/
|
|
556
|
-
export
|
|
557
|
-
|
|
558
|
-
|
|
587
|
+
export function changeMarkPlugin(t: Translate): ViewPlugin<ChangeMarkHighlighter> {
|
|
588
|
+
return ViewPlugin.fromClass(class extends ChangeMarkHighlighter {
|
|
589
|
+
constructor(view: EditorView) {
|
|
590
|
+
super(view, t)
|
|
591
|
+
}
|
|
592
|
+
}, {
|
|
593
|
+
decorations: value => value.decorations,
|
|
594
|
+
})
|
|
595
|
+
}
|
|
559
596
|
|
|
560
597
|
/**
|
|
561
598
|
* 视口内的 gutter 标记,带一条缓存。
|
|
@@ -563,15 +600,24 @@ export const changeMarkPlugin = ViewPlugin.fromClass(ChangeMarkHighlighter, {
|
|
|
563
600
|
* gutter 的 `markers` 回调在**每一次**视图更新都会跑(选中、滚动、输入都算),
|
|
564
601
|
* 而且它比较的是"视口内那一段"的 RangeSet。所以这里按"数据 + 视口"做单条缓存:
|
|
565
602
|
* 没有新数据、没滚动时直接返回已有结果,滚动时只重建视口那几十行。
|
|
603
|
+
*
|
|
604
|
+
* 缓存键里带上标记实例集合(`owner`):每个编辑器按自己的 `t` 建一份标记,语言
|
|
605
|
+
* 不同的两个编辑器同时挂载时不能互相复用。
|
|
566
606
|
*/
|
|
567
|
-
let gutterCache: {
|
|
607
|
+
let gutterCache: {
|
|
608
|
+
state: MarksState
|
|
609
|
+
from: number
|
|
610
|
+
to: number
|
|
611
|
+
owner: Record<ChangeKind, GutterMarker>
|
|
612
|
+
markers: RangeSet<GutterMarker>
|
|
613
|
+
} | undefined
|
|
568
614
|
|
|
569
|
-
function viewportMarkers(view: EditorView): RangeSet<GutterMarker> {
|
|
615
|
+
function viewportMarkers(view: EditorView, owner: Record<ChangeKind, GutterMarker>): RangeSet<GutterMarker> {
|
|
570
616
|
const marks = view.state.field(marksField, false) ?? EMPTY_STATE
|
|
571
617
|
const from = view.viewport.from
|
|
572
618
|
const to = view.viewport.to
|
|
573
619
|
const cached = gutterCache
|
|
574
|
-
if (cached !== undefined && cached.state === marks && cached.from === from && cached.to === to) {
|
|
620
|
+
if (cached !== undefined && cached.state === marks && cached.from === from && cached.to === to && cached.owner === owner) {
|
|
575
621
|
return cached.markers
|
|
576
622
|
}
|
|
577
623
|
let markers = NO_MARKERS
|
|
@@ -585,7 +631,7 @@ function viewportMarkers(view: EditorView): RangeSet<GutterMarker> {
|
|
|
585
631
|
if (span.first > lastLine) break
|
|
586
632
|
const start = Math.max(span.first, firstLine)
|
|
587
633
|
const end = Math.min(span.last, lastLine)
|
|
588
|
-
const marker =
|
|
634
|
+
const marker = owner[span.kind]
|
|
589
635
|
// 每一行必须是**独立**的标记区间:gutter 只在 `marker.from === line.from`
|
|
590
636
|
// 时才把该标记放进这一行(view 的 `advanceCursor`),一个跨多行的区间只会
|
|
591
637
|
// 出现在第一行上。
|
|
@@ -596,7 +642,7 @@ function viewportMarkers(view: EditorView): RangeSet<GutterMarker> {
|
|
|
596
642
|
}
|
|
597
643
|
markers = builder.finish()
|
|
598
644
|
}
|
|
599
|
-
gutterCache = { state: marks, from, to, markers }
|
|
645
|
+
gutterCache = { state: marks, from, to, owner, markers }
|
|
600
646
|
return markers
|
|
601
647
|
}
|
|
602
648
|
|
|
@@ -606,14 +652,17 @@ function viewportMarkers(view: EditorView): RangeSet<GutterMarker> {
|
|
|
606
652
|
* `CodeEditor` 只在调用方真的传了 `changeSet` 时把它装进编辑器(Compartment),
|
|
607
653
|
* 没传时不装 —— 这样"没有会话改动"的文件连一条 gutter 都不会多出来。
|
|
608
654
|
*/
|
|
609
|
-
export
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
655
|
+
export function changeMarksExtension(t: Translate): Extension {
|
|
656
|
+
const markers = markersFor(t)
|
|
657
|
+
return [
|
|
658
|
+
marksField,
|
|
659
|
+
changeStaleField,
|
|
660
|
+
gutter({
|
|
661
|
+
class: 'rvs-change-gutter',
|
|
662
|
+
markers: view => viewportMarkers(view, markers),
|
|
663
|
+
initialSpacer: () => SPACER,
|
|
664
|
+
lineMarkerChange: update => update.startState.field(marksField, false) !== update.state.field(marksField, false),
|
|
665
|
+
}),
|
|
666
|
+
changeMarkPlugin(t),
|
|
667
|
+
]
|
|
668
|
+
}
|
|
@@ -24,7 +24,15 @@ import { defaultKeymap, historyKeymap, indentWithTab } from '@codemirror/command
|
|
|
24
24
|
|
|
25
25
|
/** The editor actions the key bindings dispatch into. */
|
|
26
26
|
export interface EditorKeyHandlers {
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Ctrl/Cmd+S → the pane's save path.
|
|
29
|
+
*
|
|
30
|
+
* MUST be a no-op while a modal layer is open: `CodeEditor` (the only caller)
|
|
31
|
+
* checks `isModalLayerOpen()` before saving. The binding itself stays pure —
|
|
32
|
+
* this module imports no DOM — but because CodeMirror handles the key first and
|
|
33
|
+
* prevents the default, the window listener in `save-shortcut.ts` never gets to
|
|
34
|
+
* apply its own gate to this path.
|
|
35
|
+
*/
|
|
28
36
|
save(): void
|
|
29
37
|
/** Ctrl/Cmd+F → seed our find widget from the selection and open it. */
|
|
30
38
|
openFindForSelection(view: EditorView): void
|
|
@@ -34,6 +42,39 @@ export interface EditorKeyHandlers {
|
|
|
34
42
|
stepHunk(delta: 1 | -1): boolean
|
|
35
43
|
/** Escape → close the find widget; false when it was not open. */
|
|
36
44
|
closeFind(): boolean
|
|
45
|
+
/**
|
|
46
|
+
* Ctrl/Cmd+G → ask for a line number and jump there.
|
|
47
|
+
*
|
|
48
|
+
* The prompt is the caller's (`promptDialog`), so this module stays free of
|
|
49
|
+
* DOM/React; the binding always claims the key (browsers use Ctrl+G for
|
|
50
|
+
* "find next", which has nothing to do inside a code editor).
|
|
51
|
+
*/
|
|
52
|
+
gotoLine(view: EditorView): void
|
|
53
|
+
/**
|
|
54
|
+
* Ctrl/Cmd+D → select the next occurrence of the current selection.
|
|
55
|
+
*
|
|
56
|
+
* Returns the command's own answer: `false` (nothing to expand, or a mixed
|
|
57
|
+
* selection) must fall through to the browser instead of being swallowed —
|
|
58
|
+
* the same rule the hunk bindings follow.
|
|
59
|
+
*/
|
|
60
|
+
selectNextOccurrence(view: EditorView): boolean
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Resolve the "go to line" answer to a 1-based line number inside `total`.
|
|
65
|
+
*
|
|
66
|
+
* Accepts what VS Code's box accepts for the LINE half: `42`, ` 42 `, `42:7`
|
|
67
|
+
* (the column half is ignored — this editor jumps to a line, the status bar
|
|
68
|
+
* reports the column). Anything else (empty, `0`, text) is `undefined`, and a
|
|
69
|
+
* number past the end CLAMPS to the last line instead of failing: the answer
|
|
70
|
+
* usually comes from a file the user is reading, not from its exact length.
|
|
71
|
+
*/
|
|
72
|
+
export function parseGotoLine(text: string, total: number): number | undefined {
|
|
73
|
+
const match = /^\s*(\d+)(?::\d+)?\s*$/.exec(text)
|
|
74
|
+
if (match === null) return undefined
|
|
75
|
+
const value = Number(match[1])
|
|
76
|
+
if (!Number.isSafeInteger(value) || value < 1) return undefined
|
|
77
|
+
return Math.min(value, Math.max(1, Math.floor(total)))
|
|
37
78
|
}
|
|
38
79
|
|
|
39
80
|
/**
|
|
@@ -93,5 +134,22 @@ export function editorKeymap(handlers: EditorKeyHandlers): KeyBinding[] {
|
|
|
93
134
|
key: 'Escape',
|
|
94
135
|
run: () => handlers.closeFind(),
|
|
95
136
|
},
|
|
137
|
+
/**
|
|
138
|
+
* Ctrl/Cmd+G → go to line, Ctrl/Cmd+D → select next occurrence.
|
|
139
|
+
*
|
|
140
|
+
* `@codemirror/search` exports both, but this plugin deliberately does NOT
|
|
141
|
+
* mount `searchKeymap`: that keymap also opens the stock search panel, which
|
|
142
|
+
* the editor replaced with its own find widget. So the two commands are
|
|
143
|
+
* wired through injected handlers instead (the goto-line one renders no
|
|
144
|
+
* CodeMirror panel at all — the caller prompts).
|
|
145
|
+
*
|
|
146
|
+
* Mod-g claims the key even when the prompt is dismissed: Ctrl+G means
|
|
147
|
+
* "find next" in the browser and must never leave the editor. Mod-d does NOT
|
|
148
|
+
* set `preventDefault` — CodeMirror prevents the default for a key whenever
|
|
149
|
+
* one of its bindings sets that flag, even when every command returns false,
|
|
150
|
+
* and a failed expansion has to be able to fall through.
|
|
151
|
+
*/
|
|
152
|
+
{ key: 'Mod-g', run: (view) => { handlers.gotoLine(view); return true }, preventDefault: true },
|
|
153
|
+
{ key: 'Mod-d', run: (view) => handlers.selectNextOccurrence(view) },
|
|
96
154
|
]
|
|
97
155
|
}
|
|
@@ -300,7 +300,7 @@ export function FileTypeIcon(props: FileIconProps): ReactNode {
|
|
|
300
300
|
height={size}
|
|
301
301
|
viewBox="0 0 16 16"
|
|
302
302
|
fill="none"
|
|
303
|
-
className={props.className}
|
|
303
|
+
className={props.className === undefined ? 'rvs-fi' : `rvs-fi ${props.className}`}
|
|
304
304
|
aria-hidden="true"
|
|
305
305
|
>
|
|
306
306
|
<path
|
|
@@ -347,7 +347,14 @@ export function FolderGlyph(props: FolderGlyphProps): ReactNode {
|
|
|
347
347
|
const size = props.size ?? 16
|
|
348
348
|
return props.open === true
|
|
349
349
|
? (
|
|
350
|
-
<svg
|
|
350
|
+
<svg
|
|
351
|
+
width={size}
|
|
352
|
+
height={size}
|
|
353
|
+
viewBox="0 0 16 16"
|
|
354
|
+
fill="none"
|
|
355
|
+
className={props.className === undefined ? 'rvs-fi' : `rvs-fi ${props.className}`}
|
|
356
|
+
aria-hidden="true"
|
|
357
|
+
>
|
|
351
358
|
<path
|
|
352
359
|
d="M1.9 12V4.3c0-.6.4-1 1-1h3.2l1.5 1.7h5.6c.6 0 1 .4 1 1v5.4"
|
|
353
360
|
fill="#c69a3f"
|
|
@@ -365,7 +372,14 @@ export function FolderGlyph(props: FolderGlyphProps): ReactNode {
|
|
|
365
372
|
</svg>
|
|
366
373
|
)
|
|
367
374
|
: (
|
|
368
|
-
<svg
|
|
375
|
+
<svg
|
|
376
|
+
width={size}
|
|
377
|
+
height={size}
|
|
378
|
+
viewBox="0 0 16 16"
|
|
379
|
+
fill="none"
|
|
380
|
+
className={props.className === undefined ? 'rvs-fi' : `rvs-fi ${props.className}`}
|
|
381
|
+
aria-hidden="true"
|
|
382
|
+
>
|
|
369
383
|
<path
|
|
370
384
|
d="M1.9 12.3V4.2c0-.6.4-1 1-1h3.2l1.5 1.7h5.6c.6 0 1 .4 1 1v6.4c0 .6-.4 1-1 1H2.9c-.6 0-1-.4-1-1Z"
|
|
371
385
|
fill="#d9ab4e"
|
package/src/client/vsc/kit.tsx
CHANGED
|
@@ -654,13 +654,22 @@ export function DialogHost(): ReactNode {
|
|
|
654
654
|
return createPortal(
|
|
655
655
|
<>
|
|
656
656
|
{request !== undefined && <ModalCard key={request.id} request={request} />}
|
|
657
|
-
{
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
657
|
+
{/* Toast is the plugin's only report channel for "已上传 / 删除失败 / 已推送":
|
|
658
|
+
without a live region a screen reader never heard any of it (WCAG 4.1.3).
|
|
659
|
+
The stack is mounted even while empty so the region EXISTS before the
|
|
660
|
+
message arrives — a `role=status` region inserted together with its text
|
|
661
|
+
is announced by some screen readers and missed by others. It stays
|
|
662
|
+
polite; an error item asserts on its own, so a failure interrupts and a
|
|
663
|
+
success does not. (An empty stack is a zero-sized fixed box: no paint.) */}
|
|
664
|
+
<div className="rvs-toasts" role="status" aria-live="polite">
|
|
665
|
+
{items.map(item => (
|
|
666
|
+
<div
|
|
667
|
+
key={item.id}
|
|
668
|
+
className={item.error ? 'rvs-toast error' : 'rvs-toast'}
|
|
669
|
+
role={item.error ? 'alert' : undefined}
|
|
670
|
+
>{item.text}</div>
|
|
671
|
+
))}
|
|
672
|
+
</div>
|
|
664
673
|
</>,
|
|
665
674
|
document.body,
|
|
666
675
|
)
|
|
@@ -670,9 +679,13 @@ export function DialogHost(): ReactNode {
|
|
|
670
679
|
* Focusable elements inside one dialog, in DOM order.
|
|
671
680
|
*
|
|
672
681
|
* The modal is portaled to the END of `<body>`, so without a Tab trap a
|
|
673
|
-
* keyboard user tabs through the whole page to reach its buttons.
|
|
682
|
+
* keyboard user tabs through the whole page to reach its buttons. Exported for
|
|
683
|
+
* the other portaled layers that need the same walk (the terminal snippet
|
|
684
|
+
* popover); `DoctorPanel` keeps its own copy because it deliberately does not
|
|
685
|
+
* import this module (its copy path must not use the silently-failing
|
|
686
|
+
* `copyText`, which `check-doctor.mjs` pins).
|
|
674
687
|
*/
|
|
675
|
-
function focusables(root: HTMLElement | null): HTMLElement[] {
|
|
688
|
+
export function focusables(root: HTMLElement | null): HTMLElement[] {
|
|
676
689
|
if (root === null) return []
|
|
677
690
|
return Array.from(root.querySelectorAll<HTMLElement>(
|
|
678
691
|
'button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',
|
|
@@ -708,6 +721,10 @@ function ModalCard(props: { request: ModalRequest }): ReactNode {
|
|
|
708
721
|
|
|
709
722
|
useEffect(() => {
|
|
710
723
|
const onKey = (e: KeyboardEvent): void => {
|
|
724
|
+
// An IME candidate window owns Enter/Escape while composing: acting here
|
|
725
|
+
// would resolve the prompt with a half-composed value (or cancel it while
|
|
726
|
+
// the candidate list is open).
|
|
727
|
+
if (e.isComposing === true || e.keyCode === 229) return
|
|
711
728
|
if (e.key === 'Escape') {
|
|
712
729
|
e.preventDefault()
|
|
713
730
|
request.resolve(request.kind === 'prompt' ? undefined : false)
|