dsh-remote-vs 0.24.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 +50 -16
- package/README.md +40 -15
- package/THIRD-PARTY-NOTICES.md +188 -0
- package/lib/client.js +6512 -77887
- package/lib/index.js +1461 -1024
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/client/CodeEditor.d.ts +25 -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/RemoteExplorer.d.ts +53 -0
- package/lib/types/client/RemoteRoot.d.ts +5 -5
- 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 +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/editor-capability.d.ts +27 -0
- package/lib/types/client/i18n.d.ts +1 -1
- 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 +112 -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/vsc/FindWidget.d.ts +6 -0
- package/lib/types/client/vsc/breadcrumb.d.ts +30 -0
- package/lib/types/client/vsc/change-marks.d.ts +16 -6
- package/lib/types/client/vsc/editor-caret.d.ts +32 -0
- package/lib/types/client/vsc/editor-keymap.d.ts +35 -1
- 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 +13 -0
- package/lib/types/client/vsc/save-shortcut.d.ts +21 -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 +48 -0
- package/lib/types/client/vsc/terminal-writer.d.ts +52 -0
- 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/pool.d.ts +25 -0
- package/lib/types/routes.d.ts +2 -0
- package/lib/types/store.d.ts +7 -0
- package/lib/types/terminal.d.ts +33 -1
- 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 +205 -10
- package/src/client/DirectoryFlow.tsx +16 -0
- package/src/client/DoctorPanel.tsx +70 -7
- package/src/client/EditorPane.tsx +545 -118
- package/src/client/FloatingPlaceholder.tsx +34 -5
- package/src/client/HostsView.tsx +12 -3
- package/src/client/RemoteDirectoryPicker.tsx +12 -0
- package/src/client/RemoteEditorView.tsx +14 -11
- package/src/client/RemoteExplorer.tsx +929 -40
- package/src/client/RemoteRoot.tsx +167 -147
- package/src/client/SearchView.tsx +8 -0
- package/src/client/TerminalSnippets.tsx +432 -0
- package/src/client/TerminalView.tsx +50 -1
- package/src/client/XTerm.tsx +228 -58
- package/src/client/api.ts +106 -13
- package/src/client/auto-open-remote.ts +11 -9
- 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/editor-capability.ts +42 -0
- package/src/client/i18n.ts +228 -12
- package/src/client/index.tsx +22 -6
- 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 +537 -22
- package/src/client/terminal-input.ts +44 -0
- package/src/client/terminal-snippets.ts +216 -0
- package/src/client/ui.tsx +4 -0
- package/src/client/vsc/FindWidget.tsx +24 -9
- package/src/client/vsc/breadcrumb.tsx +339 -0
- package/src/client/vsc/change-marks.ts +93 -44
- package/src/client/vsc/editor-caret.ts +30 -0
- package/src/client/vsc/editor-keymap.ts +59 -1
- 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/file-icons.tsx +17 -3
- package/src/client/vsc/image-preview.tsx +110 -0
- package/src/client/vsc/kit.tsx +46 -10
- package/src/client/vsc/save-shortcut.ts +47 -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 +97 -0
- package/src/client/vsc/terminal-writer.ts +112 -0
- package/src/client/vsc/vsc.css +1078 -181
- 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/pool.ts +99 -27
- package/src/routes.ts +212 -43
- package/src/sftp.ts +51 -14
- package/src/store.ts +10 -0
- package/src/terminal.ts +225 -24
- package/src/view-settings.ts +50 -10
- package/lib/types/client/Dialog.d.ts +0 -14
- package/src/client/Dialog.tsx +0 -76
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caret readout maths for the editor status bar (pure, no CodeMirror/DOM).
|
|
3
|
+
*
|
|
4
|
+
* Kept out of `CodeEditor.tsx` so the gate can assert the 1-based conversion and
|
|
5
|
+
* the "selected characters" count without mounting an editor.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Caret readout for the status bar (1-based, matching what the user sees). */
|
|
9
|
+
export interface CodeEditorCaret {
|
|
10
|
+
/** 1-based line of the caret (the selection's head). */
|
|
11
|
+
line: number
|
|
12
|
+
/** 1-based column of the caret. */
|
|
13
|
+
column: number
|
|
14
|
+
/** Number of selected characters (0 = empty selection). */
|
|
15
|
+
selected: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The caret reading of one editor state. */
|
|
19
|
+
export function caretOf(state: {
|
|
20
|
+
doc: { lineAt(offset: number): { number: number; from: number; to: number } }
|
|
21
|
+
selection: { main: { head: number; from: number; to: number } }
|
|
22
|
+
}): CodeEditorCaret {
|
|
23
|
+
const main = state.selection.main
|
|
24
|
+
const line = state.doc.lineAt(main.head)
|
|
25
|
+
return {
|
|
26
|
+
line: line.number,
|
|
27
|
+
column: main.head - line.from + 1,
|
|
28
|
+
selected: Math.max(0, main.to - main.from),
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -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
|
}
|
|
@@ -135,3 +135,23 @@ export function langFor(path: string): Extension[] {
|
|
|
135
135
|
return []
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Guess the indentation style from the file body (status-bar hint only).
|
|
141
|
+
*
|
|
142
|
+
* Only the first stretch of lines that really starts with whitespace is
|
|
143
|
+
* inspected: the goal is a quick hint, not a formatter. `undefined` means "no
|
|
144
|
+
* indented line in the head", and the status bar then omits the item instead of
|
|
145
|
+
* inventing a default.
|
|
146
|
+
*/
|
|
147
|
+
export function detectIndentLabel(text: string): string | undefined {
|
|
148
|
+
const lines = text.split('\n', 200)
|
|
149
|
+
for (const line of lines) {
|
|
150
|
+
if (line.trim() === '') continue
|
|
151
|
+
if (line.startsWith('\t')) return 'Tab'
|
|
152
|
+
const spaces = /^ +/.exec(line)
|
|
153
|
+
if (spaces === null) continue
|
|
154
|
+
return `Spaces: ${Math.min(8, spaces[0].length)}`
|
|
155
|
+
}
|
|
156
|
+
return undefined
|
|
157
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Editor view preferences (word wrap + font size), shared by every surface that
|
|
3
|
+
* shows the editor (the sidebar pane, the conversation-view tab, the floating
|
|
4
|
+
* window).
|
|
5
|
+
*
|
|
6
|
+
* Module-level, React/DOM-free on purpose: those three surfaces are three
|
|
7
|
+
* different React trees, so React state cannot carry "I made the font bigger in
|
|
8
|
+
* the floating window, dock it and the sidebar must show the same size" — which
|
|
9
|
+
* is the whole point (it is ONE editor, only its mount changes).
|
|
10
|
+
*
|
|
11
|
+
* The pure parse/serialize half is exported because the self-check harness
|
|
12
|
+
* imports this module in Node: it must not read localStorage at module load
|
|
13
|
+
* (private mode throws on `getItem`).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** One shared view preference set. */
|
|
17
|
+
export interface EditorSettings {
|
|
18
|
+
/** Soft wrap the long lines. */
|
|
19
|
+
wrap: boolean
|
|
20
|
+
/** Editor type size in px (0.5 px steps are legal). */
|
|
21
|
+
fontSize: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** localStorage key: ONE JSON object, so the two fields cannot drift apart. */
|
|
25
|
+
export const EDITOR_SETTINGS_KEY = 'dsh-remote-vs.editor.settings'
|
|
26
|
+
|
|
27
|
+
/** Legal font-size range, shared with the floating window's Ctrl+wheel zoom. */
|
|
28
|
+
export const FONT_MIN = 9
|
|
29
|
+
export const FONT_MAX = 28
|
|
30
|
+
export const FONT_STEP = 1
|
|
31
|
+
|
|
32
|
+
/** Defaults used before anything was stored (matches the theme's 13px fallback). */
|
|
33
|
+
export const DEFAULT_EDITOR_SETTINGS: EditorSettings = { wrap: false, fontSize: 13 }
|
|
34
|
+
|
|
35
|
+
/** Clamp any input to a legal font size; non-numbers answer undefined. */
|
|
36
|
+
export function parseFontSize(value: unknown): number | undefined {
|
|
37
|
+
const numeric = typeof value === 'number'
|
|
38
|
+
? value
|
|
39
|
+
: typeof value === 'string' && value.trim() !== ''
|
|
40
|
+
? Number(value)
|
|
41
|
+
: Number.NaN
|
|
42
|
+
if (!Number.isFinite(numeric)) return undefined
|
|
43
|
+
// Half-pixel steps are legal (historically 12.5px); 13.3333 noise snaps to the grid.
|
|
44
|
+
const snapped = Math.round(numeric * 2) / 2
|
|
45
|
+
return Math.min(FONT_MAX, Math.max(FONT_MIN, snapped))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** One zoom step (-1 = smaller, +1 = bigger), already clamped. */
|
|
49
|
+
export function stepFontSize(size: number, direction: -1 | 1): number {
|
|
50
|
+
const current = parseFontSize(size) ?? DEFAULT_EDITOR_SETTINGS.fontSize
|
|
51
|
+
return parseFontSize(current + direction * FONT_STEP) ?? current
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Parse the persisted JSON.
|
|
56
|
+
*
|
|
57
|
+
* Anything damaged (not JSON, not an object, wrong field types) falls back to
|
|
58
|
+
* the defaults: this data only affects presentation, and a dirty localStorage
|
|
59
|
+
* entry must never keep the page from starting.
|
|
60
|
+
*/
|
|
61
|
+
export function parseEditorSettings(raw: string | null | undefined): EditorSettings {
|
|
62
|
+
if (typeof raw !== 'string' || raw === '') return DEFAULT_EDITOR_SETTINGS
|
|
63
|
+
let parsed: unknown
|
|
64
|
+
try {
|
|
65
|
+
parsed = JSON.parse(raw) as unknown
|
|
66
|
+
} catch {
|
|
67
|
+
return DEFAULT_EDITOR_SETTINGS
|
|
68
|
+
}
|
|
69
|
+
if (typeof parsed !== 'object' || parsed === null) return DEFAULT_EDITOR_SETTINGS
|
|
70
|
+
const record = parsed as Record<string, unknown>
|
|
71
|
+
const fontSize = parseFontSize(record.fontSize) ?? DEFAULT_EDITOR_SETTINGS.fontSize
|
|
72
|
+
const wrap = typeof record.wrap === 'boolean' ? record.wrap : DEFAULT_EDITOR_SETTINGS.wrap
|
|
73
|
+
return { wrap, fontSize }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Serialize only the known fields (never whatever else the caller passed). */
|
|
77
|
+
export function serializeEditorSettings(settings: EditorSettings): string {
|
|
78
|
+
return JSON.stringify({ wrap: settings.wrap, fontSize: settings.fontSize })
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ------------------------------------------------------------------ store
|
|
82
|
+
|
|
83
|
+
const listeners = new Set<() => void>()
|
|
84
|
+
/** Lazy current value; undefined = localStorage not read yet. */
|
|
85
|
+
let current: EditorSettings | undefined
|
|
86
|
+
|
|
87
|
+
function readFromStorage(): EditorSettings {
|
|
88
|
+
try {
|
|
89
|
+
return parseEditorSettings(localStorage.getItem(EDITOR_SETTINGS_KEY))
|
|
90
|
+
} catch {
|
|
91
|
+
// Private mode / storage disabled: the defaults still work this session.
|
|
92
|
+
return DEFAULT_EDITOR_SETTINGS
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function persist(settings: EditorSettings): void {
|
|
97
|
+
try {
|
|
98
|
+
localStorage.setItem(EDITOR_SETTINGS_KEY, serializeEditorSettings(settings))
|
|
99
|
+
} catch {
|
|
100
|
+
// Same as above: failing to persist does not affect this session.
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function emit(): void {
|
|
105
|
+
for (const listener of [...listeners]) {
|
|
106
|
+
try {
|
|
107
|
+
listener()
|
|
108
|
+
} catch {
|
|
109
|
+
// One broken surface must not starve the others.
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Current snapshot (identity-stable while unchanged, safe for useSyncExternalStore). */
|
|
115
|
+
export function editorSettingsSnapshot(): EditorSettings {
|
|
116
|
+
if (current === undefined) current = readFromStorage()
|
|
117
|
+
return current
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Subscribe to preference changes; returns the unsubscribe. */
|
|
121
|
+
export function subscribeEditorSettings(listener: () => void): () => void {
|
|
122
|
+
listeners.add(listener)
|
|
123
|
+
return () => {
|
|
124
|
+
listeners.delete(listener)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Change one preference and persist it.
|
|
130
|
+
*
|
|
131
|
+
* Illegal values (out-of-range size) are clamped BEFORE the "did it change"
|
|
132
|
+
* comparison: without that, every click on a "+" already at the cap would
|
|
133
|
+
* re-render all three surfaces for nothing.
|
|
134
|
+
*/
|
|
135
|
+
export function updateEditorSettings(patch: Partial<EditorSettings>): void {
|
|
136
|
+
const before = editorSettingsSnapshot()
|
|
137
|
+
const fontSize = patch.fontSize === undefined
|
|
138
|
+
? before.fontSize
|
|
139
|
+
: parseFontSize(patch.fontSize) ?? before.fontSize
|
|
140
|
+
const wrap = patch.wrap === undefined ? before.wrap : patch.wrap
|
|
141
|
+
if (fontSize === before.fontSize && wrap === before.wrap) return
|
|
142
|
+
const next: EditorSettings = { wrap, fontSize }
|
|
143
|
+
current = next
|
|
144
|
+
persist(next)
|
|
145
|
+
emit()
|
|
146
|
+
}
|
|
@@ -29,11 +29,10 @@ function chrome(p: Palette, dark: boolean): Extension {
|
|
|
29
29
|
'&': {
|
|
30
30
|
backgroundColor: p.bg,
|
|
31
31
|
color: p.fg,
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
// so a docked editor always renders at the default size.
|
|
32
|
+
// Type size comes from a CSS variable: the docked pane and the
|
|
33
|
+
// conversation tab set it from the shared editor preference (font buttons /
|
|
34
|
+
// Ctrl+wheel), while the floating window sets it from its own per-window
|
|
35
|
+
// zoom. A plain literal here would freeze the size and make both silent.
|
|
37
36
|
fontSize: 'var(--rvs-editor-font-size, 13px)',
|
|
38
37
|
height: '100%',
|
|
39
38
|
},
|
|
@@ -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"
|