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
|
@@ -137,21 +137,39 @@
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/*
|
|
140
|
-
* One file per row: type icon, path, counts
|
|
140
|
+
* One file per row: status letter, type icon, path, counts, review toggle.
|
|
141
141
|
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
142
|
+
* The row is a flex CONTAINER holding two buttons (open + review): a whole-row
|
|
143
|
+
* <button> cannot legally contain the toggle, and clicking the toggle must not
|
|
144
|
+
* also open the file. Every part is nowrap and the path is the only flexible
|
|
145
|
+
* one, so a long remote path ellipsizes in the middle of the row instead of
|
|
146
|
+
* pushing the counts out of view or wrapping the row into a paragraph.
|
|
146
147
|
*/
|
|
147
148
|
.rvs-chg-row {
|
|
148
149
|
display: flex;
|
|
149
150
|
flex: 0 0 auto;
|
|
150
151
|
align-items: center;
|
|
151
|
-
gap: 6px;
|
|
152
152
|
width: 100%;
|
|
153
|
+
min-width: 0;
|
|
154
|
+
border-radius: 5px;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.rvs-chg-row:hover { background-color: var(--rvs-chg-hover); }
|
|
158
|
+
|
|
159
|
+
.rvs-chg-row.rvs-chg-loading { opacity: .55; }
|
|
160
|
+
|
|
161
|
+
/* Reviewed rows recede a little, but hover brings them back to full contrast so
|
|
162
|
+
a row is never unreadable at the moment the user is about to act on it. */
|
|
163
|
+
.rvs-chg-row[data-reviewed='1']:not(:hover) .rvs-chg-open { opacity: .58; }
|
|
164
|
+
|
|
165
|
+
.rvs-chg-open {
|
|
166
|
+
display: flex;
|
|
167
|
+
flex: 1 1 auto;
|
|
168
|
+
align-items: center;
|
|
169
|
+
gap: 6px;
|
|
170
|
+
min-width: 0;
|
|
153
171
|
min-height: 24px;
|
|
154
|
-
padding: 1px 6px;
|
|
172
|
+
padding: 1px 4px 1px 6px;
|
|
155
173
|
border: none;
|
|
156
174
|
border-radius: 5px;
|
|
157
175
|
background: transparent;
|
|
@@ -163,9 +181,81 @@
|
|
|
163
181
|
cursor: pointer;
|
|
164
182
|
}
|
|
165
183
|
|
|
166
|
-
|
|
184
|
+
/*
|
|
185
|
+
* Review toggle. Hidden until the row is hovered (or focused by keyboard) so the
|
|
186
|
+
* list stays quiet, and always visible once the mark is ON — that ✓ is the only
|
|
187
|
+
* evidence the mark exists.
|
|
188
|
+
*/
|
|
189
|
+
.rvs-chg-review {
|
|
190
|
+
flex: 0 0 auto;
|
|
191
|
+
width: 18px;
|
|
192
|
+
height: 18px;
|
|
193
|
+
margin-right: 2px;
|
|
194
|
+
padding: 0;
|
|
195
|
+
border: none;
|
|
196
|
+
border-radius: 4px;
|
|
197
|
+
background: transparent;
|
|
198
|
+
color: var(--rvs-chg-fg3);
|
|
199
|
+
font-size: 11px;
|
|
200
|
+
line-height: 18px;
|
|
201
|
+
text-align: center;
|
|
202
|
+
cursor: pointer;
|
|
203
|
+
opacity: 0;
|
|
204
|
+
}
|
|
167
205
|
|
|
168
|
-
.rvs-chg-row.rvs-chg-
|
|
206
|
+
.rvs-chg-row:hover .rvs-chg-review,
|
|
207
|
+
.rvs-chg-review:focus-visible,
|
|
208
|
+
.rvs-chg-review.is-on { opacity: 1; }
|
|
209
|
+
|
|
210
|
+
.rvs-chg-review:hover { background-color: var(--rvs-chg-hover); color: var(--rvs-chg-fg); }
|
|
211
|
+
|
|
212
|
+
.rvs-chg-review.is-on { color: var(--rvs-chg-add); }
|
|
213
|
+
|
|
214
|
+
/*
|
|
215
|
+
* Status letter (A/M/D/R/C/T/U).
|
|
216
|
+
*
|
|
217
|
+
* A one-character column instead of a second tooltip: the row already shows the
|
|
218
|
+
* counts, and "was this file added, deleted or renamed" is the other question a
|
|
219
|
+
* reviewer asks. Colour follows the same vocabulary as the diff marks.
|
|
220
|
+
*/
|
|
221
|
+
.rvs-chg-status {
|
|
222
|
+
flex: 0 0 auto;
|
|
223
|
+
width: 10px;
|
|
224
|
+
font-variant-numeric: tabular-nums;
|
|
225
|
+
font-size: 10px;
|
|
226
|
+
font-weight: 600;
|
|
227
|
+
text-align: center;
|
|
228
|
+
color: var(--rvs-chg-fg3);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.rvs-chg-status[data-status='A'] { color: var(--rvs-chg-add); }
|
|
232
|
+
.rvs-chg-status[data-status='M'] { color: var(--rvs-chg-mod); }
|
|
233
|
+
.rvs-chg-status[data-status='D'] { color: var(--rvs-chg-del); }
|
|
234
|
+
.rvs-chg-status[data-status='R'] { color: var(--rvs-chg-info); }
|
|
235
|
+
.rvs-chg-status[data-status='C'] { color: var(--rvs-chg-info); }
|
|
236
|
+
.rvs-chg-status[data-status='U'] { color: var(--rvs-chg-del); }
|
|
237
|
+
|
|
238
|
+
/* The reviewed counter in the header doubles as the mark-all / clear menu. */
|
|
239
|
+
.rvs-changes-reviewed {
|
|
240
|
+
flex: 0 0 auto;
|
|
241
|
+
padding: 0 5px;
|
|
242
|
+
height: 18px;
|
|
243
|
+
border: none;
|
|
244
|
+
border-radius: 9px;
|
|
245
|
+
background: transparent;
|
|
246
|
+
color: var(--rvs-chg-fg3);
|
|
247
|
+
font: inherit;
|
|
248
|
+
font-size: 11px;
|
|
249
|
+
font-variant-numeric: tabular-nums;
|
|
250
|
+
line-height: 18px;
|
|
251
|
+
white-space: nowrap;
|
|
252
|
+
cursor: pointer;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.rvs-changes-reviewed:hover {
|
|
256
|
+
background-color: var(--rvs-chg-hover);
|
|
257
|
+
color: var(--rvs-chg-fg);
|
|
258
|
+
}
|
|
169
259
|
|
|
170
260
|
/* File-type icon: the host's icon theme when the shell provides one, else the
|
|
171
261
|
plugin's own SVG set (see vsc/kit.tsx FileIcon). */
|
|
@@ -228,3 +318,26 @@ body:not([data-ds-dark-theme]) .rvs-changes {
|
|
|
228
318
|
--rvs-chg-mod: #9a6700;
|
|
229
319
|
--rvs-chg-info: #0969da;
|
|
230
320
|
}
|
|
321
|
+
|
|
322
|
+
/*
|
|
323
|
+
* The row / header menus opened from THIS panel.
|
|
324
|
+
*
|
|
325
|
+
* `ContextMenu` portals to `document.body`, so neither `.rvs-changes`' palette
|
|
326
|
+
* nor the `.rvs-root` variables are in scope: the menu would come up with no
|
|
327
|
+
* border and no hover feedback. The panel therefore hands the shared component
|
|
328
|
+
* the four variables it reads, under this class — one menu component, one visual
|
|
329
|
+
* language, and no restyling of the other surfaces' menus.
|
|
330
|
+
*/
|
|
331
|
+
.rvs-menu-dock {
|
|
332
|
+
--rvs-fg: var(--dsw-alias-label-primary, #e6e6e6);
|
|
333
|
+
--rvs-hover: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, .14));
|
|
334
|
+
--rvs-border: var(--dsw-alias-border-l1, rgba(127, 127, 127, .28));
|
|
335
|
+
--rvs-border2: var(--dsw-alias-border-l2, rgba(127, 127, 127, .38));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
body:not([data-ds-dark-theme]) .rvs-menu-dock {
|
|
339
|
+
--rvs-fg: var(--dsw-alias-label-primary, #1f2328);
|
|
340
|
+
--rvs-hover: var(--dsw-alias-interactive-bg-hover, rgba(31, 35, 40, .07));
|
|
341
|
+
--rvs-border: var(--dsw-alias-border-l1, rgba(31, 35, 40, .16));
|
|
342
|
+
--rvs-border2: var(--dsw-alias-border-l1, rgba(31, 35, 40, .16));
|
|
343
|
+
}
|
|
@@ -165,6 +165,54 @@ function chipAt(at: number, text: string): RemovedChip | undefined {
|
|
|
165
165
|
return { at, text: truncated ? text.slice(0, MAX_CHIP_CHARS) : text, truncated }
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
/**
|
|
169
|
+
* How many lines of a collapsed deletion block travel as the tooltip preview.
|
|
170
|
+
*
|
|
171
|
+
* The pill only shows the COUNT, so the text is not on screen; it is still worth
|
|
172
|
+
* carrying a bounded prefix for the hover — enough to recognize the block, never
|
|
173
|
+
* enough to build a thousand-line title from a thousand-line removal.
|
|
174
|
+
*/
|
|
175
|
+
const MAX_BLOCK_PREVIEW_LINES = 20
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* One chip for a run of deleted lines.
|
|
179
|
+
*
|
|
180
|
+
* A block deletion used to emit one chip PER line, every one of them at column 0
|
|
181
|
+
* of the same anchor line: a ten-line removal became ten struck-through
|
|
182
|
+
* fragments printed on top of each other, which says neither "ten lines" nor
|
|
183
|
+
* what they were. A run longer than a single line now collapses into one chip
|
|
184
|
+
* carrying the count (rendered as `−N 行已删除`) with a bounded preview in its
|
|
185
|
+
* title; a one-line removal keeps the exact text at the cut, which is the case
|
|
186
|
+
* where the struck-through words are genuinely readable.
|
|
187
|
+
*
|
|
188
|
+
* @param deleted - the run's deleted texts, in order.
|
|
189
|
+
* @param line - the line the run belongs to.
|
|
190
|
+
* @param anchor - the mark's anchor line (see {@link chipOnLine}).
|
|
191
|
+
*/
|
|
192
|
+
function deletedRunChip(deleted: readonly string[], line: number, anchor: number): RemovedChip | undefined {
|
|
193
|
+
const [only] = deleted
|
|
194
|
+
if (only === undefined) return undefined
|
|
195
|
+
if (deleted.length === 1) {
|
|
196
|
+
const chip = chipAt(0, only)
|
|
197
|
+
return chip === undefined ? undefined : chipOnLine(chip, line, anchor)
|
|
198
|
+
}
|
|
199
|
+
const preview = deleted
|
|
200
|
+
.slice(0, MAX_BLOCK_PREVIEW_LINES)
|
|
201
|
+
.map(text => (text.length > MAX_CHIP_CHARS ? text.slice(0, MAX_CHIP_CHARS) : text))
|
|
202
|
+
.join('\n')
|
|
203
|
+
return chipOnLine(
|
|
204
|
+
{
|
|
205
|
+
at: 0,
|
|
206
|
+
text: preview,
|
|
207
|
+
// The preview was cut either by the line cap or by the line count.
|
|
208
|
+
truncated: deleted.length > MAX_BLOCK_PREVIEW_LINES || deleted.some(text => text.length > MAX_CHIP_CHARS),
|
|
209
|
+
count: deleted.length,
|
|
210
|
+
},
|
|
211
|
+
line,
|
|
212
|
+
anchor,
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
|
|
168
216
|
/**
|
|
169
217
|
* Attach `line` only when the fragment is NOT on the mark's anchor line.
|
|
170
218
|
*
|
|
@@ -196,24 +244,57 @@ function shortEnough(deleted: readonly string[], added: readonly AddedLine[]): b
|
|
|
196
244
|
/**
|
|
197
245
|
* Fill in `mark.inline` / `mark.removed` for one modified block.
|
|
198
246
|
*
|
|
199
|
-
* Pairing
|
|
200
|
-
*
|
|
201
|
-
*
|
|
247
|
+
* Pairing happens in two phases, and the first one is what keeps the highlight
|
|
248
|
+
* honest:
|
|
249
|
+
*
|
|
250
|
+
* 1. **Exact matches are consumed first, at any index.** A block that was merely
|
|
251
|
+
* REORDERED (`a`,`b` → `b`,`a`) has no character-level change in it, but
|
|
252
|
+
* positional pairing compares `a` against `b` and paints "these characters
|
|
253
|
+
* changed" on two lines that did not change at all. The same phase fixes the
|
|
254
|
+
* common "one line inserted inside an edited run" shape, where every line
|
|
255
|
+
* after the insertion used to be paired with the wrong neighbour. Lookup goes
|
|
256
|
+
* through a text → indices map, so the phase stays linear in the block rather
|
|
257
|
+
* than quadratic in its lines.
|
|
258
|
+
* 2. **What is left pairs by position** — the i-th edited deletion with the i-th
|
|
259
|
+
* remaining addition. git puts every deletion of a block before its
|
|
260
|
+
* additions, and a block with unequal counts leaves the extras as pure
|
|
261
|
+
* additions/removals.
|
|
202
262
|
*
|
|
203
263
|
* @param mark - the block's mark (mutated).
|
|
204
264
|
* @param deleted - the block's deleted texts, in order.
|
|
205
265
|
* @param added - the block's added lines, in order.
|
|
206
266
|
*/
|
|
207
267
|
function attachInline(mark: ChangeMark, deleted: readonly string[], added: readonly AddedLine[]): void {
|
|
208
|
-
|
|
268
|
+
// Phase 1 — consume lines that did not change, only moved.
|
|
269
|
+
const pending = new Map<string, number[]>()
|
|
270
|
+
added.forEach((item, index) => {
|
|
271
|
+
const list = pending.get(item.text)
|
|
272
|
+
if (list === undefined) pending.set(item.text, [index])
|
|
273
|
+
else list.push(index)
|
|
274
|
+
})
|
|
275
|
+
const edited: string[] = []
|
|
276
|
+
const used = new Array<boolean>(added.length).fill(false)
|
|
277
|
+
for (const text of deleted) {
|
|
278
|
+
const list = pending.get(text)
|
|
279
|
+
if (list === undefined || list.length === 0) {
|
|
280
|
+
edited.push(text)
|
|
281
|
+
continue
|
|
282
|
+
}
|
|
283
|
+
const index = list.shift()
|
|
284
|
+
if (index !== undefined) used[index] = true
|
|
285
|
+
}
|
|
286
|
+
const fresh = added.filter((_item, index) => !used[index])
|
|
287
|
+
|
|
288
|
+
// Phase 2 — positional pairing over the survivors.
|
|
289
|
+
const pairs = Math.min(edited.length, fresh.length)
|
|
209
290
|
const inline: InlineRange[] = []
|
|
210
291
|
const removed: RemovedChip[] = []
|
|
211
292
|
for (let index = 0; index < pairs; index += 1) {
|
|
212
|
-
const before =
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
293
|
+
const before = edited[index]
|
|
294
|
+
const item = fresh[index]
|
|
295
|
+
if (before === undefined || item === undefined) continue
|
|
296
|
+
const after = item.text
|
|
297
|
+
const line = item.line
|
|
217
298
|
const { head, oldMid, newMid } = splitCommon(before, after)
|
|
218
299
|
if (newMid.length === 0) {
|
|
219
300
|
// The line was only shortened: there is no new character to paint, so the
|
|
@@ -231,11 +312,10 @@ function attachInline(mark: ChangeMark, deleted: readonly string[], added: reado
|
|
|
231
312
|
for (const range of refineRanges(oldMid, newMid, head)) inline.push(rangeOnLine(range, line, mark.from))
|
|
232
313
|
}
|
|
233
314
|
// Deleted lines with no added counterpart: their text no longer exists in the
|
|
234
|
-
// new file, so it hangs on the anchor line's first column as
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
315
|
+
// new file, so it hangs on the anchor line's first column — as one collapsed
|
|
316
|
+
// chip when the run is longer than a line (see `deletedRunChip`).
|
|
317
|
+
const tailChip = deletedRunChip(edited.slice(pairs), mark.from, mark.from)
|
|
318
|
+
if (tailChip !== undefined) removed.push(tailChip)
|
|
239
319
|
if (inline.length > 0) mark.inline = inline
|
|
240
320
|
if (removed.length > 0) mark.removed = removed
|
|
241
321
|
}
|
|
@@ -280,13 +360,14 @@ function collectHunk(hunk: UnifiedHunk, marks: ChangeMark[], index: number): num
|
|
|
280
360
|
} else if (deleted.length > 0) {
|
|
281
361
|
const anchor = Math.max(1, line)
|
|
282
362
|
const mark: ChangeMark = { from: anchor, to: anchor, kind: 'del', hunk: index }
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
363
|
+
// A collapsed block pill carries a bounded preview only, so the per-line
|
|
364
|
+
// length cap (which exists to keep character-level work bounded) does not
|
|
365
|
+
// apply to it; a single deleted line still has to fit before its text is
|
|
366
|
+
// put on screen.
|
|
367
|
+
const printable = deleted.length > 1 || deleted.every(text => text.length <= MAX_INLINE_LINE)
|
|
368
|
+
if (inlineAllowed && printable) {
|
|
369
|
+
const chip = deletedRunChip(deleted, anchor, anchor)
|
|
370
|
+
if (chip !== undefined) mark.removed = [chip]
|
|
290
371
|
}
|
|
291
372
|
marks.push(mark)
|
|
292
373
|
first ??= anchor
|
|
@@ -319,9 +400,11 @@ function collectHunk(hunk: UnifiedHunk, marks: ChangeMark[], index: number): num
|
|
|
319
400
|
*
|
|
320
401
|
* @param hunks - served hunks for the whole session.
|
|
321
402
|
* @param stamp - identity of the comparison (file + baseline + turn).
|
|
403
|
+
* @param filePatch - the host's whole-file reverse patch, when it served one
|
|
404
|
+
* (see `ChangeSet.filePatch`); '' / missing = nothing to revert as a whole.
|
|
322
405
|
* @returns the mark set the editor paints, or {@link EMPTY_CHANGE_SET}.
|
|
323
406
|
*/
|
|
324
|
-
export function changeSetFromHunks(hunks: readonly UnifiedHunk[], stamp: string): ChangeSet {
|
|
407
|
+
export function changeSetFromHunks(hunks: readonly UnifiedHunk[], stamp: string, filePatch?: string): ChangeSet {
|
|
325
408
|
if (hunks.length === 0) return { marks: [], hunks: [], stamp, patches: [] }
|
|
326
409
|
const marks: ChangeMark[] = []
|
|
327
410
|
// `hunks[i]` / `patches[i]` must stay in step with the mark's `hunk` index, so
|
|
@@ -343,5 +426,6 @@ export function changeSetFromHunks(hunks: readonly UnifiedHunk[], stamp: string)
|
|
|
343
426
|
hunks: [...new Set(order.map(anchor => anchor.line))],
|
|
344
427
|
stamp,
|
|
345
428
|
patches,
|
|
429
|
+
...(filePatch === undefined || filePatch === '' ? {} : { filePatch }),
|
|
346
430
|
}
|
|
347
431
|
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 「这个文件我看过了」的本地标记。
|
|
3
|
+
*
|
|
4
|
+
* 会话改动面板原本只能看、不能收敛:一次三十个文件的重构,没有任何地方记得"这个我
|
|
5
|
+
* 已经审过",列表和游标每次都从头上开始。这里补的是**纯客户端**的审阅状态 —— 它不
|
|
6
|
+
* 写远端、不进账本、不影响任何一次 `git` 调用,因此是这条路线上唯一零风险的收敛手段
|
|
7
|
+
* ("接受改动"的另一半语义是真正的 `git apply --cached`,那要求基线等于索引,属于另一
|
|
8
|
+
* 个决定,**不在本模块**里)。
|
|
9
|
+
*
|
|
10
|
+
* ## 为什么键里带计数
|
|
11
|
+
*
|
|
12
|
+
* 键 = 路径 + 增删行数 + 状态。会话又改了同一批行(行数随之变化)时,旧标记自然失效,
|
|
13
|
+
* 文件重新变成"未审阅"——这正是想要的效果,而且不需要监听任何事件。行数完全没变的
|
|
14
|
+
* 二次编辑仍会被当成"已审阅",这是这套方案的已知盲点:它与"审阅的是哪一版"这个事实
|
|
15
|
+
* 相比,代价远小于为每个文件拉一次 diff 去算指纹。
|
|
16
|
+
*
|
|
17
|
+
* 纯函数 + 一个带上限的表,`scripts/check-review-state.mjs` 直接驱动真实的判定。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** 面板能给的一行(`RemoteChangedFile` 的投影)。 */
|
|
21
|
+
export interface ReviewSubject {
|
|
22
|
+
/** 远端绝对路径(唯一标识)。 */
|
|
23
|
+
path: string
|
|
24
|
+
added: number
|
|
25
|
+
deleted: number
|
|
26
|
+
status?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 已审阅集合:键 → 1(用对象是为了能直接 JSON 往返)。 */
|
|
30
|
+
export type ReviewedMap = Readonly<Record<string, 1>>
|
|
31
|
+
|
|
32
|
+
/** 一个会话最多记住这么多条(长命页面不能无限长)。 */
|
|
33
|
+
export const REVIEW_CAP = 1000
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 一行的审阅键。
|
|
37
|
+
*
|
|
38
|
+
* 计数进键里是刻意的:见文件头。`status` 也进键,因为"删掉了又加回来"和"一直在改"
|
|
39
|
+
* 是两件不同的事,标签变了就该重新看一遍。
|
|
40
|
+
*
|
|
41
|
+
* @param file - 面板的一行。
|
|
42
|
+
* @returns 稳定的键(路径里可能有任意字符,用 NUL 分隔不会与计数撞)。
|
|
43
|
+
*/
|
|
44
|
+
export function reviewKeyOf(file: ReviewSubject): string {
|
|
45
|
+
return `${file.path}\u0000${file.added}\u0000${file.deleted}\u0000${file.status ?? ''}`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 这一行是否已被标为审阅。 */
|
|
49
|
+
export function isReviewed(file: ReviewSubject, reviewed: ReviewedMap): boolean {
|
|
50
|
+
return reviewed[reviewKeyOf(file)] === 1
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 已审阅的行数(只数当前列表里的,所以它永远 ≤ 列表长度)。 */
|
|
54
|
+
export function reviewedCount(files: readonly ReviewSubject[], reviewed: ReviewedMap): number {
|
|
55
|
+
let count = 0
|
|
56
|
+
for (const file of files) if (isReviewed(file, reviewed)) count += 1
|
|
57
|
+
return count
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 切换一行的标记,返回新表(输入不被修改)。 */
|
|
61
|
+
export function toggleReviewed(files: readonly ReviewSubject[], reviewed: ReviewedMap, file: ReviewSubject): Record<string, 1> {
|
|
62
|
+
const key = reviewKeyOf(file)
|
|
63
|
+
const next: Record<string, 1> = {}
|
|
64
|
+
for (const [candidate, value] of Object.entries(reviewed)) next[candidate] = value
|
|
65
|
+
if (next[key] === 1) delete next[key]
|
|
66
|
+
else next[key] = 1
|
|
67
|
+
return pruneReviewed(files, next)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 全标或全清。 */
|
|
71
|
+
export function setAllReviewed(files: readonly ReviewSubject[], on: boolean): Record<string, 1> {
|
|
72
|
+
if (!on) return {}
|
|
73
|
+
const next: Record<string, 1> = {}
|
|
74
|
+
for (const file of files) {
|
|
75
|
+
if (next[reviewKeyOf(file)] === 1) continue
|
|
76
|
+
next[reviewKeyOf(file)] = 1
|
|
77
|
+
if (Object.keys(next).length >= REVIEW_CAP) break
|
|
78
|
+
}
|
|
79
|
+
return next
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 丢掉不属于当前列表的键。
|
|
84
|
+
*
|
|
85
|
+
* 列表每 3 秒重建一次,一条被删掉(或计数变了)的键如果留着,下次同一路径回到列表
|
|
86
|
+
* 时会被当成"已审阅"——那是凭空出现的勾。清理放在每次写入与每次加载后都做,代价是
|
|
87
|
+
* O(列表长度)。
|
|
88
|
+
*/
|
|
89
|
+
export function pruneReviewed(files: readonly ReviewSubject[], reviewed: ReviewedMap): Record<string, 1> {
|
|
90
|
+
const live = new Set(files.map(file => reviewKeyOf(file)))
|
|
91
|
+
const next: Record<string, 1> = {}
|
|
92
|
+
let kept = 0
|
|
93
|
+
for (const [key, value] of Object.entries(reviewed)) {
|
|
94
|
+
if (value !== 1 || !live.has(key)) continue
|
|
95
|
+
next[key] = 1
|
|
96
|
+
kept += 1
|
|
97
|
+
if (kept >= REVIEW_CAP) break
|
|
98
|
+
}
|
|
99
|
+
return next
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 解析持久化的一串 JSON。
|
|
104
|
+
*
|
|
105
|
+
* 任何畸形输入都给空表而不是抛错:这份状态是"看过没看过",读不出来最多重看一遍,
|
|
106
|
+
* 不值得让面板崩掉。键必须是字符串、值必须是 1,且受 {@link REVIEW_CAP} 限制。
|
|
107
|
+
*
|
|
108
|
+
* @param raw - `localStorage` 里存着的那串文本(可能为 null)。
|
|
109
|
+
*/
|
|
110
|
+
export function parseReviewed(raw: string | null | undefined): Record<string, 1> {
|
|
111
|
+
if (typeof raw !== 'string' || raw === '') return {}
|
|
112
|
+
let parsed: unknown
|
|
113
|
+
try {
|
|
114
|
+
parsed = JSON.parse(raw)
|
|
115
|
+
} catch {
|
|
116
|
+
return {}
|
|
117
|
+
}
|
|
118
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return {}
|
|
119
|
+
const next: Record<string, 1> = {}
|
|
120
|
+
let kept = 0
|
|
121
|
+
for (const [key, value] of Object.entries(parsed as Record<string, unknown>)) {
|
|
122
|
+
if (value !== 1 || key === '') continue
|
|
123
|
+
next[key] = 1
|
|
124
|
+
kept += 1
|
|
125
|
+
if (kept >= REVIEW_CAP) break
|
|
126
|
+
}
|
|
127
|
+
return next
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** 序列化(键数量已受上限约束,所以这串不会无限长)。 */
|
|
131
|
+
export function serializeReviewed(reviewed: ReviewedMap): string {
|
|
132
|
+
return JSON.stringify(reviewed)
|
|
133
|
+
}
|
package/src/client/i18n.ts
CHANGED
|
@@ -40,6 +40,11 @@ export const DYNAMIC_KEYS = [
|
|
|
40
40
|
// exit), which stores the key and renders it later.
|
|
41
41
|
'term.disconnected',
|
|
42
42
|
'term.closed',
|
|
43
|
+
// Reached through tRef.current(...) in the XTerm right-click menu (built
|
|
44
|
+
// inside a mount-once effect: literal keys, but not a t() call site).
|
|
45
|
+
'term.copy',
|
|
46
|
+
'term.paste',
|
|
47
|
+
'term.selectAll',
|
|
43
48
|
// Labels chosen through connectionLabelKey in connection.ts (a state → key
|
|
44
49
|
// mapping, so the call site is (connectionLabelKey(state))).
|
|
45
50
|
'connection.ok',
|
|
@@ -203,6 +208,9 @@ const zh: Record<string, string> = {
|
|
|
203
208
|
'term.empty': '还没有终端 —— 选好主机后点右上角 + 新建一个。',
|
|
204
209
|
'term.close': '关闭终端',
|
|
205
210
|
'term.closeTitle': '关闭这个终端',
|
|
211
|
+
'term.copy': '复制',
|
|
212
|
+
'term.paste': '粘贴',
|
|
213
|
+
'term.selectAll': '全选',
|
|
206
214
|
'term.noHosts': '还没有主机,请先去「设置 → 远程主机」配置。',
|
|
207
215
|
'tab.git': 'Git',
|
|
208
216
|
'git.hint': '请选择远端路径为 git 仓库的工作区。',
|
|
@@ -566,7 +574,26 @@ const zh: Record<string, string> = {
|
|
|
566
574
|
'changes.statusDeleted': '删除',
|
|
567
575
|
'changes.statusModified': '修改',
|
|
568
576
|
'changes.statusRenamed': '重命名',
|
|
569
|
-
'changes.truncated': '文件过多,只列出前 500
|
|
577
|
+
'changes.truncated': '文件过多,只列出前 500 个(统计数字也只算这 500 个)。',
|
|
578
|
+
'changes.excluded': '未统计构建产物目录:{dirs}',
|
|
579
|
+
'changes.markReviewed': '标记为已审阅',
|
|
580
|
+
'changes.unmarkReviewed': '取消审阅标记',
|
|
581
|
+
'changes.reviewCount': '已审阅 {done}/{total}',
|
|
582
|
+
'changes.reviewMenu': '审阅标记选项',
|
|
583
|
+
'changes.reviewAll': '全部标为已审阅',
|
|
584
|
+
'changes.reviewNone': '清除审阅标记',
|
|
585
|
+
'changes.menuOpen': '打开',
|
|
586
|
+
'changes.openInScm': '在 SCM 中查看',
|
|
587
|
+
'changes.copyPath': '复制远端路径',
|
|
588
|
+
'changes.revertFile': '撤销该文件的全部改动',
|
|
589
|
+
'changes.revertNotPossible': '无法撤销(新建、二进制或过大)',
|
|
590
|
+
'changes.revertCreation': '撤销新建(删除该文件)',
|
|
591
|
+
'changes.revertCreationOk': '删除该文件',
|
|
592
|
+
'changes.revertCreationTitle': '撤回这个新建文件?',
|
|
593
|
+
'changes.revertCreationText': '会删除 {path}。git 索引里还留着内容,可以用 git checkout 恢复。',
|
|
594
|
+
'changes.revertedFile': '已撤销该文件的改动',
|
|
595
|
+
'changes.revertFailed': '撤销失败',
|
|
596
|
+
'changes.deletedCreation': '已删除新建文件',
|
|
570
597
|
'changes.prev': '上一个修改点',
|
|
571
598
|
'changes.next': '下一个修改点',
|
|
572
599
|
'changes.navLabel': '改动跳转',
|
|
@@ -818,6 +845,9 @@ const en: Record<string, string> = {
|
|
|
818
845
|
'term.empty': 'No terminal yet — pick a host, then press + to open one.',
|
|
819
846
|
'term.close': 'Close terminal',
|
|
820
847
|
'term.closeTitle': 'Close this terminal',
|
|
848
|
+
'term.copy': 'Copy',
|
|
849
|
+
'term.paste': 'Paste',
|
|
850
|
+
'term.selectAll': 'Select all',
|
|
821
851
|
'term.noHosts': 'No hosts yet. Configure one in Settings → Remote Hosts first.',
|
|
822
852
|
'tab.git': 'Git',
|
|
823
853
|
'git.hint': 'Pick a workspace whose remote path is a git repository.',
|
|
@@ -1181,7 +1211,26 @@ const en: Record<string, string> = {
|
|
|
1181
1211
|
'changes.statusDeleted': 'deleted',
|
|
1182
1212
|
'changes.statusModified': 'modified',
|
|
1183
1213
|
'changes.statusRenamed': 'renamed',
|
|
1184
|
-
'changes.truncated': 'Too many files: the first 500 are listed (
|
|
1214
|
+
'changes.truncated': 'Too many files: the first 500 are listed (the counts cover only those).',
|
|
1215
|
+
'changes.excluded': 'Build output directories not counted: {dirs}',
|
|
1216
|
+
'changes.markReviewed': 'Mark as reviewed',
|
|
1217
|
+
'changes.unmarkReviewed': 'Clear the review mark',
|
|
1218
|
+
'changes.reviewCount': '{done}/{total} reviewed',
|
|
1219
|
+
'changes.reviewMenu': 'Review mark options',
|
|
1220
|
+
'changes.reviewAll': 'Mark all as reviewed',
|
|
1221
|
+
'changes.reviewNone': 'Clear all review marks',
|
|
1222
|
+
'changes.menuOpen': 'Open',
|
|
1223
|
+
'changes.openInScm': 'Show in Source Control',
|
|
1224
|
+
'changes.copyPath': 'Copy remote path',
|
|
1225
|
+
'changes.revertFile': 'Revert all changes in this file',
|
|
1226
|
+
'changes.revertNotPossible': 'Cannot be reverted (new file, binary or too large)',
|
|
1227
|
+
'changes.revertCreation': 'Undo the new file (delete it)',
|
|
1228
|
+
'changes.revertCreationOk': 'Delete the file',
|
|
1229
|
+
'changes.revertCreationTitle': 'Undo this new file?',
|
|
1230
|
+
'changes.revertCreationText': 'It deletes {path}. git keeps the bytes in its index, so git checkout can bring it back.',
|
|
1231
|
+
'changes.revertedFile': 'Reverted this file',
|
|
1232
|
+
'changes.revertFailed': 'Revert failed',
|
|
1233
|
+
'changes.deletedCreation': 'Deleted the new file',
|
|
1185
1234
|
'changes.prev': 'Previous change',
|
|
1186
1235
|
'changes.next': 'Next change',
|
|
1187
1236
|
'changes.navLabel': 'Change navigation',
|