dsh-remote-vs 0.27.0 → 0.29.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 +159 -23
- package/README.md +123 -23
- package/lib/client.js +6906 -6619
- package/lib/index.js +2014 -67
- package/lib/types/changes/recorder.d.ts +119 -2
- package/lib/types/client/CodeEditor.d.ts +15 -0
- package/lib/types/client/HostsView.d.ts +139 -2
- package/lib/types/client/api.d.ts +42 -2
- package/lib/types/client/changes/apply-failure.d.ts +41 -0
- package/lib/types/client/changes/block-confirm.d.ts +97 -0
- package/lib/types/client/changes/diff-outcome.d.ts +56 -0
- package/lib/types/client/changes/freshness.d.ts +51 -0
- package/lib/types/client/changes/model.d.ts +19 -1
- package/lib/types/client/changes/session-diff.d.ts +100 -0
- package/lib/types/client/changes/staleness.d.ts +98 -0
- package/lib/types/client/changes/turn-reverted.d.ts +82 -0
- package/lib/types/client/changes/turn-view.d.ts +131 -0
- package/lib/types/client/changes/undo-affordance.d.ts +44 -10
- package/lib/types/client/changes/undo-target.d.ts +12 -0
- package/lib/types/client/connection.d.ts +28 -1
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/store.d.ts +91 -1
- package/lib/types/client/vsc/change-marks.d.ts +21 -0
- package/lib/types/forward.d.ts +11 -1
- package/lib/types/pool.d.ts +95 -1
- package/lib/types/protocol.d.ts +221 -1
- package/lib/types/proxy.d.ts +136 -0
- package/lib/types/store.d.ts +81 -1
- package/lib/types/tools.d.ts +3 -0
- package/package.json +1 -1
- package/src/changes/recorder.ts +851 -8
- package/src/client/CodeEditor.tsx +43 -3
- package/src/client/ConnectionStatus.tsx +19 -5
- package/src/client/EditorPane.tsx +64 -7
- package/src/client/HostsView.tsx +552 -11
- package/src/client/PortsView.tsx +16 -0
- package/src/client/SettingsHosts.tsx +132 -6
- package/src/client/api.ts +60 -3
- package/src/client/changes/ChangesDock.tsx +539 -54
- package/src/client/changes/apply-failure.ts +73 -0
- package/src/client/changes/block-confirm.ts +180 -0
- package/src/client/changes/changes.css +45 -0
- package/src/client/changes/diff-outcome.ts +97 -0
- package/src/client/changes/freshness.ts +68 -0
- package/src/client/changes/model.ts +56 -1
- package/src/client/changes/session-diff.ts +187 -0
- package/src/client/changes/staleness.ts +148 -0
- package/src/client/changes/turn-reverted.ts +254 -0
- package/src/client/changes/turn-view.ts +195 -0
- package/src/client/changes/undo-affordance.ts +295 -63
- package/src/client/changes/undo-target.ts +12 -0
- package/src/client/connection.ts +76 -2
- package/src/client/i18n.ts +204 -4
- package/src/client/scm/DiffView.tsx +32 -13
- package/src/client/store.tsx +392 -16
- package/src/client/vsc/change-marks.ts +21 -0
- package/src/client/vsc/preview-document.tsx +4 -1
- package/src/client/vsc/vsc.css +6747 -6509
- package/src/forward.ts +38 -2
- package/src/importers.ts +125 -13
- package/src/keygen.ts +8 -1
- package/src/pool.ts +422 -27
- package/src/protocol.ts +229 -1
- package/src/proxy.ts +673 -0
- package/src/routes.ts +93 -14
- package/src/store.ts +335 -0
- package/src/tools.ts +47 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 「把鼠标停在这一行上,对这里的改动做事」:一枚贴行的 `⋯` 按钮 + 它展开的小菜单。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 为什么不直接用 `hoverTooltip`:它把浮层挂进 CodeMirror 自己的 `.cm-tooltip` 层,位置
|
|
5
5
|
* 由文本坐标算,形态只有"命中点正上方/正下方"两档。这对文字注释刚好,对一个**要点的
|
|
6
6
|
* 按钮**有两个毛病:
|
|
7
7
|
* 1. 落不到行的**右侧** —— 我们要按钮贴着行尾,不能盖住正在看的改动行;
|
|
@@ -14,52 +14,95 @@
|
|
|
14
14
|
*
|
|
15
15
|
* 命中规则与 CodeMirror 的装饰无关,只读 `changeSetOf(state).marks`(1-based 闭区间):
|
|
16
16
|
* **只有真的落在某个 mark 里才弹**。刻意不用 `changeBlockAt` —— 它带单行兜底,任何
|
|
17
|
-
*
|
|
17
|
+
* 一行都会返回一个区间,那样悬浮在任何地方都会冒出按钮。
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* ## 为什么是"一枚按钮 + 菜单",而不是并排两枚按钮
|
|
20
|
+
*
|
|
21
|
+
* 动作有两个(撤销这处改动 / 确认保留),一开始做成并排两枚,但行尾放不下时只能把
|
|
22
|
+
* 整组挪走 —— 挪到被悬停行的上方后,指针从那一行移向按钮必然经过上一行;上一行多半
|
|
23
|
+
* 不是改动行,`mousemove` 一落到它就整组收起,按钮因此**永远点不到**(2026-11-26 复
|
|
24
|
+
* 核实测)。现在只在行尾放一枚小的 `⋯`(与行同一垂直中线),点击后展开的菜单挂在它
|
|
25
|
+
* 旁边:指针从行内水平移到按钮、再从按钮移到菜单,全程不进入别的行。
|
|
26
|
+
*
|
|
27
|
+
* 本模块只回答"用户要对哪一处改动做什么":`onUndo(mark)` / `confirm.onToggle(mark)`
|
|
28
|
+
* 收到的是 `marks` 里的那个对象,其中 `hunk` 是 `ChangeSet.patches` 的下标。真正的
|
|
29
|
+
* 撤销(远端 `git apply -R`)由调用方完成,文案也由调用方的 i18n 决定。
|
|
23
30
|
*/
|
|
24
31
|
import type { EditorState, Extension } from '@codemirror/state'
|
|
25
32
|
import { EditorView, ViewPlugin, type Rect, type ViewUpdate } from '@codemirror/view'
|
|
26
33
|
import { changeSetOf, type ChangeMark } from '../vsc/change-marks.ts'
|
|
27
34
|
|
|
28
|
-
/**
|
|
29
|
-
const
|
|
35
|
+
/** 贴行那枚 `⋯` 的 class(样式在 `vsc/vsc.css` 的 `session changes` 一节)。 */
|
|
36
|
+
const TRIGGER_CLASS = 'rvs-change-actions'
|
|
30
37
|
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
/** 展开菜单的 class(菜单项也在里面:`.rvs-change-actions-menu button`)。 */
|
|
39
|
+
const MENU_CLASS = 'rvs-change-actions-menu'
|
|
40
|
+
|
|
41
|
+
/** 菜单里两个动作的 class(自检按它们定位,不依赖文案)。 */
|
|
42
|
+
const UNDO_ITEM_CLASS = 'rvs-change-actions-undo'
|
|
43
|
+
const CONFIRM_ITEM_CLASS = 'rvs-change-actions-confirm'
|
|
44
|
+
|
|
45
|
+
/** 两个浮层元素的 z-index(编辑器宿主有裁剪层,必须高过它)。 */
|
|
46
|
+
const LAYER_Z = '2100'
|
|
47
|
+
|
|
48
|
+
/** 悬停多久后弹出(毫秒)。 */
|
|
37
49
|
const DEFAULT_HOVER_MS = 300
|
|
38
50
|
|
|
39
51
|
/**
|
|
40
|
-
*
|
|
52
|
+
* 指针离开编辑器内容后,浮层还留多久(毫秒)。
|
|
41
53
|
*
|
|
42
|
-
* 只为跨越"行尾 → 按钮"
|
|
43
|
-
*
|
|
54
|
+
* 只为跨越"行尾 → 按钮"之间那段空隙,以及从按钮进菜单的距离:那段只有几个像素,
|
|
55
|
+
* 150ms 足够,又不至于让一个已经离开的浮层在屏幕上赖着。
|
|
44
56
|
*/
|
|
45
57
|
const LEAVE_GRACE_MS = 150
|
|
46
58
|
|
|
47
59
|
/** 默认按钮文案。真实调用方(`CodeEditor`)总会传自己 i18n 的那一条。 */
|
|
48
60
|
export const DEFAULT_UNDO_LABEL = '撤销这处改动'
|
|
49
61
|
|
|
62
|
+
/** 「确认保留」的默认文案(同上是兜底:真实调用方传 i18n)。 */
|
|
63
|
+
export const DEFAULT_CONFIRM_LABEL = '确认保留'
|
|
64
|
+
|
|
65
|
+
/** 已确认态下的默认文案。 */
|
|
66
|
+
export const DEFAULT_CONFIRMED_LABEL = '已确认保留'
|
|
67
|
+
|
|
68
|
+
/** `⋯` 按钮的默认说明(真实调用方传 i18n)。 */
|
|
69
|
+
export const DEFAULT_TRIGGER_LABEL = '改动操作'
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 菜单里的第二个动作:「这处改动我看过,保留」。
|
|
73
|
+
*
|
|
74
|
+
* 它是**纯本地记账**(见 `changes/block-confirm.ts`):不写远端、不发请求、不动
|
|
75
|
+
* `ChangeSet`。所以这里只把"这一块当前是什么状态"问出来、把点击交回去,存哪里、
|
|
76
|
+
* 怎么持久化都由调用方决定 —— 编辑器组件不持有那份状态。
|
|
77
|
+
*/
|
|
78
|
+
export interface BlockConfirmOptions {
|
|
79
|
+
/** 这一块现在是否已确认(每次点击后重新读取,状态在 React 之外变化)。 */
|
|
80
|
+
isConfirmed: (mark: ChangeMark) => boolean
|
|
81
|
+
/** 用户点了切换:调用方负责落盘(本地存储),不得发起任何远端写。 */
|
|
82
|
+
onToggle: (mark: ChangeMark) => void
|
|
83
|
+
/** 未确认时的文案。 */
|
|
84
|
+
label: (mark: ChangeMark) => string
|
|
85
|
+
/** 已确认时的文案;省略则沿用 {@link label}。 */
|
|
86
|
+
pressedLabel?: (mark: ChangeMark) => string
|
|
87
|
+
}
|
|
88
|
+
|
|
50
89
|
export interface UndoAffordanceOptions {
|
|
51
90
|
/**
|
|
52
|
-
*
|
|
91
|
+
* 点了撤销:`mark` 就是 `ChangeSet.marks` 里的那个对象(`hunk` = `patches` 下标)。
|
|
53
92
|
* 不给时整块扩展不安装(`[]`),行为与没有这个功能时完全一致。
|
|
54
93
|
*/
|
|
55
94
|
onUndo?: (mark: ChangeMark) => void
|
|
56
95
|
/**
|
|
57
|
-
*
|
|
96
|
+
* 撤销项的文案。默认只是兜底:真实调用方按 `kind` 给出自己的(i18n)说法,
|
|
58
97
|
* 例如删除锚点说「撤销这处删除」。
|
|
59
98
|
*/
|
|
60
99
|
label?: (mark: ChangeMark) => string
|
|
100
|
+
/** `⋯` 按钮的说明(title / aria-label)。 */
|
|
101
|
+
triggerLabel?: () => string
|
|
61
102
|
/** 悬停延迟,缺省 300ms。 */
|
|
62
103
|
hoverTime?: number
|
|
104
|
+
/** 「确认保留」这一级(省略 = 菜单里只有撤销一项)。 */
|
|
105
|
+
confirm?: BlockConfirmOptions
|
|
63
106
|
}
|
|
64
107
|
|
|
65
108
|
/** 指针底下那一行命中的改动(1-based 行号 + `marks` 里的原对象)。 */
|
|
@@ -137,7 +180,7 @@ function lineUnderPointer(view: EditorView, event: MouseEvent): number | null {
|
|
|
137
180
|
}
|
|
138
181
|
}
|
|
139
182
|
|
|
140
|
-
/**
|
|
183
|
+
/** 一件改动浮层的实例状态:`⋯` 按钮、它的菜单、悬停计时、当前命中的那一处改动。 */
|
|
141
184
|
class UndoAffordanceView {
|
|
142
185
|
/**
|
|
143
186
|
* 自检用来认出"这个插件装上了没有"。
|
|
@@ -151,15 +194,23 @@ class UndoAffordanceView {
|
|
|
151
194
|
private readonly view: EditorView
|
|
152
195
|
private readonly onUndo: (mark: ChangeMark) => void
|
|
153
196
|
private readonly label: (mark: ChangeMark) => string
|
|
197
|
+
private readonly triggerLabel: () => string
|
|
154
198
|
private readonly hoverTime: number
|
|
155
|
-
|
|
199
|
+
/** 「确认保留」这一级的回调;`undefined` = 菜单里只有撤销一项。 */
|
|
200
|
+
private readonly confirm: BlockConfirmOptions | undefined
|
|
201
|
+
private trigger: HTMLButtonElement | undefined
|
|
202
|
+
private menu: HTMLDivElement | undefined
|
|
203
|
+
private undoItem: HTMLButtonElement | undefined
|
|
204
|
+
private confirmItem: HTMLButtonElement | undefined
|
|
205
|
+
/** 菜单当前是否展开(展开时 `aria-expanded` 为 true)。 */
|
|
206
|
+
private menuOpen = false
|
|
156
207
|
private timer: number | undefined
|
|
157
208
|
/**
|
|
158
209
|
* 「指针已经离开了」的宽限计时。
|
|
159
210
|
*
|
|
160
|
-
*
|
|
211
|
+
* 浮层挂在行尾右侧、位于编辑器内容之外,鼠标从那一行移到按钮上必然先离开
|
|
161
212
|
* `contentDOM` —— 若 `mouseleave` 立刻收,用户永远点不到。所以离开后等一小会儿,
|
|
162
|
-
*
|
|
213
|
+
* 指针真的进了按钮/菜单就撤销这次收起。
|
|
163
214
|
*/
|
|
164
215
|
private leaveTimer: number | undefined
|
|
165
216
|
/** 指针当前停在的改动(可能还在等计时)。 */
|
|
@@ -168,15 +219,17 @@ class UndoAffordanceView {
|
|
|
168
219
|
private shown: Hovered | undefined
|
|
169
220
|
|
|
170
221
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
222
|
+
* 收起用的全局监听:任何时候按下鼠标(触发按钮与菜单自己除外)、按 Escape、页面切到
|
|
223
|
+
* 后台、窗口失焦,都把浮层收掉。一次注册、常在的写法与 `useSelectionPopup` 一致 ——
|
|
173
224
|
* 浮层活不过它所属的编辑器表面,宁可多收一次,也不能留一个指向旧行的按钮。
|
|
174
225
|
*/
|
|
175
226
|
private readonly onGlobalMouseDown = (event: MouseEvent): void => {
|
|
176
227
|
if (this.shown === undefined) return
|
|
177
|
-
const button = this.button
|
|
178
228
|
const target = event.target instanceof Node ? event.target : null
|
|
179
|
-
|
|
229
|
+
// 触发按钮与菜单都在 body 上、都不在编辑器 DOM 里:点它们不算"点了别处"。
|
|
230
|
+
for (const element of [this.trigger, this.menu]) {
|
|
231
|
+
if (element !== undefined && target !== null && element.contains(target)) return
|
|
232
|
+
}
|
|
180
233
|
this.reset()
|
|
181
234
|
}
|
|
182
235
|
|
|
@@ -195,7 +248,9 @@ class UndoAffordanceView {
|
|
|
195
248
|
this.view = view
|
|
196
249
|
this.onUndo = options.onUndo ?? (() => {})
|
|
197
250
|
this.label = options.label ?? (() => DEFAULT_UNDO_LABEL)
|
|
251
|
+
this.triggerLabel = options.triggerLabel ?? (() => DEFAULT_TRIGGER_LABEL)
|
|
198
252
|
this.hoverTime = options.hoverTime ?? DEFAULT_HOVER_MS
|
|
253
|
+
this.confirm = options.confirm
|
|
199
254
|
document.addEventListener('mousedown', this.onGlobalMouseDown, true)
|
|
200
255
|
document.addEventListener('keydown', this.onGlobalKeyDown, true)
|
|
201
256
|
document.addEventListener('visibilitychange', this.onVisibilityChange)
|
|
@@ -205,6 +260,13 @@ class UndoAffordanceView {
|
|
|
205
260
|
/** 鼠标在编辑器内容里移动:命中一处改动就(重新)开始悬停计时。 */
|
|
206
261
|
handleMove(event: MouseEvent): void {
|
|
207
262
|
this.cancelLeave()
|
|
263
|
+
/**
|
|
264
|
+
* 键盘用户已经把焦点放进菜单项时,鼠标的偶然移动不该把菜单收掉(否则用键盘
|
|
265
|
+
* 打开菜单后,手一碰鼠标菜单就消失,而焦点已经不在编辑器里、再想用键盘继续
|
|
266
|
+
* 也没有落点)。收起改由 Escape / 点菜单外部决定(`onGlobalKeyDown` /
|
|
267
|
+
* `onGlobalMouseDown`)。
|
|
268
|
+
*/
|
|
269
|
+
if (this.menuHasFocus()) return
|
|
208
270
|
/**
|
|
209
271
|
* 只读的编辑器没有可执行的撤销:断线降级(`connection.state === error`)与超上限
|
|
210
272
|
* 截断都通过 CodeMirror 的 `readOnly` 生效,而这条动作是一次**远端写**
|
|
@@ -227,15 +289,15 @@ class UndoAffordanceView {
|
|
|
227
289
|
return
|
|
228
290
|
}
|
|
229
291
|
const current = this.hovered
|
|
230
|
-
//
|
|
292
|
+
// 同一个改动点:计时已经开始(或浮层已经弹出),不重来 —— 否则手一抖就得再等一遍。
|
|
231
293
|
if (current !== undefined && current.line === line && current.mark === mark) return
|
|
232
|
-
//
|
|
294
|
+
// 换了一处(或从别处移过来):旧浮层立刻收,旧计时作废。
|
|
233
295
|
this.reset()
|
|
234
296
|
this.hovered = { mark, line, element: lineElementAt(this.view, event) }
|
|
235
297
|
this.timer = window.setTimeout(() => { this.arm() }, this.hoverTime)
|
|
236
298
|
}
|
|
237
299
|
|
|
238
|
-
/**
|
|
300
|
+
/** 指针离开编辑器内容(可能正走向按钮/菜单,见 `leaveTimer`)。 */
|
|
239
301
|
handleLeave(): void {
|
|
240
302
|
if (this.shown === undefined) {
|
|
241
303
|
// 还没弹出来就走了:计时直接作废,不用等宽限。
|
|
@@ -271,30 +333,117 @@ class UndoAffordanceView {
|
|
|
271
333
|
this.show(hover)
|
|
272
334
|
}
|
|
273
335
|
|
|
274
|
-
/**
|
|
275
|
-
|
|
276
|
-
|
|
336
|
+
/**
|
|
337
|
+
* 建那枚 `⋯`(一个实例一个,复用)。
|
|
338
|
+
*
|
|
339
|
+
* 点它只做一件事:展开/收起菜单。按钮本身永远是**固定定位挂在 body 上**的,
|
|
340
|
+
* 位置由 `show()` 按行尾算。
|
|
341
|
+
*/
|
|
342
|
+
private ensureTrigger(): HTMLButtonElement {
|
|
343
|
+
const existing = this.trigger
|
|
277
344
|
if (existing !== undefined) return existing
|
|
278
345
|
const button = document.createElement('button')
|
|
279
346
|
button.type = 'button'
|
|
280
|
-
button.className =
|
|
347
|
+
button.className = TRIGGER_CLASS
|
|
348
|
+
button.textContent = '⋯'
|
|
349
|
+
button.setAttribute('aria-haspopup', 'menu')
|
|
350
|
+
button.setAttribute('aria-expanded', 'false')
|
|
281
351
|
// 行内再写一遍固定定位:样式表缺席(自检、被别处的样式覆盖)时按钮仍然不会被
|
|
282
352
|
// 任何滚动/裁剪祖先吃掉。
|
|
283
353
|
button.style.position = 'fixed'
|
|
284
|
-
button.style.zIndex =
|
|
354
|
+
button.style.zIndex = LAYER_Z
|
|
285
355
|
// 按下时不抢焦点、不打断编辑器里的选区:与旁边那个「添加到对话」按钮同一套处理。
|
|
286
356
|
button.addEventListener('mousedown', (event) => { event.preventDefault() })
|
|
287
357
|
// 指针真的进了按钮:撤销上面那次"离开了"的收起。
|
|
288
358
|
button.addEventListener('mouseenter', () => { this.cancelLeave() })
|
|
289
359
|
button.addEventListener('mouseleave', () => { this.scheduleLeave() })
|
|
290
360
|
button.addEventListener('click', () => {
|
|
361
|
+
if (this.shown === undefined) return
|
|
362
|
+
if (this.menuOpen) this.closeMenu()
|
|
363
|
+
else this.openMenu()
|
|
364
|
+
})
|
|
365
|
+
this.trigger = button
|
|
366
|
+
return button
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** 建菜单(一个实例一个,复用):撤销 +(可选)确认保留。 */
|
|
370
|
+
private ensureMenu(): HTMLDivElement {
|
|
371
|
+
const existing = this.menu
|
|
372
|
+
if (existing !== undefined) return existing
|
|
373
|
+
const menu = document.createElement('div')
|
|
374
|
+
menu.className = MENU_CLASS
|
|
375
|
+
menu.setAttribute('role', 'menu')
|
|
376
|
+
menu.style.position = 'fixed'
|
|
377
|
+
menu.style.zIndex = LAYER_Z
|
|
378
|
+
menu.hidden = true
|
|
379
|
+
menu.addEventListener('mouseenter', () => { this.cancelLeave() })
|
|
380
|
+
menu.addEventListener('mouseleave', () => { this.scheduleLeave() })
|
|
381
|
+
menu.addEventListener('mousedown', (event) => {
|
|
382
|
+
// 点菜单项不抢焦点(编辑器里的选区不该因为一次操作丢掉)。
|
|
383
|
+
event.preventDefault()
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
const undo = document.createElement('button')
|
|
387
|
+
undo.type = 'button'
|
|
388
|
+
undo.className = UNDO_ITEM_CLASS
|
|
389
|
+
undo.setAttribute('role', 'menuitem')
|
|
390
|
+
undo.addEventListener('click', () => {
|
|
291
391
|
const shown = this.shown
|
|
292
392
|
// 先收浮层再回调:回调会改远端文件、重读标签页,浮层留着就已经指向旧内容了。
|
|
293
393
|
this.reset()
|
|
294
394
|
if (shown !== undefined) this.onUndo(shown.mark)
|
|
295
395
|
})
|
|
296
|
-
|
|
297
|
-
|
|
396
|
+
menu.appendChild(undo)
|
|
397
|
+
|
|
398
|
+
const confirm = this.confirm
|
|
399
|
+
if (confirm !== undefined) {
|
|
400
|
+
const item = document.createElement('button')
|
|
401
|
+
item.type = 'button'
|
|
402
|
+
item.className = CONFIRM_ITEM_CLASS
|
|
403
|
+
item.setAttribute('role', 'menuitem')
|
|
404
|
+
item.addEventListener('click', () => {
|
|
405
|
+
const shown = this.shown
|
|
406
|
+
if (shown === undefined) return
|
|
407
|
+
// 不收起:切换的是一个位(已确认 ↔ 未确认),收起用户就看不见这次点击的结果。
|
|
408
|
+
confirm.onToggle(shown.mark)
|
|
409
|
+
this.syncConfirm(shown.mark)
|
|
410
|
+
this.placeMenu()
|
|
411
|
+
})
|
|
412
|
+
menu.appendChild(item)
|
|
413
|
+
this.confirmItem = item
|
|
414
|
+
}
|
|
415
|
+
this.undoItem = undo
|
|
416
|
+
this.menu = menu
|
|
417
|
+
return menu
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** 把菜单里的两项刷成这一处改动的当前状态。 */
|
|
421
|
+
private syncItems(mark: ChangeMark): void {
|
|
422
|
+
const undo = this.undoItem
|
|
423
|
+
if (undo !== undefined) {
|
|
424
|
+
const text = this.label(mark)
|
|
425
|
+
if (undo.textContent !== text) undo.textContent = text
|
|
426
|
+
undo.title = text
|
|
427
|
+
undo.setAttribute('aria-label', text)
|
|
428
|
+
undo.dataset.kind = mark.kind
|
|
429
|
+
undo.dataset.hunk = String(mark.hunk ?? -1)
|
|
430
|
+
}
|
|
431
|
+
this.syncConfirm(mark)
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** 把「确认保留」项刷成这一块当前的状态(文案 + aria-pressed + data 属性)。 */
|
|
435
|
+
private syncConfirm(mark: ChangeMark): void {
|
|
436
|
+
const confirm = this.confirm
|
|
437
|
+
const item = this.confirmItem
|
|
438
|
+
if (confirm === undefined || item === undefined) return
|
|
439
|
+
const on = confirm.isConfirmed(mark)
|
|
440
|
+
const text = on ? (confirm.pressedLabel?.(mark) ?? confirm.label(mark)) : confirm.label(mark)
|
|
441
|
+
if (item.textContent !== text) item.textContent = text
|
|
442
|
+
item.title = text
|
|
443
|
+
item.setAttribute('aria-label', text)
|
|
444
|
+
item.setAttribute('aria-pressed', on ? 'true' : 'false')
|
|
445
|
+
item.dataset.confirmed = on ? '1' : '0'
|
|
446
|
+
item.classList.toggle('is-on', on)
|
|
298
447
|
}
|
|
299
448
|
|
|
300
449
|
/** 取消"指针离开"的宽限收起。 */
|
|
@@ -304,41 +453,117 @@ class UndoAffordanceView {
|
|
|
304
453
|
this.leaveTimer = undefined
|
|
305
454
|
}
|
|
306
455
|
|
|
307
|
-
/**
|
|
456
|
+
/** 等一小会儿再收:指针可能是走向按钮/菜单(见 `leaveTimer`)。 */
|
|
308
457
|
private scheduleLeave(): void {
|
|
309
458
|
this.cancelLeave()
|
|
310
459
|
this.leaveTimer = window.setTimeout(() => {
|
|
311
460
|
this.leaveTimer = undefined
|
|
461
|
+
// 焦点在菜单里(键盘路径):指针离开不该把菜单收掉。
|
|
462
|
+
if (this.menuHasFocus()) return
|
|
312
463
|
this.reset()
|
|
313
464
|
}, LEAVE_GRACE_MS)
|
|
314
465
|
}
|
|
315
466
|
|
|
316
|
-
/**
|
|
467
|
+
/** 焦点是否在展开的菜单里(键盘用户正在菜单项之间移动)。 */
|
|
468
|
+
private menuHasFocus(): boolean {
|
|
469
|
+
const menu = this.menu
|
|
470
|
+
if (menu === undefined || !this.menuOpen) return false
|
|
471
|
+
return menu.contains(document.activeElement)
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* 把 `⋯` 放到这一行的右侧(贴行尾,视口内)。
|
|
476
|
+
*
|
|
477
|
+
* 关键约束:**垂直中线锁在这一行上**。按钮只有一行高,指针从行内水平移到它、
|
|
478
|
+
* 再从它移到菜单,全程不进入别的 `.cm-line` —— 上一版把整组按钮挪到行的上方,
|
|
479
|
+
* 指针必然先经过上一行,而上一行不是改动行会立刻触发 `reset()`,按钮永远点不到
|
|
480
|
+
* (2026-11-26 复核实测)。行尾贴到视口边缘时只做横向夹取,绝不上下移动。
|
|
481
|
+
*/
|
|
317
482
|
private show(hover: Hovered): void {
|
|
318
|
-
const
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (rect === null) {
|
|
483
|
+
const trigger = this.ensureTrigger()
|
|
484
|
+
const label = this.triggerLabel()
|
|
485
|
+
trigger.title = label
|
|
486
|
+
trigger.setAttribute('aria-label', label)
|
|
487
|
+
if (trigger.parentNode === null) document.body.appendChild(trigger)
|
|
488
|
+
const menu = this.ensureMenu()
|
|
489
|
+
if (menu.parentNode === null) document.body.appendChild(menu)
|
|
490
|
+
this.syncItems(hover.mark)
|
|
491
|
+
if (!this.placeTrigger(hover)) {
|
|
328
492
|
// 位置量不出来(既没有文本坐标也没有行元素):宁可先不显示,也不要把按钮
|
|
329
493
|
// 丢到屏幕左上角去。
|
|
330
|
-
|
|
331
|
-
|
|
494
|
+
trigger.remove()
|
|
495
|
+
menu.remove()
|
|
332
496
|
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** 按行尾计算 `⋯` 的位置;量不到位置时返回 false。 */
|
|
500
|
+
private placeTrigger(hover: Hovered): boolean {
|
|
501
|
+
const trigger = this.trigger
|
|
502
|
+
if (trigger === undefined) return false
|
|
503
|
+
const rect = this.rectFor(hover)
|
|
504
|
+
if (rect === null) return false
|
|
333
505
|
const gap = 8
|
|
334
|
-
const
|
|
335
|
-
let left = rect.right + gap
|
|
336
|
-
// 按钮宽度只有挂进文档才量得到;量不到(0)时按"不许超出视口右边界"处理。
|
|
337
|
-
const width = button.getBoundingClientRect().width
|
|
506
|
+
const width = trigger.getBoundingClientRect().width
|
|
338
507
|
const limit = window.innerWidth - gap
|
|
508
|
+
let left = rect.right + gap
|
|
509
|
+
// 只夹横向:垂直中线必须留在这一行上(见 `show` 的说明)。
|
|
339
510
|
left = width > 0 && left + width > limit ? Math.max(gap, limit - width) : Math.min(left, limit)
|
|
340
|
-
|
|
341
|
-
|
|
511
|
+
trigger.style.left = `${Math.round(left)}px`
|
|
512
|
+
trigger.style.top = `${Math.round((rect.top + rect.bottom) / 2)}px`
|
|
513
|
+
if (this.menuOpen) this.placeMenu()
|
|
514
|
+
return true
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* 菜单贴着按钮:默认在下方,放不下就翻到上方,横向与按钮右对齐。
|
|
519
|
+
*
|
|
520
|
+
* **垂直方向零缝**,这是可达性的关键(复核 MUST):菜单与按钮之间若留出 4px 空隙,
|
|
521
|
+
* 那条带正好落在下一行 `.cm-line` 的箱体上;指针从按钮下移到菜单必然经过它,
|
|
522
|
+
* `mousemove` 一落到那一行(不是改动行)就 `handleMove` → `reset()`,菜单和按钮
|
|
523
|
+
* 一起消失,鼠标主路径因此完全点不到菜单项(复核者用真插件 + jsdom 复现)。
|
|
524
|
+
* 现在菜单顶边(下方模式)就是按钮底边、翻转模式菜单底边就是按钮顶边,再配合样式表
|
|
525
|
+
* 里那条 8px 透明桥(`::before`,只覆盖按钮自身的区域),接缝处不留给编辑器内容。
|
|
526
|
+
*/
|
|
527
|
+
private placeMenu(): void {
|
|
528
|
+
const menu = this.menu
|
|
529
|
+
const trigger = this.trigger
|
|
530
|
+
if (menu === undefined || trigger === undefined) return
|
|
531
|
+
const anchor = trigger.getBoundingClientRect()
|
|
532
|
+
const box = menu.getBoundingClientRect()
|
|
533
|
+
/** 只用于视口边缘的留白;垂直方向不使用任何间隙(见方法说明)。 */
|
|
534
|
+
const edge = 4
|
|
535
|
+
const limitX = window.innerWidth - edge
|
|
536
|
+
const limitY = window.innerHeight - edge
|
|
537
|
+
const width = box.width
|
|
538
|
+
let left = anchor.right - width
|
|
539
|
+
left = Math.max(edge, Math.min(left, limitX - width))
|
|
540
|
+
let top = anchor.bottom
|
|
541
|
+
let side: 'below' | 'above' = 'below'
|
|
542
|
+
if (box.height > 0 && top + box.height > limitY) {
|
|
543
|
+
top = anchor.top - box.height
|
|
544
|
+
side = 'above'
|
|
545
|
+
}
|
|
546
|
+
menu.dataset.side = side
|
|
547
|
+
menu.style.left = `${Math.round(left)}px`
|
|
548
|
+
menu.style.top = `${Math.round(top)}px`
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/** 展开菜单(`aria-expanded` 同步,位置先算再显示)。 */
|
|
552
|
+
private openMenu(): void {
|
|
553
|
+
const menu = this.ensureMenu()
|
|
554
|
+
if (menu.parentNode === null) document.body.appendChild(menu)
|
|
555
|
+
this.menuOpen = true
|
|
556
|
+
this.trigger?.setAttribute('aria-expanded', 'true')
|
|
557
|
+
menu.hidden = false
|
|
558
|
+
this.placeMenu()
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/** 收起菜单(`⋯` 留在原地,用户可以直接再点开)。 */
|
|
562
|
+
private closeMenu(): void {
|
|
563
|
+
this.menuOpen = false
|
|
564
|
+
this.trigger?.setAttribute('aria-expanded', 'false')
|
|
565
|
+
const menu = this.menu
|
|
566
|
+
if (menu !== undefined) menu.hidden = true
|
|
342
567
|
}
|
|
343
568
|
|
|
344
569
|
/**
|
|
@@ -370,8 +595,11 @@ class UndoAffordanceView {
|
|
|
370
595
|
this.cancelLeave()
|
|
371
596
|
this.hovered = undefined
|
|
372
597
|
this.shown = undefined
|
|
373
|
-
|
|
374
|
-
|
|
598
|
+
this.closeMenu()
|
|
599
|
+
const trigger = this.trigger
|
|
600
|
+
if (trigger !== undefined && trigger.parentNode !== null) trigger.remove()
|
|
601
|
+
const menu = this.menu
|
|
602
|
+
if (menu !== undefined && menu.parentNode !== null) menu.remove()
|
|
375
603
|
}
|
|
376
604
|
|
|
377
605
|
update(update: ViewUpdate): void {
|
|
@@ -387,8 +615,12 @@ class UndoAffordanceView {
|
|
|
387
615
|
|
|
388
616
|
destroy(): void {
|
|
389
617
|
this.reset()
|
|
390
|
-
this.
|
|
391
|
-
this.
|
|
618
|
+
this.trigger?.remove()
|
|
619
|
+
this.trigger = undefined
|
|
620
|
+
this.menu?.remove()
|
|
621
|
+
this.menu = undefined
|
|
622
|
+
this.undoItem = undefined
|
|
623
|
+
this.confirmItem = undefined
|
|
392
624
|
document.removeEventListener('mousedown', this.onGlobalMouseDown, true)
|
|
393
625
|
document.removeEventListener('keydown', this.onGlobalKeyDown, true)
|
|
394
626
|
document.removeEventListener('visibilitychange', this.onVisibilityChange)
|
|
@@ -397,7 +629,7 @@ class UndoAffordanceView {
|
|
|
397
629
|
}
|
|
398
630
|
|
|
399
631
|
/**
|
|
400
|
-
*
|
|
632
|
+
* 装上「改动操作」浮层(`⋯` + 菜单)。
|
|
401
633
|
*
|
|
402
634
|
* 没有 `onUndo`(调用方没接这个动作)时返回空扩展:不是"装上了但点了没反应",而是
|
|
403
635
|
* 压根没有插件 —— 不留 DOM 监听、不留任何行为差异。
|
|
@@ -37,6 +37,18 @@ export interface ChangeOrigin {
|
|
|
37
37
|
alias: string
|
|
38
38
|
/** Ledger root the patch paths are relative to (`git apply -R` runs here). */
|
|
39
39
|
root: string
|
|
40
|
+
/**
|
|
41
|
+
* Which axis the hunks came from: the session total (default) or one turn.
|
|
42
|
+
*
|
|
43
|
+
* Load-bearing twice: the staleness judge needs the list that matches the
|
|
44
|
+
* marks (turn counts vs session counts differ by definition), and a re-read
|
|
45
|
+
* after a save/revert must fetch the SAME axis — a turn patch applied to a tab
|
|
46
|
+
* whose marks were rebuilt from the session baseline would revert the wrong
|
|
47
|
+
* amount of work.
|
|
48
|
+
*/
|
|
49
|
+
scope?: 'session' | 'turn'
|
|
50
|
+
/** For `scope: 'turn'`: the turn whose delta the marks describe. */
|
|
51
|
+
turn?: number
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
/** Why a revert must be refused. */
|
package/src/client/connection.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* idle minutes, and the next operation dials again.
|
|
15
15
|
*/
|
|
16
16
|
import { useSyncExternalStore } from 'react'
|
|
17
|
-
import type { RemoteConnectionStatus } from '../protocol.ts'
|
|
17
|
+
import type { EgressInfo, RemoteConnectionStatus } from '../protocol.ts'
|
|
18
18
|
|
|
19
19
|
export type ConnectionState = 'ok' | 'error' | 'idle'
|
|
20
20
|
|
|
@@ -59,6 +59,51 @@ export function connectionLabelKey(state: ConnectionState): string {
|
|
|
59
59
|
return 'connection.idle'
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* One route, as the localized sentence fragment the chip prints.
|
|
64
|
+
*
|
|
65
|
+
* Pure and exported so the jsdom gate can pin the copy without a browser and the
|
|
66
|
+
* three route kinds cannot drift into three different wordings. The Host sends
|
|
67
|
+
* the hop (`host:port` / the jump alias), never a sentence: the wording is UI
|
|
68
|
+
* copy and has to exist in both languages.
|
|
69
|
+
*/
|
|
70
|
+
export function describeEgress(egress: EgressInfo, t: (key: string) => string): string {
|
|
71
|
+
if (egress.kind === 'jump') return t('connection.egressJump').replace('{jump}', egress.viaAlias ?? egress.detail)
|
|
72
|
+
if (egress.kind === 'proxy') {
|
|
73
|
+
const template = egress.proxyKind === 'socks5' ? t('connection.egressSocks5') : t('connection.egressHttp')
|
|
74
|
+
return template.replace('{proxy}', egress.detail)
|
|
75
|
+
}
|
|
76
|
+
return t('connection.egressDirect').replace('{target}', egress.detail)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The tooltip line that answers "did this really go through the jump host?".
|
|
81
|
+
*
|
|
82
|
+
* The ACTUAL egress of the live connection wins. With nothing dialed the
|
|
83
|
+
* CONFIGURED route is shown and LABELLED as such, so a configuration can never
|
|
84
|
+
* be read as evidence about a connection — that distinction is the whole point
|
|
85
|
+
* (a host edited to use a jump host keeps serving on its old direct link until
|
|
86
|
+
* the old connection is dropped). A configured route that cannot be used says
|
|
87
|
+
* why instead of reading healthy.
|
|
88
|
+
*/
|
|
89
|
+
export function egressTitleLine(
|
|
90
|
+
connection: Pick<ConnectionView, 'egress' | 'configured'>,
|
|
91
|
+
t: (key: string) => string,
|
|
92
|
+
): string | undefined {
|
|
93
|
+
if (connection.egress !== undefined) {
|
|
94
|
+
return t('connection.egress').replace('{egress}', describeEgress(connection.egress, t))
|
|
95
|
+
}
|
|
96
|
+
const configured = connection.configured
|
|
97
|
+
if (configured === undefined) return undefined
|
|
98
|
+
const line = t('connection.egressConfigured').replace('{egress}', describeEgress(configured, t))
|
|
99
|
+
return configured.problem === undefined
|
|
100
|
+
? line
|
|
101
|
+
: // No separator space here: the two copies carry their own (zh uses a
|
|
102
|
+
// full-width bracket, en a leading space), so the punctuation stays right
|
|
103
|
+
// in both languages.
|
|
104
|
+
`${line}${t('connection.egressProblem').replace('{problem}', configured.problem)}`
|
|
105
|
+
}
|
|
106
|
+
|
|
62
107
|
/** What the UI renders for one alias. */
|
|
63
108
|
export interface ConnectionView {
|
|
64
109
|
alias: string
|
|
@@ -71,6 +116,13 @@ export interface ConnectionView {
|
|
|
71
116
|
okAt?: number
|
|
72
117
|
/** A pooled SSH connection is open right now (diagnostic detail only). */
|
|
73
118
|
open: boolean
|
|
119
|
+
/**
|
|
120
|
+
* The route the LIVE connection was opened through. Evidence, not intention:
|
|
121
|
+
* it is what the Host's pool reports for the connection it is holding.
|
|
122
|
+
*/
|
|
123
|
+
egress?: EgressInfo
|
|
124
|
+
/** The route the stored configuration resolves to (no live connection). */
|
|
125
|
+
configured?: EgressInfo
|
|
74
126
|
/**
|
|
75
127
|
* Client time of the last locally noted failure. A poll that still reports
|
|
76
128
|
* the older success must not clear an error the page just saw.
|
|
@@ -125,12 +177,28 @@ function refreshSnapshot(): void {
|
|
|
125
177
|
|| (next !== undefined && snapshot !== undefined
|
|
126
178
|
&& next.alias === snapshot.alias && next.state === snapshot.state
|
|
127
179
|
&& next.error === snapshot.error && next.errorAt === snapshot.errorAt
|
|
128
|
-
&& next.okAt === snapshot.okAt && next.open === snapshot.open && next.notedAt === snapshot.notedAt
|
|
180
|
+
&& next.okAt === snapshot.okAt && next.open === snapshot.open && next.notedAt === snapshot.notedAt
|
|
181
|
+
&& sameEgress(next.egress, snapshot.egress) && sameEgress(next.configured, snapshot.configured))
|
|
129
182
|
if (same) return
|
|
130
183
|
snapshot = next
|
|
131
184
|
notify()
|
|
132
185
|
}
|
|
133
186
|
|
|
187
|
+
/**
|
|
188
|
+
* Field-wise equality for one reported route.
|
|
189
|
+
*
|
|
190
|
+
* The Host re-sends the object on every poll and this module rebuilds the view,
|
|
191
|
+
* so identity says nothing: a fresh-but-equal egress must not wake subscribers
|
|
192
|
+
* (that would repaint the whole surface every 5 s), while a real change — the
|
|
193
|
+
* route the connection took — must.
|
|
194
|
+
*/
|
|
195
|
+
function sameEgress(a: EgressInfo | undefined, b: EgressInfo | undefined): boolean {
|
|
196
|
+
if (a === b) return true
|
|
197
|
+
if (a === undefined || b === undefined) return false
|
|
198
|
+
return a.kind === b.kind && a.detail === b.detail && a.viaAlias === b.viaAlias
|
|
199
|
+
&& a.source === b.source && a.proxyKind === b.proxyKind && a.problem === b.problem
|
|
200
|
+
}
|
|
201
|
+
|
|
134
202
|
/** Point the view at the workspace the user is looking at. */
|
|
135
203
|
export function setActiveConnectionAlias(alias: string): void {
|
|
136
204
|
if (alias === activeAlias) return
|
|
@@ -166,6 +234,8 @@ export function applyConnectionStatuses(list: readonly RemoteConnectionStatus[])
|
|
|
166
234
|
...(item.errorAt === undefined ? {} : { errorAt: item.errorAt }),
|
|
167
235
|
...(item.okAt === undefined ? {} : { okAt: item.okAt }),
|
|
168
236
|
open: item.open,
|
|
237
|
+
...(item.egress === undefined ? {} : { egress: item.egress }),
|
|
238
|
+
...(item.configured === undefined ? {} : { configured: item.configured }),
|
|
169
239
|
})
|
|
170
240
|
}
|
|
171
241
|
refreshSnapshot()
|
|
@@ -186,6 +256,10 @@ export function noteConnectionFailure(alias: string, error: unknown): void {
|
|
|
186
256
|
errorAt: Date.now(),
|
|
187
257
|
...(prev?.okAt === undefined ? {} : { okAt: prev.okAt }),
|
|
188
258
|
open: prev?.open ?? false,
|
|
259
|
+
// The route the DEAD connection used is not carried over (it is evidence
|
|
260
|
+
// about a link that just failed); the configured route still describes what
|
|
261
|
+
// the next attempt will take, so it stays until the Host answers.
|
|
262
|
+
...(prev?.configured === undefined ? {} : { configured: prev.configured }),
|
|
189
263
|
notedAt: Date.now(),
|
|
190
264
|
})
|
|
191
265
|
refreshSnapshot()
|