dsh-remote-vs 0.21.0 → 0.22.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 +1 -1
- package/README.md +1 -1
- package/lib/client.js +1007 -264
- package/lib/index.js +180 -13
- package/lib/types/changes/recorder.d.ts +21 -0
- package/lib/types/changes/status.d.ts +41 -1
- package/lib/types/changes/text-diff.d.ts +18 -0
- package/lib/types/client/XTerm.d.ts +2 -0
- package/lib/types/client/changes/ChangesDock.d.ts +9 -2
- package/lib/types/client/changes/model.d.ts +3 -1
- package/lib/types/client/changes/review-state.d.ts +67 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/store.d.ts +51 -0
- package/lib/types/client/vsc/change-marks.d.ts +17 -0
- package/lib/types/client/vsc/kit.d.ts +9 -0
- package/lib/types/client/vsc/terminal-clipboard.d.ts +94 -0
- package/lib/types/protocol.d.ts +37 -1
- package/package.json +1 -1
- package/src/changes/recorder.ts +93 -28
- package/src/changes/status.ts +69 -2
- package/src/changes/text-diff.ts +42 -0
- package/src/client/TerminalView.tsx +1 -0
- package/src/client/XTerm.tsx +112 -21
- package/src/client/changes/ChangesDock.tsx +241 -39
- package/src/client/changes/changes.css +122 -9
- package/src/client/changes/model.ts +106 -22
- package/src/client/changes/review-state.ts +133 -0
- package/src/client/i18n.ts +51 -2
- package/src/client/store.tsx +186 -2
- package/src/client/vsc/change-marks.ts +39 -6
- package/src/client/vsc/kit.tsx +16 -1
- package/src/client/vsc/terminal-clipboard.ts +170 -0
- package/src/client/vsc/vsc.css +23 -0
- package/src/protocol.ts +37 -1
package/src/client/XTerm.tsx
CHANGED
|
@@ -10,6 +10,13 @@ import type { ITheme } from '@xterm/xterm'
|
|
|
10
10
|
import { FitAddon } from '@xterm/addon-fit'
|
|
11
11
|
import type { TerminalClientFrame, TerminalServerFrame } from '../protocol.ts'
|
|
12
12
|
import { isDarkScheme, subscribeColorScheme } from './theme.ts'
|
|
13
|
+
import { ContextMenu, useContextMenu, type MenuEntry } from './vsc/kit.tsx'
|
|
14
|
+
import {
|
|
15
|
+
clipboardChordFor,
|
|
16
|
+
createPasteFallback,
|
|
17
|
+
stripBracketedPasteMarkers,
|
|
18
|
+
terminalMenuState,
|
|
19
|
+
} from './vsc/terminal-clipboard.ts'
|
|
13
20
|
|
|
14
21
|
function send(ws: WebSocket, frame: TerminalClientFrame): void {
|
|
15
22
|
if (ws.readyState === WebSocket.OPEN) {
|
|
@@ -112,11 +119,20 @@ export function XTerm(props: {
|
|
|
112
119
|
* which correctly re-runs the line.
|
|
113
120
|
*/
|
|
114
121
|
initialInput?: string
|
|
122
|
+
/** Translator for the right-click menu (copy / paste / select all). */
|
|
123
|
+
t: (key: string) => string
|
|
115
124
|
}): ReactNode {
|
|
116
125
|
const hostRef = useRef<HTMLDivElement>(null)
|
|
117
126
|
const propsRef = useRef(props)
|
|
118
127
|
propsRef.current = props
|
|
119
128
|
const liveRef = useRef<{ refit: () => void } | undefined>(undefined)
|
|
129
|
+
// The context menu lives at component level (portal); the mount-once effect
|
|
130
|
+
// reaches it through refs, the same pattern the explorer row uses.
|
|
131
|
+
const menu = useContextMenu()
|
|
132
|
+
const openMenuRef = useRef(menu.open)
|
|
133
|
+
openMenuRef.current = menu.open
|
|
134
|
+
const tRef = useRef(props.t)
|
|
135
|
+
tRef.current = props.t
|
|
120
136
|
|
|
121
137
|
// Shown again after being hidden: refit and push the size.
|
|
122
138
|
useEffect(() => {
|
|
@@ -187,7 +203,9 @@ export function XTerm(props: {
|
|
|
187
203
|
* characters — far under that cap either way, and far above a keystroke.
|
|
188
204
|
*/
|
|
189
205
|
const INPUT_CHUNK_CHARS = 64 * 1024
|
|
190
|
-
const sendInput = (
|
|
206
|
+
const sendInput = (rawData: string): void => {
|
|
207
|
+
const data = stripBracketedPasteMarkers(rawData)
|
|
208
|
+
if (data === '') return
|
|
191
209
|
if (data.length <= INPUT_CHUNK_CHARS) {
|
|
192
210
|
send(ws, { t: 'in', d: data })
|
|
193
211
|
return
|
|
@@ -253,9 +271,13 @@ export function XTerm(props: {
|
|
|
253
271
|
// Late layout (tab switch): refit shortly after mount too.
|
|
254
272
|
const timer = window.setTimeout(pushSize, 300)
|
|
255
273
|
|
|
256
|
-
//
|
|
257
|
-
// Ctrl+Shift+C / Cmd+C / Ctrl+Insert =
|
|
258
|
-
// Shift+Insert
|
|
274
|
+
// Clipboard (VS Code / Windows Terminal conventions; plain Ctrl+C stays SIGINT):
|
|
275
|
+
// copy = Ctrl+Shift+C / Cmd+C / Ctrl+Insert, paste = Ctrl+Shift+V / Cmd+V /
|
|
276
|
+
// Shift+Insert. Handled chords call preventDefault() THEMSELVES: returning
|
|
277
|
+
// false only stops xterm, and the browser would then run its own default
|
|
278
|
+
// (Chrome maps Ctrl+Shift+V to paste-as-plain-text, which double-pasted).
|
|
279
|
+
// Plain Ctrl+V is left to the browser first; when no paste event arrives the
|
|
280
|
+
// Clipboard API fallback fires (some shells swallow the native paste).
|
|
259
281
|
const doCopy = (clear: boolean): void => {
|
|
260
282
|
const selection = term.getSelection()
|
|
261
283
|
if (selection === '') return
|
|
@@ -273,30 +295,91 @@ export function XTerm(props: {
|
|
|
273
295
|
term.paste(text)
|
|
274
296
|
})
|
|
275
297
|
}
|
|
298
|
+
const pasteFallback = createPasteFallback({
|
|
299
|
+
read: readClipboard,
|
|
300
|
+
paste: (text) => { term.paste(text) },
|
|
301
|
+
onDenied: () => { term.write('\r\n[dsh-remote] clipboard read denied by the browser\r\n') },
|
|
302
|
+
})
|
|
303
|
+
/**
|
|
304
|
+
* All paste input converges here: one insertion per paste event.
|
|
305
|
+
*
|
|
306
|
+
* Capture phase + stopPropagation keeps xterm's own textarea handler from
|
|
307
|
+
* inserting a second copy, and preventDefault stops the browser's remaining
|
|
308
|
+
* default. The watcher is cancelled so the Clipboard-API fallback (for hosts
|
|
309
|
+
* that never deliver this event) does not fire on top of it.
|
|
310
|
+
*/
|
|
311
|
+
/**
|
|
312
|
+
* Explicit paste chords (Ctrl+Shift+V / Cmd+V / Shift+Insert) insert through
|
|
313
|
+
* the Clipboard API themselves. Some hosts still deliver the browser's native
|
|
314
|
+
* paste afterwards even when the keydown was preventDefault-ed (observed with
|
|
315
|
+
* Ctrl+Shift+V paste-as-plain-text), which pasted twice. This window swallows
|
|
316
|
+
* that native delivery; plain Ctrl+V keeps the native path below.
|
|
317
|
+
*/
|
|
318
|
+
let suppressNativePasteUntil = 0
|
|
319
|
+
const onPasteEvent = (e: ClipboardEvent): void => {
|
|
320
|
+
e.preventDefault()
|
|
321
|
+
e.stopPropagation()
|
|
322
|
+
if (Date.now() < suppressNativePasteUntil) {
|
|
323
|
+
// The explicit chord already inserted this paste through the API.
|
|
324
|
+
suppressNativePasteUntil = 0
|
|
325
|
+
return
|
|
326
|
+
}
|
|
327
|
+
const text = e.clipboardData?.getData('text/plain') ?? ''
|
|
328
|
+
pasteFallback.observed()
|
|
329
|
+
if (text !== '') term.paste(text)
|
|
330
|
+
}
|
|
331
|
+
host.addEventListener('paste', onPasteEvent, true)
|
|
276
332
|
term.attachCustomKeyEventHandler((e) => {
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return true
|
|
333
|
+
const chord = clipboardChordFor({
|
|
334
|
+
key: e.key,
|
|
335
|
+
ctrl: e.ctrlKey,
|
|
336
|
+
shift: e.shiftKey,
|
|
337
|
+
alt: e.altKey,
|
|
338
|
+
meta: e.metaKey,
|
|
339
|
+
})
|
|
340
|
+
if (chord === undefined) return true
|
|
341
|
+
if (chord === 'copy-interrupt') {
|
|
342
|
+
// Ctrl+C: with a selection the convention is COPY (never SIGINT); without
|
|
343
|
+
// one the key falls through so the remote shell interrupts as usual.
|
|
344
|
+
if (!term.hasSelection()) return true
|
|
345
|
+
e.preventDefault()
|
|
346
|
+
doCopy(false)
|
|
347
|
+
return false
|
|
289
348
|
}
|
|
290
|
-
if (
|
|
349
|
+
if (chord === 'paste') {
|
|
350
|
+
// Explicit paste chord: insert ONCE through the Clipboard API and swallow
|
|
351
|
+
// the browser's native delivery for this gesture (some hosts ignore the
|
|
352
|
+
// keydown preventDefault and paste again).
|
|
353
|
+
e.preventDefault()
|
|
354
|
+
suppressNativePasteUntil = Date.now() + 600
|
|
291
355
|
doPaste()
|
|
292
356
|
return false
|
|
293
357
|
}
|
|
294
|
-
|
|
358
|
+
if (chord === 'paste-native') {
|
|
359
|
+
// Plain Ctrl+V: the browser's native paste is the primary path; when the
|
|
360
|
+
// host swallows it, the watcher falls back to the Clipboard API.
|
|
361
|
+
pasteFallback.arm()
|
|
362
|
+
return true
|
|
363
|
+
}
|
|
364
|
+
// Copy: with nothing selected the key belongs to the terminal/browser.
|
|
365
|
+
if (!term.hasSelection()) return true
|
|
366
|
+
e.preventDefault()
|
|
367
|
+
doCopy(false)
|
|
368
|
+
return false
|
|
295
369
|
})
|
|
296
370
|
const onContextMenu = (e: MouseEvent): void => {
|
|
297
371
|
e.preventDefault()
|
|
298
|
-
|
|
299
|
-
|
|
372
|
+
const hasSelection = term.hasSelection()
|
|
373
|
+
const entries: MenuEntry[] = [
|
|
374
|
+
{
|
|
375
|
+
label: tRef.current('term.copy'),
|
|
376
|
+
disabled: terminalMenuState({ hasSelection }).copyDisabled,
|
|
377
|
+
onSelect: () => { doCopy(false); term.focus() },
|
|
378
|
+
},
|
|
379
|
+
{ label: tRef.current('term.paste'), onSelect: () => { doPaste(); term.focus() } },
|
|
380
|
+
{ label: tRef.current('term.selectAll'), separated: true, onSelect: () => { term.selectAll(); term.focus() } },
|
|
381
|
+
]
|
|
382
|
+
openMenuRef.current(e.clientX, e.clientY, entries)
|
|
300
383
|
}
|
|
301
384
|
host.addEventListener('contextmenu', onContextMenu)
|
|
302
385
|
|
|
@@ -306,6 +389,7 @@ export function XTerm(props: {
|
|
|
306
389
|
unflip()
|
|
307
390
|
window.clearTimeout(timer)
|
|
308
391
|
window.removeEventListener('resize', onWindowResize)
|
|
392
|
+
host.removeEventListener('paste', onPasteEvent, true)
|
|
309
393
|
host.removeEventListener('contextmenu', onContextMenu)
|
|
310
394
|
resizeObserver.disconnect()
|
|
311
395
|
try {
|
|
@@ -319,5 +403,12 @@ export function XTerm(props: {
|
|
|
319
403
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
320
404
|
}, [])
|
|
321
405
|
|
|
322
|
-
return
|
|
406
|
+
return (
|
|
407
|
+
<>
|
|
408
|
+
<div ref={hostRef} style={{ height: '100%', minHeight: 200 }} />
|
|
409
|
+
{menu.menu !== undefined && (
|
|
410
|
+
<ContextMenu x={menu.menu.x} y={menu.menu.y} entries={menu.menu.entries} onClose={menu.close} />
|
|
411
|
+
)}
|
|
412
|
+
</>
|
|
413
|
+
)
|
|
323
414
|
}
|
|
@@ -12,8 +12,15 @@
|
|
|
12
12
|
* written with `node:fs`), which the probe measured as 58 remote sessions with
|
|
13
13
|
* zero change events.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* Three things happen here, and they are deliberately different in kind:
|
|
16
|
+
* - a row's LEFT click opens the file and hands the editor the same hunks, so the
|
|
17
|
+
* changed lines are painted in place;
|
|
18
|
+
* - a row's RIGHT click offers the writes ("revert everything this session did to
|
|
19
|
+
* this file", "undo a tracked creation") plus the navigation shortcuts. The
|
|
20
|
+
* host decides which of those exist (`RemoteChangedFile.revert`), because only
|
|
21
|
+
* git knows whether a creation has a copy to fall back on;
|
|
22
|
+
* - the ✓ on a row is a LOCAL review note (`review-state.ts`): it writes nothing,
|
|
23
|
+
* it is what makes a thirty-file refactor converge.
|
|
17
24
|
*/
|
|
18
25
|
|
|
19
26
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
@@ -25,8 +32,10 @@ import {
|
|
|
25
32
|
openRemoteFileInBinding,
|
|
26
33
|
refreshAll,
|
|
27
34
|
remoteOpenBindings,
|
|
35
|
+
revertFileChanges,
|
|
28
36
|
sessionRepoSubdir,
|
|
29
37
|
setFollowSession,
|
|
38
|
+
setView,
|
|
30
39
|
useExplorer,
|
|
31
40
|
workspaceMatchesSession,
|
|
32
41
|
} from '../store.tsx'
|
|
@@ -34,14 +43,32 @@ import { bindingForChangedFile } from '../remote-file-open-target.ts'
|
|
|
34
43
|
import { useRemoteChatTarget } from '../use-remote-chat-target.ts'
|
|
35
44
|
import type { RemoteChangedFile, RemoteChangesSummary } from '../../protocol.ts'
|
|
36
45
|
import { EMPTY_CHANGE_SET, changeSetFromHunks, type ChangeSet } from './model.ts'
|
|
46
|
+
import {
|
|
47
|
+
isReviewed,
|
|
48
|
+
parseReviewed,
|
|
49
|
+
pruneReviewed,
|
|
50
|
+
reviewedCount,
|
|
51
|
+
serializeReviewed,
|
|
52
|
+
setAllReviewed,
|
|
53
|
+
toggleReviewed as toggleReviewedEntry,
|
|
54
|
+
} from './review-state.ts'
|
|
37
55
|
import { setUndoContext } from './undo-context.ts'
|
|
38
56
|
import { forgetChangeOrigin, publishableUndoOrigin, rememberChangeOrigin } from './undo-target.ts'
|
|
39
|
-
import { FileIcon } from '../vsc/kit.tsx'
|
|
57
|
+
import { ContextMenu, FileIcon, copyText, useContextMenu } from '../vsc/kit.tsx'
|
|
40
58
|
import './changes.css'
|
|
41
59
|
|
|
42
60
|
/** How often an open panel re-reads the ledger (the host refreshes it per turn). */
|
|
43
61
|
const POLL_MS = 3000
|
|
44
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Where the review marks are remembered, per session.
|
|
65
|
+
*
|
|
66
|
+
* `localStorage`, like the port-forward rules: this is a note about the user's own
|
|
67
|
+
* reading progress, not a fact about the remote tree, so it must survive a page
|
|
68
|
+
* reload without becoming a protocol field nobody else needs.
|
|
69
|
+
*/
|
|
70
|
+
const REVIEW_STORAGE_PREFIX = 'rvs.changes.reviewed.'
|
|
71
|
+
|
|
45
72
|
/**
|
|
46
73
|
* How many polls between two follow retries (5 × 3 s = one probe every 15 s).
|
|
47
74
|
*
|
|
@@ -79,6 +106,17 @@ function splitDisplay(display: string): { dir: string; name: string } {
|
|
|
79
106
|
return at < 0 ? { dir: '', name: display } : { dir: display.slice(0, at + 1), name: display.slice(at + 1) }
|
|
80
107
|
}
|
|
81
108
|
|
|
109
|
+
/** Read one session's review marks, tolerating a storage that refuses to answer. */
|
|
110
|
+
function loadReviewed(sessionId: string | undefined): Record<string, 1> {
|
|
111
|
+
if (sessionId === undefined || sessionId === '') return {}
|
|
112
|
+
try {
|
|
113
|
+
return parseReviewed(window.localStorage.getItem(`${REVIEW_STORAGE_PREFIX}${sessionId}`))
|
|
114
|
+
} catch {
|
|
115
|
+
// Private mode / disabled storage: the marks simply do not persist.
|
|
116
|
+
return {}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
82
120
|
export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
83
121
|
const explorer = useExplorer()
|
|
84
122
|
// The dock is a second surface of the same store as the explorer, and it can
|
|
@@ -104,9 +142,13 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
104
142
|
// push the composer off the screen.
|
|
105
143
|
const [collapsed, setCollapsed] = useState(true)
|
|
106
144
|
const [busy, setBusy] = useState<string | undefined>(undefined)
|
|
145
|
+
/** This session's local review marks (see `review-state.ts`). */
|
|
146
|
+
const [reviewed, setReviewed] = useState<Record<string, 1>>(() => loadReviewed(sessionId))
|
|
107
147
|
const alive = useRef(true)
|
|
108
148
|
const currentSession = useRef(sessionId)
|
|
109
149
|
currentSession.current = sessionId
|
|
150
|
+
const rowMenu = useContextMenu()
|
|
151
|
+
const reviewMenu = useContextMenu()
|
|
110
152
|
// The Source Control panel's repository directory, resolved at call time: it is
|
|
111
153
|
// the user's explicit answer to "which repository in this workspace", and it
|
|
112
154
|
// outranks the host's one-level guess. A ref (not a value) so a change made
|
|
@@ -150,6 +192,12 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
150
192
|
}
|
|
151
193
|
}, [load])
|
|
152
194
|
|
|
195
|
+
// A different conversation has different marks: reload them instead of carrying
|
|
196
|
+
// one session's ✓ onto another's files.
|
|
197
|
+
useEffect(() => {
|
|
198
|
+
setReviewed(loadReviewed(sessionId))
|
|
199
|
+
}, [sessionId])
|
|
200
|
+
|
|
153
201
|
/**
|
|
154
202
|
* Publish the revert coordinates for the tab the user is LOOKING AT.
|
|
155
203
|
*
|
|
@@ -233,6 +281,25 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
233
281
|
void followSessionWorkspace({ sessionId, alias: summary.alias, remoteRoot: summary.root })
|
|
234
282
|
}, [sessionId, summary, chatTarget.sessionId])
|
|
235
283
|
|
|
284
|
+
const files = useMemo(() => summary?.files ?? [], [summary])
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Resolve the binding a row belongs to, with one refresh for a cold page.
|
|
288
|
+
*
|
|
289
|
+
* The store may still be loading its workspace table on a cold page, so a miss
|
|
290
|
+
* is worth one refresh before giving up.
|
|
291
|
+
*/
|
|
292
|
+
const bindingOf = useCallback(async (file: RemoteChangedFile) => {
|
|
293
|
+
if (summary === null) return undefined
|
|
294
|
+
let binding = bindingForChangedFile(remoteOpenBindings(), summary, file.path)
|
|
295
|
+
if (binding === undefined) {
|
|
296
|
+
refreshAll()
|
|
297
|
+
await new Promise(resolve => { window.setTimeout(resolve, 300) })
|
|
298
|
+
binding = bindingForChangedFile(remoteOpenBindings(), summary, file.path)
|
|
299
|
+
}
|
|
300
|
+
return binding
|
|
301
|
+
}, [summary])
|
|
302
|
+
|
|
236
303
|
/** Open one listed file in the remote editor with its change marks. */
|
|
237
304
|
const openChanged = useCallback(async (file: RemoteChangedFile): Promise<void> => {
|
|
238
305
|
if (sessionId === undefined || summary === null) return
|
|
@@ -242,24 +309,14 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
242
309
|
if (!alive.current) return
|
|
243
310
|
const stamp = `${file.path}@${summary.at}@${summary.turn}`
|
|
244
311
|
const set: ChangeSet = diff !== null && diff.kind === 'text'
|
|
245
|
-
? changeSetFromHunks(diff.hunks, stamp)
|
|
312
|
+
? changeSetFromHunks(diff.hunks, stamp, diff.patch)
|
|
246
313
|
: { ...EMPTY_CHANGE_SET, stamp }
|
|
247
|
-
// The store may still be loading its workspace table on a cold page, so a
|
|
248
|
-
// miss is worth one refresh before giving up on the click. Read through
|
|
249
|
-
// the snapshot accessor, not the render-time props, so the retry actually
|
|
250
|
-
// sees what the load wrote.
|
|
251
|
-
//
|
|
252
314
|
// Resolved by the session's REMOTE root, never by the alias alone: one
|
|
253
315
|
// alias carries several bindings (two workspaces can live on one alias),
|
|
254
316
|
// and the alias-only form picked whichever came first —
|
|
255
317
|
// the file opened while the tree and the selector stayed on the other
|
|
256
318
|
// workspace. That was the reported bug.
|
|
257
|
-
|
|
258
|
-
if (binding === undefined) {
|
|
259
|
-
refreshAll()
|
|
260
|
-
await new Promise(resolve => { window.setTimeout(resolve, 300) })
|
|
261
|
-
binding = bindingForChangedFile(remoteOpenBindings(), summary, file.path)
|
|
262
|
-
}
|
|
319
|
+
const binding = await bindingOf(file)
|
|
263
320
|
if (binding === undefined) {
|
|
264
321
|
explorer.info(t('changes.noWorkspace'))
|
|
265
322
|
return
|
|
@@ -284,9 +341,94 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
284
341
|
} finally {
|
|
285
342
|
if (alive.current) setBusy(undefined)
|
|
286
343
|
}
|
|
287
|
-
}, [explorer, sessionId, summary, t])
|
|
344
|
+
}, [bindingOf, explorer, sessionId, summary, t])
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Revert EVERYTHING this session did to one listed file.
|
|
348
|
+
*
|
|
349
|
+
* The write itself (gates, patch, confirmation, refresh) lives in the store's
|
|
350
|
+
* `revertFileChanges`: it is the same class of remote write as the hover-revert
|
|
351
|
+
* and must obey the same rules. This callback only resolves the coordinates the
|
|
352
|
+
* row stands for.
|
|
353
|
+
*/
|
|
354
|
+
const revertRow = useCallback(async (file: RemoteChangedFile): Promise<void> => {
|
|
355
|
+
if (sessionId === undefined || summary === null || file.revert === undefined) return
|
|
356
|
+
const binding = await bindingOf(file)
|
|
357
|
+
if (binding === undefined) {
|
|
358
|
+
explorer.info(t('changes.noWorkspace'))
|
|
359
|
+
return
|
|
360
|
+
}
|
|
361
|
+
setBusy(file.path)
|
|
362
|
+
try {
|
|
363
|
+
await revertFileChanges({
|
|
364
|
+
sessionId,
|
|
365
|
+
bindingId: binding.id,
|
|
366
|
+
alias: binding.alias,
|
|
367
|
+
root: summary.root,
|
|
368
|
+
path: file.path,
|
|
369
|
+
display: file.display,
|
|
370
|
+
mode: file.revert,
|
|
371
|
+
})
|
|
372
|
+
} finally {
|
|
373
|
+
if (alive.current) setBusy(undefined)
|
|
374
|
+
}
|
|
375
|
+
}, [bindingOf, explorer, sessionId, summary, t])
|
|
376
|
+
|
|
377
|
+
const toggleReviewed = useCallback((file: RemoteChangedFile): void => {
|
|
378
|
+
setReviewed(previous => toggleReviewedEntry(files, previous, file))
|
|
379
|
+
}, [files])
|
|
380
|
+
|
|
381
|
+
// Persist the marks whenever they change. A storage that refuses (private mode)
|
|
382
|
+
// must cost nothing but persistence — never a broken panel.
|
|
383
|
+
useEffect(() => {
|
|
384
|
+
if (sessionId === undefined || sessionId === '') return
|
|
385
|
+
try {
|
|
386
|
+
window.localStorage.setItem(`${REVIEW_STORAGE_PREFIX}${sessionId}`, serializeReviewed(reviewed))
|
|
387
|
+
} catch {
|
|
388
|
+
// Ignore: see above.
|
|
389
|
+
}
|
|
390
|
+
}, [reviewed, sessionId])
|
|
391
|
+
|
|
392
|
+
// Drop marks for rows that are gone (or whose counts changed). Without this a
|
|
393
|
+
// path that leaves and comes back would show a ✓ nobody gave it.
|
|
394
|
+
useEffect(() => {
|
|
395
|
+
setReviewed(previous => {
|
|
396
|
+
const next = pruneReviewed(files, previous)
|
|
397
|
+
// A prune only ever removes entries, so equal length means "identical".
|
|
398
|
+
return Object.keys(next).length === Object.keys(previous).length ? previous : next
|
|
399
|
+
})
|
|
400
|
+
}, [files])
|
|
401
|
+
|
|
402
|
+
const done = reviewedCount(files, reviewed)
|
|
403
|
+
|
|
404
|
+
const openRowMenu = useCallback((event: React.MouseEvent, file: RemoteChangedFile): void => {
|
|
405
|
+
event.preventDefault()
|
|
406
|
+
event.stopPropagation()
|
|
407
|
+
const cannotRevert = file.revert === undefined
|
|
408
|
+
rowMenu.open(event.clientX, event.clientY, [
|
|
409
|
+
{ label: t('changes.menuOpen'), onSelect: () => { void openChanged(file) } },
|
|
410
|
+
{
|
|
411
|
+
label: file.revert === 'delete' ? t('changes.revertCreation') : t('changes.revertFile'),
|
|
412
|
+
danger: true,
|
|
413
|
+
disabled: cannotRevert,
|
|
414
|
+
...(cannotRevert ? { hint: t('changes.revertNotPossible') } : {}),
|
|
415
|
+
separated: true,
|
|
416
|
+
onSelect: () => { void revertRow(file) },
|
|
417
|
+
},
|
|
418
|
+
{ label: t('changes.openInScm'), separated: true, onSelect: () => { setView('scm') } },
|
|
419
|
+
{ label: t('changes.copyPath'), onSelect: () => { void copyText(file.path) } },
|
|
420
|
+
])
|
|
421
|
+
}, [openChanged, revertRow, rowMenu, t])
|
|
422
|
+
|
|
423
|
+
/** The header counter doubles as the "mark all / clear all" menu. */
|
|
424
|
+
const openReviewMenu = useCallback((event: React.MouseEvent): void => {
|
|
425
|
+
const rect = (event.currentTarget as HTMLElement).getBoundingClientRect()
|
|
426
|
+
reviewMenu.open(rect.left, rect.bottom + 4, [
|
|
427
|
+
{ label: t('changes.reviewAll'), onSelect: () => { setReviewed(setAllReviewed(files, true)) } },
|
|
428
|
+
{ label: t('changes.reviewNone'), onSelect: () => { setReviewed(setAllReviewed(files, false)) } },
|
|
429
|
+
])
|
|
430
|
+
}, [files, reviewMenu, t])
|
|
288
431
|
|
|
289
|
-
const files = summary?.files ?? []
|
|
290
432
|
const activeTab = explorer.tabs.find(candidate => candidate.id === explorer.activeTabId)
|
|
291
433
|
const visible = useMemo(() => {
|
|
292
434
|
if (summary === null) return false
|
|
@@ -318,6 +460,16 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
318
460
|
<span className="rvs-chg-del">−{summary?.deleted ?? 0}</span>
|
|
319
461
|
</span>
|
|
320
462
|
)}
|
|
463
|
+
{done > 0 && (
|
|
464
|
+
<button
|
|
465
|
+
type="button"
|
|
466
|
+
className="rvs-changes-reviewed"
|
|
467
|
+
title={t('changes.reviewMenu')}
|
|
468
|
+
onClick={openReviewMenu}
|
|
469
|
+
>
|
|
470
|
+
{t('changes.reviewCount').replace('{done}', String(done)).replace('{total}', String(files.length))}
|
|
471
|
+
</button>
|
|
472
|
+
)}
|
|
321
473
|
{summary?.pending === true && <span className="rvs-changes-pending">{t('changes.pending')}</span>}
|
|
322
474
|
<span className="rvs-changes-spacer" />
|
|
323
475
|
{stale && <span className="rvs-changes-stale" title={t('changes.staleHint')}>{t('changes.stale')}</span>}
|
|
@@ -339,37 +491,87 @@ export function ChangesDock(props: ChangesDockProps): React.ReactNode {
|
|
|
339
491
|
)}
|
|
340
492
|
{files.map(file => {
|
|
341
493
|
const { dir, name } = splitDisplay(file.display)
|
|
494
|
+
const marked = isReviewed(file, reviewed)
|
|
342
495
|
return (
|
|
343
|
-
<
|
|
344
|
-
type="button"
|
|
496
|
+
<div
|
|
345
497
|
key={file.path}
|
|
346
498
|
className={`rvs-chg-row${busy === file.path ? ' rvs-chg-loading' : ''}`}
|
|
347
|
-
|
|
348
|
-
onClick={() => { void openChanged(file) }}
|
|
499
|
+
data-reviewed={marked ? '1' : '0'}
|
|
349
500
|
>
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
<
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
501
|
+
{/*
|
|
502
|
+
Two buttons, not one: a whole-row <button> cannot legally contain
|
|
503
|
+
the review toggle, and the toggle must not open the file. The
|
|
504
|
+
status letter is decoration here — its meaning is in the title.
|
|
505
|
+
*/}
|
|
506
|
+
<button
|
|
507
|
+
type="button"
|
|
508
|
+
className="rvs-chg-open"
|
|
509
|
+
title={`${file.path}\n${statusWord(file, t)}`}
|
|
510
|
+
onClick={() => { void openChanged(file) }}
|
|
511
|
+
onContextMenu={(event) => { openRowMenu(event, file) }}
|
|
512
|
+
>
|
|
513
|
+
<span className="rvs-chg-status" data-status={file.status ?? 'M'} aria-hidden="true">
|
|
514
|
+
{file.status ?? 'M'}
|
|
515
|
+
</span>
|
|
516
|
+
<span className="rvs-chg-icon" aria-hidden="true"><FileIcon path={file.display} size={14} /></span>
|
|
517
|
+
<span className="rvs-chg-path">
|
|
518
|
+
<span className="rvs-chg-dir">{dir}</span>
|
|
519
|
+
<span className="rvs-chg-name">{name}</span>
|
|
520
|
+
</span>
|
|
521
|
+
<span className="rvs-chg-counts">
|
|
522
|
+
{file.oversized === true
|
|
523
|
+
? <span className="rvs-chg-note">{t('changes.oversized')}</span>
|
|
524
|
+
: file.binary === true
|
|
525
|
+
? <span className="rvs-chg-note">{t('changes.binary')}</span>
|
|
526
|
+
: (
|
|
527
|
+
<>
|
|
528
|
+
<span className="rvs-chg-add">+{file.added}</span>
|
|
529
|
+
<span className="rvs-chg-del">−{file.deleted}</span>
|
|
530
|
+
</>
|
|
531
|
+
)}
|
|
532
|
+
</span>
|
|
533
|
+
</button>
|
|
534
|
+
<button
|
|
535
|
+
type="button"
|
|
536
|
+
className={`rvs-chg-review${marked ? ' is-on' : ''}`}
|
|
537
|
+
aria-pressed={marked}
|
|
538
|
+
title={marked ? t('changes.unmarkReviewed') : t('changes.markReviewed')}
|
|
539
|
+
onClick={() => { toggleReviewed(file) }}
|
|
540
|
+
>{marked ? '✓' : ''}</button>
|
|
541
|
+
</div>
|
|
368
542
|
)
|
|
369
543
|
})}
|
|
370
544
|
{summary?.truncated === true && <div className="rvs-changes-note">{t('changes.truncated')}</div>}
|
|
545
|
+
{/*
|
|
546
|
+
Which paths the new-file scan skipped. Stated, never silent: a file
|
|
547
|
+
the user expected to see must not be missing without a reason, and
|
|
548
|
+
the SCM panel is where every path (build output included) is listed.
|
|
549
|
+
*/}
|
|
550
|
+
{(summary?.excludedDirs?.length ?? 0) > 0 && (
|
|
551
|
+
<div className="rvs-changes-note" title={summary?.excludedDirs?.join(', ')}>
|
|
552
|
+
{t('changes.excluded').replace('{dirs}', summary?.excludedDirs?.join(', ') ?? '')}
|
|
553
|
+
</div>
|
|
554
|
+
)}
|
|
371
555
|
</div>
|
|
372
556
|
)}
|
|
557
|
+
{rowMenu.menu !== undefined && (
|
|
558
|
+
<ContextMenu
|
|
559
|
+
x={rowMenu.menu.x}
|
|
560
|
+
y={rowMenu.menu.y}
|
|
561
|
+
entries={rowMenu.menu.entries}
|
|
562
|
+
onClose={rowMenu.close}
|
|
563
|
+
className="rvs-menu-dock"
|
|
564
|
+
/>
|
|
565
|
+
)}
|
|
566
|
+
{reviewMenu.menu !== undefined && (
|
|
567
|
+
<ContextMenu
|
|
568
|
+
x={reviewMenu.menu.x}
|
|
569
|
+
y={reviewMenu.menu.y}
|
|
570
|
+
entries={reviewMenu.menu.entries}
|
|
571
|
+
onClose={reviewMenu.close}
|
|
572
|
+
className="rvs-menu-dock"
|
|
573
|
+
/>
|
|
574
|
+
)}
|
|
373
575
|
</div>
|
|
374
576
|
)
|
|
375
577
|
}
|