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
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
applyChangeSet,
|
|
30
30
|
bootstrap,
|
|
31
31
|
followSessionWorkspace,
|
|
32
|
+
openChangeDiff,
|
|
32
33
|
openRemoteFileInBinding,
|
|
33
34
|
refreshAll,
|
|
34
35
|
remoteOpenBindings,
|
|
@@ -36,13 +37,29 @@ import {
|
|
|
36
37
|
sessionRepoSubdir,
|
|
37
38
|
setFollowSession,
|
|
38
39
|
setView,
|
|
40
|
+
syncChangeSetStaleness,
|
|
39
41
|
useExplorer,
|
|
40
42
|
workspaceMatchesSession,
|
|
41
43
|
} from '../store.tsx'
|
|
42
44
|
import { bindingForChangedFile } from '../remote-file-open-target.ts'
|
|
43
45
|
import { useRemoteChatTarget } from '../use-remote-chat-target.ts'
|
|
44
|
-
import type { RemoteChangedFile, RemoteChangesSummary } from '../../protocol.ts'
|
|
45
|
-
import {
|
|
46
|
+
import type { RemoteChangedFile, RemoteChangesDiff, RemoteChangesSummary, RemoteChangesTurnView } from '../../protocol.ts'
|
|
47
|
+
import type { ChangeSet } from './model.ts'
|
|
48
|
+
import { canShowChangeDiff } from './session-diff.ts'
|
|
49
|
+
import { changeSetFromDiff, diffNoticeKey, type DiffNotice } from './diff-outcome.ts'
|
|
50
|
+
import {
|
|
51
|
+
CHANGE_SCOPE_STORAGE_KEY,
|
|
52
|
+
parseChangeScope,
|
|
53
|
+
scopeAfterOutcome,
|
|
54
|
+
serializeChangeScope,
|
|
55
|
+
turnOutcomeOf,
|
|
56
|
+
turnScopeAvailable,
|
|
57
|
+
turnFullyReverted,
|
|
58
|
+
visibleTurnRows,
|
|
59
|
+
type ChangeScope,
|
|
60
|
+
} from './turn-view.ts'
|
|
61
|
+
import { loadTurnRevertedPaths } from './turn-reverted.ts'
|
|
62
|
+
import { loadStillInFlight, shouldForceRefresh } from './freshness.ts'
|
|
46
63
|
import {
|
|
47
64
|
isReviewed,
|
|
48
65
|
nextUnreviewed,
|
|
@@ -69,10 +86,12 @@ const POLL_MS = 3000
|
|
|
69
86
|
* "pending" badge), so the poll cannot simply stop: the header would then keep
|
|
70
87
|
* describing an older turn. A fifth of the cadence keeps it honest without
|
|
71
88
|
* paying a loopback POST (and, through the host's ledger `touch`, a tracked
|
|
72
|
-
* git scan every 30 s
|
|
89
|
+
* git scan every 5–30 s — adaptive, see `selfHealMaxAge` in the recorder) four
|
|
90
|
+
* times a second-old counter does not need.
|
|
73
91
|
*
|
|
74
92
|
* A HIDDEN page is different and skips the tick entirely: nothing on screen can
|
|
75
|
-
* change, and `visibilitychange`
|
|
93
|
+
* change, and `visibilitychange` + `focus` force one refresh when it is shown
|
|
94
|
+
* again (see `shouldForceRefresh`).
|
|
76
95
|
* Manual ⟳ (`load(true)`) and the first read are never gated.
|
|
77
96
|
*/
|
|
78
97
|
const FOLDED_POLL_SKIP = 5
|
|
@@ -106,6 +125,9 @@ const INVISIBLE_POLL_SKIP = 10
|
|
|
106
125
|
*/
|
|
107
126
|
const REVIEW_STORAGE_PREFIX = 'rvs.changes.reviewed.'
|
|
108
127
|
|
|
128
|
+
/** 空集合:非本轮模式不该每次渲染都分配一个新的 Set(`visibleTurnRows` 只读它)。 */
|
|
129
|
+
const EMPTY_REVERTED_PATHS: ReadonlySet<string> = new Set()
|
|
130
|
+
|
|
109
131
|
/**
|
|
110
132
|
* How many polls between two follow retries (5 × 3 s = one probe every 15 s).
|
|
111
133
|
*
|
|
@@ -154,6 +176,39 @@ function loadReviewed(sessionId: string | undefined): Record<string, 1> {
|
|
|
154
176
|
}
|
|
155
177
|
}
|
|
156
178
|
|
|
179
|
+
/** 读上次选择的作用域;读不出来就是默认的会话累计。 */
|
|
180
|
+
function loadScope(): ChangeScope {
|
|
181
|
+
try {
|
|
182
|
+
return parseChangeScope(window.localStorage.getItem(CHANGE_SCOPE_STORAGE_KEY))
|
|
183
|
+
} catch {
|
|
184
|
+
// Private mode / disabled storage: the choice simply does not persist.
|
|
185
|
+
return 'session'
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function saveScope(scope: ChangeScope): void {
|
|
190
|
+
try {
|
|
191
|
+
window.localStorage.setItem(CHANGE_SCOPE_STORAGE_KEY, serializeChangeScope(scope))
|
|
192
|
+
} catch {
|
|
193
|
+
// Same trade as the review marks: persistence is the only thing lost.
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 「本轮 #N · HH:MM」——时间用本机时区的时:分,标签短到能和文件数并排。
|
|
199
|
+
*
|
|
200
|
+
* 带上 `#N` 是刻意的:`turnView` 描述的是**最近一个已完成轮次**,而面板的
|
|
201
|
+
* `summary.turn` 可能已经翻到下一轮(那一轮还没结束)。数字不一致时用户看到的是
|
|
202
|
+
* "本轮还在跑",而不是一份被悄悄标错的列表。
|
|
203
|
+
*/
|
|
204
|
+
function turnTitle(t: (key: string) => string, view: RemoteChangesTurnView): string {
|
|
205
|
+
const at = new Date(view.at)
|
|
206
|
+
const time = Number.isNaN(at.getTime())
|
|
207
|
+
? ''
|
|
208
|
+
: `${String(at.getHours()).padStart(2, '0')}:${String(at.getMinutes()).padStart(2, '0')}`
|
|
209
|
+
return t('changes.turnTitle').replace('{turn}', String(view.turn)).replace('{time}', time)
|
|
210
|
+
}
|
|
211
|
+
|
|
157
212
|
export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
158
213
|
const explorer = useExplorer()
|
|
159
214
|
// The dock is a second surface of the same store as the explorer, and it can
|
|
@@ -179,6 +234,20 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
179
234
|
// push the composer off the screen.
|
|
180
235
|
const [collapsed, setCollapsed] = useState(true)
|
|
181
236
|
const [busy, setBusy] = useState<string | undefined>(undefined)
|
|
237
|
+
/**
|
|
238
|
+
* 上一次点行留下的"这份 diff 是哪一种结局"的说明(二进制 / 读不到 / 已被改回 /
|
|
239
|
+
* 只给了前缀)。一次只留一条:它描述的就是刚才那一次点击,换一行就该换说法。
|
|
240
|
+
*/
|
|
241
|
+
const [diffNotice, setDiffNotice] = useState<{ path: string; notice: DiffNotice } | undefined>(undefined)
|
|
242
|
+
/**
|
|
243
|
+
* 面板按哪条轴列改动:会话累计(默认)还是最近一个已完成轮次。
|
|
244
|
+
*
|
|
245
|
+
* 选择存在浏览器本地(`CHANGE_SCOPE_STORAGE_KEY`):它描述的是"我想怎么看",
|
|
246
|
+
* 不是远端事实。默认必须是 `session` —— 那是这个面板一直以来的语义。
|
|
247
|
+
*/
|
|
248
|
+
const [scope, setScope] = useState<ChangeScope>(loadScope)
|
|
249
|
+
/** 本轮模式下这次点击"为什么没画标记 / 为什么回退"的那句话(不静默)。 */
|
|
250
|
+
const [scopeNote, setScopeNote] = useState<{ key: string; detail?: string } | undefined>(undefined)
|
|
182
251
|
/** This session's local review marks (see `review-state.ts`). */
|
|
183
252
|
const [reviewed, setReviewed] = useState<Record<string, 1>>(() => loadReviewed(sessionId))
|
|
184
253
|
/**
|
|
@@ -194,6 +263,22 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
194
263
|
/** 行元素(键同游标),供「跳到下一个未审阅」把目标滚进视野。 */
|
|
195
264
|
const rowRefs = useRef(new Map<string, HTMLDivElement>())
|
|
196
265
|
const alive = useRef(true)
|
|
266
|
+
/**
|
|
267
|
+
* 回到页面时"强制刷新一次"的去抖时间戳(见 `shouldForceRefresh`)。
|
|
268
|
+
*
|
|
269
|
+
* 用 ref 而不是 state:它只影响下一次该不该 force,不需要触发渲染;effect 因
|
|
270
|
+
* `collapsed`/`load` 重建时也必须继续记住上一次强制刷新的时刻。
|
|
271
|
+
*/
|
|
272
|
+
const lastForceAt = useRef<number | undefined>(undefined)
|
|
273
|
+
/** 在飞的 `list` 请求数:回到页面时若已有请求在跑,就不再叠一次 force。 */
|
|
274
|
+
const loadInFlight = useRef(0)
|
|
275
|
+
/**
|
|
276
|
+
* 在飞请求的起始时刻(第一个请求开始记、最后一个结束清)。
|
|
277
|
+
*
|
|
278
|
+
* 只看计数是不够的:某次 fetch 永远不 settle 会让"在飞就跳过"变成永久跳过,
|
|
279
|
+
* 回到页面再也不强制刷新。`loadStillInFlight` 用 60s 上限把它当失败处理。
|
|
280
|
+
*/
|
|
281
|
+
const loadInFlightAt = useRef<number | undefined>(undefined)
|
|
197
282
|
// Mirrors "the panel renders something" for the poll tick: adding that as an
|
|
198
283
|
// effect dependency would rebuild the interval (and pay a re-read) every time
|
|
199
284
|
// the panel appears or disappears, which is not what the cadence is about.
|
|
@@ -217,20 +302,41 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
217
302
|
// unique-candidate probe); a foreign directory never is.
|
|
218
303
|
const repoSubdirOf = (): string => sessionRepoSubdir(sessionId)
|
|
219
304
|
|
|
220
|
-
|
|
305
|
+
/**
|
|
306
|
+
* Read the ledger once.
|
|
307
|
+
*
|
|
308
|
+
* @param force - `⟳` semantics: the host scans tracked files now AND re-arms the
|
|
309
|
+
* slow new-file walk (expensive, but the user asked for it).
|
|
310
|
+
* @param trackedOnly - "back to the page" semantics: the host refreshes tracked
|
|
311
|
+
* files now but leaves the slow walk alone (its cadence and write-off verdict
|
|
312
|
+
* must not be re-armed on every window focus — see `RemoteChangesListRequest`).
|
|
313
|
+
* NOTE: both flags only SCHEDULE the rescan; this response still carries the
|
|
314
|
+
* previous summary, and the fresh one arrives on the next poll (≤ 3s).
|
|
315
|
+
*/
|
|
316
|
+
const load = useCallback(async (force = false, trackedOnly = false): Promise<void> => {
|
|
221
317
|
if (sessionId === undefined || sessionId === '') return
|
|
222
318
|
const asked = sessionId
|
|
319
|
+
if (loadInFlight.current === 0) loadInFlightAt.current = Date.now()
|
|
320
|
+
loadInFlight.current += 1
|
|
223
321
|
try {
|
|
224
|
-
const next = await api.changes.list(asked, force, repoSubdirOf())
|
|
322
|
+
const next = await api.changes.list(asked, force, repoSubdirOf(), trackedOnly)
|
|
225
323
|
// Two guards: the panel may be gone, and the user may have switched
|
|
226
324
|
// sessions while this was in flight — a late answer for the old session
|
|
227
325
|
// must not be filed under the new one.
|
|
228
326
|
if (!alive.current || currentSession.current !== asked) return
|
|
229
327
|
setData({ id: asked, summary: next })
|
|
230
328
|
setError(undefined)
|
|
329
|
+
// 新的统计列表是"屏幕上那批标记还算不算数"的唯一证据:行数/状态变了或文件
|
|
330
|
+
// 从列表消失,就给对应标签页打既有那张「位置已过期」。不发起远端读。
|
|
331
|
+
if (next !== null) {
|
|
332
|
+
syncChangeSetStaleness(asked, next.files, next.truncated === true, next.at, next.turnView)
|
|
333
|
+
}
|
|
231
334
|
} catch (problem) {
|
|
232
335
|
if (!alive.current || currentSession.current !== asked) return
|
|
233
336
|
setError(problem instanceof Error ? problem.message : String(problem))
|
|
337
|
+
} finally {
|
|
338
|
+
loadInFlight.current -= 1
|
|
339
|
+
if (loadInFlight.current === 0) loadInFlightAt.current = undefined
|
|
234
340
|
}
|
|
235
341
|
}, [sessionId])
|
|
236
342
|
const summary = data !== null && data.id === sessionId ? data.summary : null
|
|
@@ -256,15 +362,46 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
256
362
|
if (skip > 1 && ticks % skip !== 0) return
|
|
257
363
|
void load()
|
|
258
364
|
}, POLL_MS)
|
|
365
|
+
/**
|
|
366
|
+
* 回到页面 / 窗口重新获得焦点:请求宿主**立即重扫一次**。
|
|
367
|
+
*
|
|
368
|
+
* 与点 `⟳` 的区别是**代价**:这里传 `trackedOnly`,宿主只重扫 tracked 文件,
|
|
369
|
+
* 不重置慢扫描的节流、也不重新武装被写掉的 `git ls-files --others`(参考树 11s、
|
|
370
|
+
* 冷树分钟级)——"回到页面"可以每几秒发生一次,点 `⟳` 是一次明确的人工动作。
|
|
371
|
+
*
|
|
372
|
+
* 三条防抖一起上:
|
|
373
|
+
* - `shouldForceRefresh` 的 5s 去抖(点回窗口/切标签会连续触发 visibility 与
|
|
374
|
+
* focus 两个事件);
|
|
375
|
+
* - 页面仍隐藏时不 force(隐藏期间本来就不轮询);
|
|
376
|
+
* - 已有 `list` 请求在飞时跳过(它马上就会带回新数据,再叠一次只是浪费);
|
|
377
|
+
* 在飞状态按 60s 上限处理(`loadStillInFlight`),一次挂住的请求不能让
|
|
378
|
+
* force 永久失效。
|
|
379
|
+
*
|
|
380
|
+
* 注意:这次调用只是**安排**宿主重扫,返回的仍是上一次的摘要;新摘要要等下一次
|
|
381
|
+
* 轮询(≤ 3s)才回来(NIT-5 已在 README 写明)。
|
|
382
|
+
*/
|
|
383
|
+
const forceRefresh = (): void => {
|
|
384
|
+
const now = Date.now()
|
|
385
|
+
if (!shouldForceRefresh({
|
|
386
|
+
now,
|
|
387
|
+
lastForceAt: lastForceAt.current,
|
|
388
|
+
visible: !document.hidden,
|
|
389
|
+
inFlight: loadStillInFlight(now, loadInFlightAt.current),
|
|
390
|
+
})) return
|
|
391
|
+
lastForceAt.current = now
|
|
392
|
+
void load(false, true)
|
|
393
|
+
}
|
|
259
394
|
// Shown again, or unfolded: read at once instead of waiting for the next
|
|
260
395
|
// tick (a folded panel may be up to 15 s stale by design). `collapsed` is a
|
|
261
396
|
// dependency, so folding/unfolding also re-runs this effect and reloads.
|
|
262
|
-
const wake = (): void => { if (!document.hidden)
|
|
397
|
+
const wake = (): void => { if (!document.hidden) forceRefresh() }
|
|
263
398
|
document.addEventListener('visibilitychange', wake)
|
|
399
|
+
window.addEventListener('focus', forceRefresh)
|
|
264
400
|
return () => {
|
|
265
401
|
alive.current = false
|
|
266
402
|
window.clearInterval(timer)
|
|
267
403
|
document.removeEventListener('visibilitychange', wake)
|
|
404
|
+
window.removeEventListener('focus', forceRefresh)
|
|
268
405
|
}
|
|
269
406
|
}, [load, collapsed])
|
|
270
407
|
|
|
@@ -359,7 +496,71 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
359
496
|
void followSessionWorkspace({ sessionId, alias: summary.alias, remoteRoot: summary.root })
|
|
360
497
|
}, [sessionId, summary, chatTarget.sessionId])
|
|
361
498
|
|
|
362
|
-
|
|
499
|
+
/**
|
|
500
|
+
* 会话累计的行永远是这份 summary 的 `files`;本轮是 `turnView.files`。
|
|
501
|
+
*
|
|
502
|
+
* `turnMode` 还要求 Host 真的给了可用的一轮(`turn > 0`):没关闭过轮次、或者
|
|
503
|
+
* 客户端连的是更老的 Host 时,作用域选择自动退回会话累计 —— 面板不能因为一个
|
|
504
|
+
* 存下来的偏好就空着。
|
|
505
|
+
*/
|
|
506
|
+
const sessionFiles = useMemo(() => summary?.files ?? [], [summary])
|
|
507
|
+
const turnView = summary?.turnView
|
|
508
|
+
const turnFiles = useMemo(() => turnView?.files ?? [], [turnView])
|
|
509
|
+
const turnMode = scope === 'turn' && turnScopeAvailable(turnView)
|
|
510
|
+
/**
|
|
511
|
+
* 「本轮里这个文件已被撤销」的客户端记账(见 `changes/turn-reverted.ts`)。
|
|
512
|
+
*
|
|
513
|
+
* 每次渲染**现读**(读操作,不写):撤销发生在 store 里,store 一定会 patch 快照让
|
|
514
|
+
* 面板重渲染,所以这里不需要额外的订阅/事件,重渲染时就能看到最新记录;宿主冻结的
|
|
515
|
+
* `turnView` 本身永远不变。会话累计模式不读这个存储。
|
|
516
|
+
*/
|
|
517
|
+
const revertedPaths = turnMode && turnView !== undefined && sessionId !== undefined
|
|
518
|
+
? loadTurnRevertedPaths(sessionId, turnView.turn)
|
|
519
|
+
: EMPTY_REVERTED_PATHS
|
|
520
|
+
/**
|
|
521
|
+
* 可见行:宿主冻结的行里去掉"本轮已撤销"的那些。文件数、`+a −b`、✓ 的分母、
|
|
522
|
+
* 「下一个未审阅」都必须用这一份,否则会留下"列表只剩一行、合计还是三行"的残影。
|
|
523
|
+
*/
|
|
524
|
+
const turnRows = turnMode ? visibleTurnRows(turnFiles, revertedPaths) : undefined
|
|
525
|
+
const files = turnMode ? (turnRows?.visible ?? []) : sessionFiles
|
|
526
|
+
/** 被隐藏的行数(仅本轮模式;>0 时面板给一句说明)。 */
|
|
527
|
+
const hiddenRows = turnRows?.hidden ?? 0
|
|
528
|
+
/**
|
|
529
|
+
* 「本轮改动已全部撤销」只有在视图完整时才成立:`truncated`(有行因上限/未知侧/
|
|
530
|
+
* 未校正被丢弃)或 `pending`(慢扫描还没落地)时,"可见行为 0"只证明"看到的都撤了",
|
|
531
|
+
* 不证明"这一轮已经没有改动"——说出口会与同屏的「视图不完整 / 还在等扫描」矛盾。
|
|
532
|
+
*/
|
|
533
|
+
const allReverted = turnMode && turnView !== undefined && turnFullyReverted({
|
|
534
|
+
visible: files.length,
|
|
535
|
+
hidden: hiddenRows,
|
|
536
|
+
...(turnView.truncated === true ? { truncated: true as const } : {}),
|
|
537
|
+
...(turnView.pending === true ? { pending: true as const } : {}),
|
|
538
|
+
})
|
|
539
|
+
/**
|
|
540
|
+
* 审阅标记是按"行数 + 状态"建键的,两种视图对同一文件给出的数字按定义不同。
|
|
541
|
+
*
|
|
542
|
+
* 清理/切换标记时按**两份列表的并集**来判:只用当前视图那张表,切一次作用域就会
|
|
543
|
+
* 把另一边的 ✓ 全删掉,而它们描述的是另一条轴上仍然有效的审阅。
|
|
544
|
+
*/
|
|
545
|
+
const reviewable = useMemo(
|
|
546
|
+
() => (turnFiles.length === 0 ? sessionFiles : [...sessionFiles, ...turnFiles]),
|
|
547
|
+
[sessionFiles, turnFiles],
|
|
548
|
+
)
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* 切换作用域。
|
|
552
|
+
*
|
|
553
|
+
* @param keepNote - `stale` 回退时保留那句解释(见 `scopeAfterOutcome`):否则
|
|
554
|
+
* 用户只会看到列表静默换轴(审核 M1)。其余切换照常清掉上一条"为什么没标记"的
|
|
555
|
+
* 说明,它描述的是上一次点击、且属于另一个轴。
|
|
556
|
+
*/
|
|
557
|
+
const switchScope = useCallback((next: ChangeScope, keepNote = false): void => {
|
|
558
|
+
setScope(next)
|
|
559
|
+
saveScope(next)
|
|
560
|
+
if (!keepNote) setScopeNote(undefined)
|
|
561
|
+
setDiffNotice(undefined)
|
|
562
|
+
setCursorKey(undefined)
|
|
563
|
+
}, [])
|
|
363
564
|
|
|
364
565
|
/**
|
|
365
566
|
* Resolve the binding a row belongs to, with one refresh for a cold page.
|
|
@@ -378,6 +579,76 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
378
579
|
return binding
|
|
379
580
|
}, [summary])
|
|
380
581
|
|
|
582
|
+
/**
|
|
583
|
+
* Paint one row's comparison into the editor (both scopes end up here).
|
|
584
|
+
*
|
|
585
|
+
* Everything after `diff` is scope-agnostic on purpose: the editor only ever
|
|
586
|
+
* receives hunks, the review marks only ever carry counts, and the revert
|
|
587
|
+
* coordinates are the ones the comparison came from — so the two axes differ in
|
|
588
|
+
* WHICH comparison is fetched, not in how it is shown.
|
|
589
|
+
*
|
|
590
|
+
* @param notice - a conclusion the panel must state although no marks will be
|
|
591
|
+
* painted (`oversized` / `binary` rows: the comparison was not even fetched).
|
|
592
|
+
* @param quiet - 调用方已经用 `scopeNote` 说清了这次点击的处置(例如「本轮只有统计」),
|
|
593
|
+
* 不要再叠一句 `diff-outcome` 的结论:两句会互相拆台("没有块标记" vs "远端读不到")。
|
|
594
|
+
*/
|
|
595
|
+
const attachMarks = useCallback(async (
|
|
596
|
+
file: RemoteChangedFile,
|
|
597
|
+
diff: RemoteChangesDiff | null,
|
|
598
|
+
stamp: string,
|
|
599
|
+
origin: { scope: ChangeScope; turn?: number },
|
|
600
|
+
notice?: DiffNotice,
|
|
601
|
+
quiet = false,
|
|
602
|
+
): Promise<void> => {
|
|
603
|
+
if (sessionId === undefined || summary === null) return
|
|
604
|
+
// 行数/状态/块标识一起带下去:面板的轮询要用行数判断这批标记是否过期
|
|
605
|
+
// (`syncChangeSetStaleness`),编辑器要用**远端绝对路径**命名「确认保留」
|
|
606
|
+
// 的块。被字节上限扣下的 diff 不建标记(审核 M2),只给结论。
|
|
607
|
+
const built = changeSetFromDiff(diff, stamp, {
|
|
608
|
+
path: file.path,
|
|
609
|
+
...(file.status === undefined ? {} : { status: file.status }),
|
|
610
|
+
})
|
|
611
|
+
const set: ChangeSet = built.set
|
|
612
|
+
// 二进制 / 过大 / 读不到 / 已被改回 / 截断:屏幕上不会出现标记,必须当面说清
|
|
613
|
+
// 是哪一种,而不是留下一片空白让人以为"没改动"。
|
|
614
|
+
if (notice !== undefined) setDiffNotice({ path: file.path, notice })
|
|
615
|
+
else if (!quiet && built.notice !== undefined) setDiffNotice({ path: file.path, notice: built.notice })
|
|
616
|
+
// Resolved by the session's REMOTE root, never by the alias alone: one
|
|
617
|
+
// alias carries several bindings (two workspaces can live on one alias),
|
|
618
|
+
// and the alias-only form picked whichever came first —
|
|
619
|
+
// the file opened while the tree and the selector stayed on the other
|
|
620
|
+
// workspace. That was the reported bug.
|
|
621
|
+
const binding = await bindingOf(file)
|
|
622
|
+
if (binding === undefined) {
|
|
623
|
+
explorer.info(t('changes.noWorkspace'))
|
|
624
|
+
return
|
|
625
|
+
}
|
|
626
|
+
openRemoteFileInBinding(binding.id, file.path, set.hunks[0] === undefined ? {} : { line: set.hunks[0] })
|
|
627
|
+
// The tab id is deterministic (store.openFile builds it the same way), so
|
|
628
|
+
// the marks can be attached without waiting for the file read to settle.
|
|
629
|
+
const tabId = `file:${binding.alias}:${file.path}`
|
|
630
|
+
applyChangeSet(tabId, set)
|
|
631
|
+
// Remember WHERE these marks came from, once: the revert coordinates are
|
|
632
|
+
// read back from here (`publishableUndoOrigin`) instead of from the last
|
|
633
|
+
// summary this panel happened to render. No real hunk = no revert target,
|
|
634
|
+
// so a binary/failed diff forgets the previous provenance instead of
|
|
635
|
+
// leaving an older one around.
|
|
636
|
+
// 被字节上限扣下的 diff 没有可撤销的补丁(每个 hunk patch 都是 ''):既不能
|
|
637
|
+
// 标标记,也不能留 provenance,否则悬浮撤销会指向一次注定失败的远端写。
|
|
638
|
+
if (diff !== null && diff.kind === 'text' && diff.truncated !== true && diff.hunks.length > 0) {
|
|
639
|
+
rememberChangeOrigin(tabId, {
|
|
640
|
+
sessionId,
|
|
641
|
+
bindingId: binding.id,
|
|
642
|
+
alias: binding.alias,
|
|
643
|
+
root: summary.root,
|
|
644
|
+
scope: origin.scope,
|
|
645
|
+
...(origin.turn === undefined ? {} : { turn: origin.turn }),
|
|
646
|
+
})
|
|
647
|
+
} else {
|
|
648
|
+
forgetChangeOrigin(tabId)
|
|
649
|
+
}
|
|
650
|
+
}, [bindingOf, explorer, sessionId, summary, t])
|
|
651
|
+
|
|
381
652
|
/** Open one listed file in the remote editor with its change marks. */
|
|
382
653
|
const openChanged = useCallback(async (file: RemoteChangedFile): Promise<void> => {
|
|
383
654
|
if (sessionId === undefined || summary === null) return
|
|
@@ -386,44 +657,86 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
386
657
|
// instead of from wherever the last jump happened to stop.
|
|
387
658
|
setCursorKey(reviewKeyOf(file))
|
|
388
659
|
setBusy(file.path)
|
|
660
|
+
setDiffNotice(undefined)
|
|
661
|
+
setScopeNote(undefined)
|
|
389
662
|
try {
|
|
390
|
-
|
|
663
|
+
if (turnMode && turnView !== undefined) {
|
|
664
|
+
const turnOrigin = { scope: 'turn' as const, turn: turnView.turn }
|
|
665
|
+
// The stamp carries the axis and the turn: a saved turn comparison and a
|
|
666
|
+
// session comparison of the same file are different data.
|
|
667
|
+
const turnStamp = `${file.path}@turn${turnView.turn}@${turnView.at}`
|
|
668
|
+
/**
|
|
669
|
+
* 只有统计的一轮(内容超出内存预算 / 文件上限):不发请求,打开文件并说明
|
|
670
|
+
* 原因。列表行已经给出真实增删数,但没有可画的 hunk,也没有可撤销的补丁。
|
|
671
|
+
*/
|
|
672
|
+
if (turnView.cached !== true) {
|
|
673
|
+
setScopeNote({
|
|
674
|
+
key: 'changes.turnStatsOnly',
|
|
675
|
+
...(turnView.reason === undefined ? {} : { detail: turnView.reason }),
|
|
676
|
+
})
|
|
677
|
+
await attachMarks(file, null, turnStamp, turnOrigin, undefined, true)
|
|
678
|
+
return
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* 二进制/过大行与会话视图同一套结论,连比较都不取(审核 M1/M2):这类行的
|
|
682
|
+
* 计数被 Host 钉成 0/0,取了行级比较只会得到一份永远对不上的数字。
|
|
683
|
+
*/
|
|
684
|
+
if (file.binary === true) {
|
|
685
|
+
await attachMarks(file, null, turnStamp, turnOrigin, 'binary')
|
|
686
|
+
return
|
|
687
|
+
}
|
|
688
|
+
if (file.oversized === true) {
|
|
689
|
+
await attachMarks(file, null, turnStamp, turnOrigin, 'oversized')
|
|
690
|
+
return
|
|
691
|
+
}
|
|
692
|
+
const answer = await api.changes.turnDiff(sessionId, file.path, repoSubdirOf())
|
|
693
|
+
if (!alive.current) return
|
|
694
|
+
/**
|
|
695
|
+
* 四种结局都在这里定:画本轮 hunk / 文件在本轮之后又变了(回退会话累计)/
|
|
696
|
+
* 没有可画的内容(说明原因)/ 二进制。判定本身是纯函数(`turn-view.ts`)。
|
|
697
|
+
*/
|
|
698
|
+
const outcome = turnOutcomeOf(answer, turnView)
|
|
699
|
+
if (outcome.action === 'fallback') {
|
|
700
|
+
// Switch FIRST and keep the note, then say why (review M1): the old
|
|
701
|
+
// order cleared the very sentence that explains the switch.
|
|
702
|
+
const next = scopeAfterOutcome(outcome, scope)
|
|
703
|
+
switchScope(next.scope, next.keepNote)
|
|
704
|
+
setScopeNote({ key: outcome.noteKey })
|
|
705
|
+
// …and fall through to the session comparison below, in this same click.
|
|
706
|
+
} else if (outcome.action === 'closed') {
|
|
707
|
+
setScopeNote({
|
|
708
|
+
key: outcome.noteKey,
|
|
709
|
+
...(outcome.detail === undefined ? {} : { detail: outcome.detail }),
|
|
710
|
+
})
|
|
711
|
+
await attachMarks(file, null, turnStamp, turnOrigin, undefined, true)
|
|
712
|
+
return
|
|
713
|
+
} else if (outcome.action === 'binary') {
|
|
714
|
+
await attachMarks(file, null, turnStamp, turnOrigin, 'binary')
|
|
715
|
+
return
|
|
716
|
+
} else {
|
|
717
|
+
await attachMarks(file, outcome.diff, turnStamp, turnOrigin)
|
|
718
|
+
return
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* 过大的行(字节被增量扫描的上限扣下)**不做行级比较**(审核 M1)。
|
|
723
|
+
*
|
|
724
|
+
* 列表对这类行把计数钉成 0/0,而点开时 Host 走更大的读取预算、可能真的给出
|
|
725
|
+
* 一份比较 —— 那份比较的计数与列表行的 0/0 永远对不上,会引起 3 秒一次的假
|
|
726
|
+
* "位置已过期";极端情况下 before 侧仍被扣下,得到的是"整篇删除/新增"的假
|
|
727
|
+
* 差异。所以这里连 diff 都不取:不建标记、不说行数,只打开文件并说明原因。
|
|
728
|
+
*/
|
|
729
|
+
const oversized = file.oversized === true
|
|
730
|
+
const diff = oversized ? null : await api.changes.diff(sessionId, file.path, repoSubdirOf())
|
|
391
731
|
if (!alive.current) return
|
|
392
732
|
const stamp = `${file.path}@${summary.at}@${summary.turn}`
|
|
393
|
-
|
|
394
|
-
? changeSetFromHunks(diff.hunks, stamp, diff.patch)
|
|
395
|
-
: { ...EMPTY_CHANGE_SET, stamp }
|
|
396
|
-
// Resolved by the session's REMOTE root, never by the alias alone: one
|
|
397
|
-
// alias carries several bindings (two workspaces can live on one alias),
|
|
398
|
-
// and the alias-only form picked whichever came first —
|
|
399
|
-
// the file opened while the tree and the selector stayed on the other
|
|
400
|
-
// workspace. That was the reported bug.
|
|
401
|
-
const binding = await bindingOf(file)
|
|
402
|
-
if (binding === undefined) {
|
|
403
|
-
explorer.info(t('changes.noWorkspace'))
|
|
404
|
-
return
|
|
405
|
-
}
|
|
406
|
-
openRemoteFileInBinding(binding.id, file.path, set.hunks[0] === undefined ? {} : { line: set.hunks[0] })
|
|
407
|
-
// The tab id is deterministic (store.openFile builds it the same way), so
|
|
408
|
-
// the marks can be attached without waiting for the file read to settle.
|
|
409
|
-
const tabId = `file:${binding.alias}:${file.path}`
|
|
410
|
-
applyChangeSet(tabId, set)
|
|
411
|
-
// Remember WHERE these marks came from, once: the revert coordinates are
|
|
412
|
-
// read back from here (`publishableUndoOrigin`) instead of from the last
|
|
413
|
-
// summary this panel happened to render. No real hunk = no revert target,
|
|
414
|
-
// so a binary/failed diff forgets the previous provenance instead of
|
|
415
|
-
// leaving an older one around.
|
|
416
|
-
if (diff !== null && diff.kind === 'text' && diff.hunks.length > 0) {
|
|
417
|
-
rememberChangeOrigin(tabId, { sessionId, bindingId: binding.id, alias: binding.alias, root: summary.root })
|
|
418
|
-
} else {
|
|
419
|
-
forgetChangeOrigin(tabId)
|
|
420
|
-
}
|
|
733
|
+
await attachMarks(file, diff, stamp, { scope: 'session' }, oversized ? 'oversized' : undefined)
|
|
421
734
|
} catch (problem) {
|
|
422
735
|
if (alive.current) explorer.info(`${t('changes.diffFailed')}: ${problem instanceof Error ? problem.message : String(problem)}`)
|
|
423
736
|
} finally {
|
|
424
737
|
if (alive.current) setBusy(undefined)
|
|
425
738
|
}
|
|
426
|
-
}, [
|
|
739
|
+
}, [attachMarks, explorer, scope, sessionId, summary, switchScope, t, turnMode, turnView])
|
|
427
740
|
|
|
428
741
|
/**
|
|
429
742
|
* Revert EVERYTHING this session did to one listed file.
|
|
@@ -450,15 +763,22 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
450
763
|
path: file.path,
|
|
451
764
|
display: file.display,
|
|
452
765
|
mode: file.revert,
|
|
766
|
+
// 本轮行上的"撤销该文件的全部改动"= 撤到上一轮关闭时;补丁由 Host 从
|
|
767
|
+
// 本轮缓存里给(`turnDiff`),不是会话基线那份。`turn` 让 store 在成功后把
|
|
768
|
+
// 这一行记成"本轮已撤销",面板据此隐藏它(宿主冻结的 delta 不动)。
|
|
769
|
+
...(turnMode
|
|
770
|
+
? { scope: 'turn' as const, ...(turnView === undefined ? {} : { turn: turnView.turn }) }
|
|
771
|
+
: {}),
|
|
453
772
|
})
|
|
454
773
|
} finally {
|
|
455
774
|
if (alive.current) setBusy(undefined)
|
|
456
775
|
}
|
|
457
|
-
}, [bindingOf, explorer, sessionId, summary, t])
|
|
776
|
+
}, [bindingOf, explorer, sessionId, summary, t, turnMode, turnView])
|
|
458
777
|
|
|
459
778
|
const toggleReviewed = useCallback((file: RemoteChangedFile): void => {
|
|
460
|
-
|
|
461
|
-
|
|
779
|
+
// 清理按两份列表的并集来(见 `reviewable`):切作用域不该删掉另一边的 ✓。
|
|
780
|
+
setReviewed(previous => toggleReviewedEntry(reviewable, previous, file))
|
|
781
|
+
}, [reviewable])
|
|
462
782
|
|
|
463
783
|
// Persist the marks whenever they change. A storage that refuses (private mode)
|
|
464
784
|
// must cost nothing but persistence — never a broken panel.
|
|
@@ -479,11 +799,11 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
479
799
|
// just restored from localStorage (and wrote the empty map back).
|
|
480
800
|
if (summary === null) return
|
|
481
801
|
setReviewed(previous => {
|
|
482
|
-
const next = pruneReviewed(
|
|
802
|
+
const next = pruneReviewed(reviewable, previous)
|
|
483
803
|
// A prune only ever removes entries, so equal length means "identical".
|
|
484
804
|
return Object.keys(next).length === Object.keys(previous).length ? previous : next
|
|
485
805
|
})
|
|
486
|
-
}, [
|
|
806
|
+
}, [reviewable, summary])
|
|
487
807
|
|
|
488
808
|
/**
|
|
489
809
|
* Bring the cursor's row into view.
|
|
@@ -520,24 +840,73 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
520
840
|
[files, reviewed, cursorKey],
|
|
521
841
|
)
|
|
522
842
|
|
|
843
|
+
/**
|
|
844
|
+
* 「查看差异」:把这一行打开成**只读并排 diff**(数据来自会话账本)。
|
|
845
|
+
*
|
|
846
|
+
* 与左键「打开」是两件事:打开是"进文件里看这一处",这里是"先把改前改后并排
|
|
847
|
+
* 看一遍",不改变编辑器里的标签页内容、也不写任何东西。`notice` 是这次比较
|
|
848
|
+
* 必须说清的话(截断/二进制/读不到/已无差异),由调用方渲染。
|
|
849
|
+
*/
|
|
850
|
+
const viewDiff = useCallback(async (file: RemoteChangedFile): Promise<void> => {
|
|
851
|
+
if (sessionId === undefined || summary === null) return
|
|
852
|
+
setBusy(file.path)
|
|
853
|
+
setDiffNotice(undefined)
|
|
854
|
+
try {
|
|
855
|
+
const binding = await bindingOf(file)
|
|
856
|
+
if (binding === undefined) {
|
|
857
|
+
explorer.info(t('changes.noWorkspace'))
|
|
858
|
+
return
|
|
859
|
+
}
|
|
860
|
+
const result = await openChangeDiff({
|
|
861
|
+
sessionId,
|
|
862
|
+
alias: binding.alias,
|
|
863
|
+
root: summary.root,
|
|
864
|
+
path: file.path,
|
|
865
|
+
display: file.display === '' ? file.path : file.display,
|
|
866
|
+
repoSubdir: repoSubdirOf(),
|
|
867
|
+
})
|
|
868
|
+
if (!alive.current) return
|
|
869
|
+
if (result.notice !== undefined) setDiffNotice({ path: file.path, notice: result.notice })
|
|
870
|
+
} catch (problem) {
|
|
871
|
+
if (alive.current) explorer.info(`${t('changes.diffFailed')}: ${problem instanceof Error ? problem.message : String(problem)}`)
|
|
872
|
+
} finally {
|
|
873
|
+
if (alive.current) setBusy(undefined)
|
|
874
|
+
}
|
|
875
|
+
}, [bindingOf, explorer, sessionId, summary, t])
|
|
876
|
+
|
|
523
877
|
const openRowMenu = useCallback((event: React.MouseEvent, file: RemoteChangedFile): void => {
|
|
524
878
|
event.preventDefault()
|
|
525
879
|
event.stopPropagation()
|
|
526
880
|
const cannotRevert = file.revert === undefined
|
|
881
|
+
/**
|
|
882
|
+
* 只有真的画得出两栏时才给这条:
|
|
883
|
+
* - 二进制/超大文件打开只会得到空视图;
|
|
884
|
+
* - **本轮视图只开文件**:「查看差异」读的是会话累计的账本,和行上的本轮行数
|
|
885
|
+
* 不是同一份比较,摆在这里只会让人以为这一轮的差异就是那两栏。
|
|
886
|
+
*/
|
|
887
|
+
const canDiff = canShowChangeDiff(file) && !turnMode
|
|
527
888
|
rowMenu.open(event.clientX, event.clientY, [
|
|
528
889
|
{ label: t('changes.menuOpen'), onSelect: () => { void openChanged(file) } },
|
|
890
|
+
{
|
|
891
|
+
label: t('changes.menuViewDiff'),
|
|
892
|
+
disabled: !canDiff,
|
|
893
|
+
...(canDiff ? {} : { hint: turnMode ? t('changes.turnDiffDisabled') : t('changes.diffNotPossible') }),
|
|
894
|
+
onSelect: () => { void viewDiff(file) },
|
|
895
|
+
},
|
|
529
896
|
{
|
|
530
897
|
label: file.revert === 'delete' ? t('changes.revertCreation') : t('changes.revertFile'),
|
|
531
898
|
danger: true,
|
|
532
899
|
disabled: cannotRevert,
|
|
533
|
-
|
|
900
|
+
// 本轮只保留反向补丁:新建文件在本轮**没有**撤销项,原因要说到"用哪条路"
|
|
901
|
+
// (切回会话累计或 SCM 面板),不是通用的"无法撤销"(审核 N2)。
|
|
902
|
+
...(cannotRevert ? { hint: turnMode ? t('changes.turnRevertNotPossible') : t('changes.revertNotPossible') } : {}),
|
|
534
903
|
separated: true,
|
|
535
904
|
onSelect: () => { void revertRow(file) },
|
|
536
905
|
},
|
|
537
906
|
{ label: t('changes.openInScm'), separated: true, onSelect: () => { setView('scm') } },
|
|
538
907
|
{ label: t('changes.copyPath'), onSelect: () => { void copyText(file.path) } },
|
|
539
908
|
])
|
|
540
|
-
}, [openChanged, revertRow, rowMenu, t])
|
|
909
|
+
}, [openChanged, revertRow, rowMenu, t, turnMode, viewDiff])
|
|
541
910
|
|
|
542
911
|
/** The header counter doubles as the "mark all / clear all" menu. */
|
|
543
912
|
const openReviewMenu = useCallback((event: React.MouseEvent): void => {
|
|
@@ -565,8 +934,14 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
565
934
|
const activeTab = explorer.tabs.find(candidate => candidate.id === explorer.activeTabId)
|
|
566
935
|
const visible = useMemo(() => {
|
|
567
936
|
if (summary === null) return false
|
|
568
|
-
|
|
569
|
-
|
|
937
|
+
// Visibility is the SESSION surface's question: the panel exists while the
|
|
938
|
+
// session has work in either view — a turn that changed nothing must not hide
|
|
939
|
+
// the dock (that would also strand the user in a scope with no rows).
|
|
940
|
+
return sessionFiles.length > 0
|
|
941
|
+
|| turnFiles.length > 0
|
|
942
|
+
|| summary.pending === true
|
|
943
|
+
|| summary.unavailable !== undefined
|
|
944
|
+
}, [sessionFiles.length, turnFiles.length, summary])
|
|
570
945
|
// Published for the tick (see `visibleRef`): read at tick time, not captured at
|
|
571
946
|
// effect time, so the cadence follows the panel without restarting the timer.
|
|
572
947
|
// "Rendered" mirrors the early return below: an error is shown even without a
|
|
@@ -577,7 +952,24 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
577
952
|
if (!visible && error === undefined) return null
|
|
578
953
|
|
|
579
954
|
const stale = activeTab?.changeStale === true
|
|
580
|
-
|
|
955
|
+
/**
|
|
956
|
+
* 标题跟着作用域走:累计视图还是「本次改动 · N」,本轮是无歧义的「本轮 #N · HH:MM」。
|
|
957
|
+
* 带轮次号是必须的 —— `turnView` 只描述最近一个**已完成**轮次,画面上的
|
|
958
|
+
* `summary.turn` 可能已经翻到还没结束的下一轮。
|
|
959
|
+
*/
|
|
960
|
+
const title = turnMode && turnView !== undefined
|
|
961
|
+
? `${turnTitle(t, turnView)}${files.length > 0 ? ` · ${files.length}` : ''}`
|
|
962
|
+
: files.length > 0 ? `${t('changes.title')} · ${files.length}` : t('changes.title')
|
|
963
|
+
/**
|
|
964
|
+
* 合计按**可见行**重算:宿主那份冻结合计会把已撤销的文件也算进去(列表已经没有它,
|
|
965
|
+
* 数字却还算着,就是"残影")。会话累计模式仍用宿主给的合计(语义不变)。
|
|
966
|
+
*/
|
|
967
|
+
const shownAdded = turnMode ? (turnRows?.added ?? 0) : (summary?.added ?? 0)
|
|
968
|
+
const shownDeleted = turnMode ? (turnRows?.deleted ?? 0) : (summary?.deleted ?? 0)
|
|
969
|
+
// 本轮可见行全是二进制/超大(0/0)时不摆一对 `+0 −0`;会话累计保持原样。
|
|
970
|
+
const showTotals = turnMode
|
|
971
|
+
? files.length > 0 && (shownAdded > 0 || shownDeleted > 0)
|
|
972
|
+
: files.length > 0
|
|
581
973
|
|
|
582
974
|
return (
|
|
583
975
|
<div className="rvs-changes" data-collapsed={collapsed ? '1' : '0'}>
|
|
@@ -592,10 +984,32 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
592
984
|
<span className="rvs-changes-chevron" aria-hidden="true">{collapsed ? '▸' : '▾'}</span>
|
|
593
985
|
<span className="rvs-changes-title">{title}</span>
|
|
594
986
|
</button>
|
|
595
|
-
{
|
|
987
|
+
{showTotals && (
|
|
596
988
|
<span className="rvs-changes-totals">
|
|
597
|
-
<span className="rvs-chg-add">+{
|
|
598
|
-
<span className="rvs-chg-del">−{
|
|
989
|
+
<span className="rvs-chg-add">+{shownAdded}</span>
|
|
990
|
+
<span className="rvs-chg-del">−{shownDeleted}</span>
|
|
991
|
+
</span>
|
|
992
|
+
)}
|
|
993
|
+
{/*
|
|
994
|
+
作用域切换只在 Host 真的给了一轮时出现:没有 `turnView` 的会话(老 Host、
|
|
995
|
+
或还没关闭过轮次)保持原样,不给一个点了没有反应的选择。
|
|
996
|
+
*/}
|
|
997
|
+
{turnScopeAvailable(turnView) && (
|
|
998
|
+
<span className="rvs-changes-scope" role="group" aria-label={t('changes.scopeLabel')}>
|
|
999
|
+
<button
|
|
1000
|
+
type="button"
|
|
1001
|
+
className="rvs-changes-scope-btn"
|
|
1002
|
+
aria-pressed={scope === 'session'}
|
|
1003
|
+
title={t('changes.scopeSessionHint')}
|
|
1004
|
+
onClick={() => { switchScope('session') }}
|
|
1005
|
+
>{t('changes.scopeSession')}</button>
|
|
1006
|
+
<button
|
|
1007
|
+
type="button"
|
|
1008
|
+
className="rvs-changes-scope-btn"
|
|
1009
|
+
aria-pressed={scope === 'turn'}
|
|
1010
|
+
title={t('changes.scopeTurnHint')}
|
|
1011
|
+
onClick={() => { switchScope('turn') }}
|
|
1012
|
+
>{t('changes.scopeTurn')}</button>
|
|
599
1013
|
</span>
|
|
600
1014
|
)}
|
|
601
1015
|
{done > 0 && (
|
|
@@ -653,11 +1067,71 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
653
1067
|
{!collapsed && (
|
|
654
1068
|
<div className="rvs-changes-body">
|
|
655
1069
|
{error !== undefined && <div className="rvs-changes-note rvs-changes-error">{t('changes.failed')}: {error}</div>}
|
|
1070
|
+
{/*
|
|
1071
|
+
刚才那次点击的结论(二进制 / 读不到 / 已被改回 / 只给了前缀)。留在这里
|
|
1072
|
+
而不是只闪一条 toast:它解释的是"为什么屏幕上没有标记",用户随时能回读。
|
|
1073
|
+
*/}
|
|
1074
|
+
{diffNotice !== undefined && (
|
|
1075
|
+
<div className="rvs-changes-note rvs-changes-diffnote" title={diffNotice.path}>
|
|
1076
|
+
{t(diffNoticeKey(diffNotice.notice))}
|
|
1077
|
+
</div>
|
|
1078
|
+
)}
|
|
1079
|
+
{/*
|
|
1080
|
+
本轮视图自己的说明("为什么没有标记 / 为什么回退成会话累计")。上方那条
|
|
1081
|
+
`diffNotice` 是**比较结论文案**,这条是**这次点击的处置**,两者可能同时
|
|
1082
|
+
存在,所以分两行。
|
|
1083
|
+
*/}
|
|
1084
|
+
{scopeNote !== undefined && (
|
|
1085
|
+
<div className="rvs-changes-note rvs-changes-scopenote" title={scopeNote.detail}>
|
|
1086
|
+
{t(scopeNote.key)}
|
|
1087
|
+
{scopeNote.detail === undefined ? '' : ` · ${scopeNote.detail}`}
|
|
1088
|
+
</div>
|
|
1089
|
+
)}
|
|
656
1090
|
{summary?.unavailable !== undefined && (
|
|
657
1091
|
<div className="rvs-changes-note">{t('changes.unavailable')} · {summary.unavailable}</div>
|
|
658
1092
|
)}
|
|
659
|
-
{
|
|
660
|
-
|
|
1093
|
+
{/*
|
|
1094
|
+
本轮只有统计(内存预算 / 文件上限):统计是真的,但点行拿不到 hunk,也
|
|
1095
|
+
不能撤销。这句话必须常驻,不能只在点击后出现 —— 用户有权先知道。
|
|
1096
|
+
*/}
|
|
1097
|
+
{turnMode && turnView?.cached === false && (
|
|
1098
|
+
<div className="rvs-changes-note rvs-changes-turnnote" title={turnView.reason}>
|
|
1099
|
+
{t('changes.turnStatsOnly')}
|
|
1100
|
+
</div>
|
|
1101
|
+
)}
|
|
1102
|
+
{/*
|
|
1103
|
+
这一轮的新文件扫描还没落地:同一轮会被重算,列表可能继续变长。说清楚,
|
|
1104
|
+
否则用户会以为"新文件没算进本轮"(审核 S2)。
|
|
1105
|
+
*/}
|
|
1106
|
+
{turnMode && turnView?.pending === true && (
|
|
1107
|
+
<div className="rvs-changes-note rvs-changes-turnnote">{t('changes.turnPending')}</div>
|
|
1108
|
+
)}
|
|
1109
|
+
{/*
|
|
1110
|
+
撤销成功后被隐藏的行:宿主冻结的 delta 仍然列着它(宿主语义不动),所以
|
|
1111
|
+
"少了几行"必须由面板自己说清楚。只有视图**完整**且可见行为 0 时才说"全部
|
|
1112
|
+
撤销"(`turnFullyReverted`);partial/pending 下仍用带 {n} 的那句 —— 面板
|
|
1113
|
+
无法证明"这一轮再没有别的改动"(SHOULD-1)。
|
|
1114
|
+
*/}
|
|
1115
|
+
{turnMode && hiddenRows > 0 && (
|
|
1116
|
+
<div className="rvs-changes-note rvs-changes-turnnote">
|
|
1117
|
+
{allReverted
|
|
1118
|
+
? t('changes.turnRevertedAll')
|
|
1119
|
+
: t('changes.turnRevertedHidden').replace('{n}', String(hiddenRows))}
|
|
1120
|
+
</div>
|
|
1121
|
+
)}
|
|
1122
|
+
{/*
|
|
1123
|
+
A turn still waiting for its slow scan is NOT "this turn changed nothing":
|
|
1124
|
+
saying both would flatly contradict the "still filling in" note above
|
|
1125
|
+
(review NIT-1). Neither is "every row was reverted": that case has its own
|
|
1126
|
+
sentence above (`turnRevertedAll`), so the generic empty copy stays away —
|
|
1127
|
+
and in a partial/pending view the "all" sentence itself is withheld above.
|
|
1128
|
+
*/}
|
|
1129
|
+
{files.length === 0
|
|
1130
|
+
&& summary?.unavailable === undefined
|
|
1131
|
+
&& summary?.pending !== true
|
|
1132
|
+
&& turnView?.pending !== true
|
|
1133
|
+
&& hiddenRows === 0 && (
|
|
1134
|
+
<div className="rvs-changes-note">{turnMode ? t('changes.turnEmpty') : t('changes.empty')}</div>
|
|
661
1135
|
)}
|
|
662
1136
|
{/*
|
|
663
1137
|
The filter can hide every row; an empty body must then say WHY instead
|
|
@@ -723,7 +1197,18 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
723
1197
|
</div>
|
|
724
1198
|
)
|
|
725
1199
|
})}
|
|
726
|
-
{
|
|
1200
|
+
{/*
|
|
1201
|
+
两条轴说"不完整"的原因不同,不能共用一句话:
|
|
1202
|
+
- 会话累计:`changes.truncated` = 文件超过 500,只列出前 N 个(语义不变);
|
|
1203
|
+
- 本轮:`changes.turnPartial` 覆盖三种成因 —— 文件上限、上一侧内容未知
|
|
1204
|
+
(二进制/字节被扣下,无法归属)、上一轮扫描从未落定(上一轮校正没赶上)。
|
|
1205
|
+
常见场景(改过二进制文件)几乎每轮都会显示,用"文件过多"解释会撒谎。
|
|
1206
|
+
*/}
|
|
1207
|
+
{turnMode
|
|
1208
|
+
? (turnView?.truncated === true
|
|
1209
|
+
&& <div className="rvs-changes-note rvs-changes-turnnote">{t('changes.turnPartial')}</div>)
|
|
1210
|
+
: (summary?.truncated === true
|
|
1211
|
+
&& <div className="rvs-changes-note">{t('changes.truncated')}</div>)}
|
|
727
1212
|
{/*
|
|
728
1213
|
Which paths the new-file scan skipped. Stated, never silent: a file
|
|
729
1214
|
the user expected to see must not be missing without a reason, and
|