dsh-remote-vs 0.21.1 → 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.
@@ -75,6 +75,14 @@ export interface RemovedChip {
75
75
  truncated: boolean
76
76
  /** 这个 chip 落在哪一行(1-based)。**省略 = 所属 mark 的 `from` 行**。 */
77
77
  line?: number
78
+ /**
79
+ * 这个 chip 代表的**被删行数**(省略或 1 = 单行/行内片段)。
80
+ *
81
+ * 一个整块删除(例如删掉 10 行)不能画成 10 个 chip 叠在同一列上 —— 那既读不出
82
+ * "删了 10 行",也读不出内容。此时 `count > 1`,`text` 改为携带**预览**(前若干
83
+ * 行的原文,供 tooltip),渲染成一个 `−N 行已删除` 的可读胶囊。
84
+ */
85
+ count?: number
78
86
  }
79
87
 
80
88
  /**
@@ -118,6 +126,15 @@ export interface ChangeSet {
118
126
  * 护栏,比在浏览器里重算一遍替换区间可靠。
119
127
  */
120
128
  patches?: string[]
129
+ /**
130
+ * 整文件的补丁(一个文件头 + 全部 hunk),用于"撤销该文件的全部改动"。
131
+ *
132
+ * 一次远端写而不是逐 hunk 循环:后者会让后面每个 hunk 的行号整体错位,撤到一半
133
+ * 报冲突,文件就停在半截状态。补丁由 Host 生成(浏览器一侧没有基线内容,自己拼
134
+ * 出来的补丁只会把别人的改动一起盖掉)。省略 = 这个文件没有可整体撤销的补丁
135
+ * (新建 / 二进制 / 字节被上限扣下)。
136
+ */
137
+ filePatch?: string
121
138
  }
122
139
 
123
140
  /** 换一份改动标记;`null` = 清空(有改动数据,但没有任何要画的东西)。 */
@@ -170,6 +187,9 @@ const WORD_ADD = Decoration.mark({ class: 'rvs-change-word-add' })
170
187
  /** 删除 chip 的悬浮说明。与 gutter 的 `LABEL` 一样,是编辑器侧的固定文案。 */
171
188
  const CHIP_TITLE = '已删除的内容'
172
189
 
190
+ /** 整块删除那种胶囊的悬浮说明(后面跟行数)。 */
191
+ const BLOCK_CHIP_TITLE = '已删除的整块内容'
192
+
173
193
  /**
174
194
  * 被删内容的零宽 widget。
175
195
  *
@@ -180,25 +200,37 @@ const CHIP_TITLE = '已删除的内容'
180
200
  class RemovedChipWidget extends WidgetType {
181
201
  private readonly text: string
182
202
  private readonly truncated: boolean
203
+ private readonly count: number
183
204
 
184
- constructor(text: string, truncated: boolean) {
205
+ constructor(text: string, truncated: boolean, count = 0) {
185
206
  super()
186
207
  this.text = text
187
208
  this.truncated = truncated
209
+ this.count = count
188
210
  }
189
211
 
190
212
  eq(other: WidgetType): boolean {
191
213
  return other instanceof RemovedChipWidget
192
214
  && other.text === this.text
193
215
  && other.truncated === this.truncated
216
+ && other.count === this.count
194
217
  }
195
218
 
196
219
  toDOM(): HTMLElement {
197
220
  const chip = document.createElement('span')
198
- chip.className = 'rvs-change-word-del'
199
- chip.textContent = this.truncated ? `${this.text}…` : this.text
200
- chip.title = CHIP_TITLE
201
- chip.setAttribute('aria-label', CHIP_TITLE)
221
+ /**
222
+ * 整块删除(`count > 1`)读成一枚胶囊,不是一行删除线文字。
223
+ *
224
+ * 行内删短(`const a = 1 + 2` → `const a = 1`)仍然是划掉的原文 —— 那里被删的
225
+ * 是一个片段,位置和内容都能直接读。多行整块没有这个性质:原文是一个段落,
226
+ * 划线堆在行首只会糊成一片,所以这里只报**行数**,原文进 tooltip(已在数据层
227
+ * 限过长度,见 `model.ts` 的 `deletedRunChip`)。
228
+ */
229
+ const block = this.count > 1
230
+ chip.className = block ? 'rvs-change-word-del rvs-change-block-del' : 'rvs-change-word-del'
231
+ chip.textContent = block ? `−${this.count} 行已删除` : (this.truncated ? `${this.text}…` : this.text)
232
+ chip.title = block ? `${BLOCK_CHIP_TITLE}(${this.count} 行)\n${this.text}` : CHIP_TITLE
233
+ chip.setAttribute('aria-label', chip.title)
202
234
  return chip
203
235
  }
204
236
  }
@@ -209,7 +241,7 @@ class RemovedChipWidget extends WidgetType {
209
241
  * `-2e8`、chip `-1e8`、字符区间 `-1`)。
210
242
  */
211
243
  function chipDecoration(chip: RemovedChip): Decoration {
212
- return Decoration.widget({ widget: new RemovedChipWidget(chip.text, chip.truncated), side: -1 })
244
+ return Decoration.widget({ widget: new RemovedChipWidget(chip.text, chip.truncated, chip.count ?? 0), side: -1 })
213
245
  }
214
246
 
215
247
  /** 一行的行内片段:新增字符区间 + 删除 chip。 */
@@ -251,6 +283,7 @@ function inlineIndexOf(set: ChangeSet | null, doc: Text): Map<number, LineInline
251
283
  at: Math.max(0, Math.round(chip.at)),
252
284
  text: chip.text,
253
285
  truncated: chip.truncated === true,
286
+ ...(chip.count === undefined ? {} : { count: chip.count }),
254
287
  })
255
288
  }
256
289
  }
@@ -783,6 +783,15 @@ export function ContextMenu(props: {
783
783
  y: number
784
784
  entries: MenuEntry[]
785
785
  onClose: () => void
786
+ /**
787
+ * Extra class on the menu box, for a surface that lives OUTSIDE `.rvs-root`.
788
+ *
789
+ * The menu is portalled to `document.body`, so the `--rvs-*` variables defined
790
+ * on the root never reach it: an outside surface (the change panel above the
791
+ * composer) supplies its own palette through this hook instead of forking the
792
+ * component.
793
+ */
794
+ className?: string
786
795
  }): ReactNode {
787
796
  const boxRef = useRef<HTMLDivElement>(null)
788
797
  const [pos, setPos] = useState({ left: props.x, top: props.y })
@@ -896,7 +905,13 @@ export function ContextMenu(props: {
896
905
  if (typeof document === 'undefined') return null
897
906
  return createPortal(
898
907
  <div className="rvs-portal">
899
- <div ref={boxRef} className="rvs-menu" role="menu" style={{ left: pos.left, top: pos.top }} onKeyDown={onMenuKeyDown}>
908
+ <div
909
+ ref={boxRef}
910
+ className={props.className === undefined ? 'rvs-menu' : `rvs-menu ${props.className}`}
911
+ role="menu"
912
+ style={{ left: pos.left, top: pos.top }}
913
+ onKeyDown={onMenuKeyDown}
914
+ >
900
915
  {props.entries.map((entry, index) => (
901
916
  <div key={`${entry.label}-${index}`}>
902
917
  {entry.separated === true && index > 0 && <div className="rvs-menu-sep" />}
@@ -1836,6 +1836,29 @@ body:not([data-ds-dark-theme]) .rvs-edge .rvs-change-word-del {
1836
1836
  background-color: rgba(207, 34, 46, .14);
1837
1837
  }
1838
1838
 
1839
+ /**
1840
+ * 整块删除:一枚带行数的胶囊,不是一行划掉的文字。
1841
+ *
1842
+ * 多行删除的原文是一个段落,划线堆在锚点行首只会糊成一片(数据层因此把 `count > 1`
1843
+ * 的 chip 压成一枚,见 `change-marks.ts` 的 `RemovedChipWidget`)。这里只做外形:
1844
+ * 去掉继承来的删除线(胶囊不是"被划掉的字符串"),字号与计数对齐,别把行高撑开。
1845
+ */
1846
+ .rvs-edge .rvs-change-block-del {
1847
+ padding: 0 4px;
1848
+ margin: 0 1px;
1849
+ border-radius: 3px;
1850
+ background-color: rgba(248, 81, 73, .18);
1851
+ font-size: 11px;
1852
+ font-variant-numeric: tabular-nums;
1853
+ text-decoration: none;
1854
+ opacity: 1;
1855
+ white-space: nowrap;
1856
+ }
1857
+
1858
+ body:not([data-ds-dark-theme]) .rvs-edge .rvs-change-block-del {
1859
+ background-color: rgba(207, 34, 46, .14);
1860
+ }
1861
+
1839
1862
  /**
1840
1863
  * 改动跳转按钮:浮在编辑器右上角。
1841
1864
  *
package/src/protocol.ts CHANGED
@@ -471,6 +471,18 @@ export interface RemoteChangedFile {
471
471
  oversized?: true
472
472
  /** Change kind from --name-status; undefined when git gave none. */
473
473
  status?: 'A' | 'M' | 'D' | 'R' | 'C' | 'T' | 'U'
474
+ /**
475
+ * What "undo this file" may do, decided by the HOST (the client never guesses).
476
+ *
477
+ * - `patch`: a real reverse patch exists — reverting restores the session
478
+ * baseline in one `git apply -R`.
479
+ * - `delete`: the file is a whole-file CREATION git has a copy of (a tracked
480
+ * addition), so the only reverse is deleting it. Recoverable from the index,
481
+ * but still a destructive write, so the client must confirm it.
482
+ * - absent: nothing can be undone — an UNTRACKED creation (git holds no copy),
483
+ * a binary, or a file whose bytes were withheld by the size caps.
484
+ */
485
+ revert?: 'patch' | 'delete'
474
486
  }
475
487
 
476
488
  /**
@@ -493,8 +505,23 @@ export interface RemoteChangesSummary {
493
505
  deleted: number
494
506
  /** Wall-clock ms when this summary was last recomputed. */
495
507
  at: number
496
- /** More files than the cap: `files` is truncated but the totals are whole. */
508
+ /**
509
+ * More files than the cap: `files` is truncated and so are `added` / `deleted`.
510
+ *
511
+ * The totals are summed from the rows that made it into `files` (the cost of
512
+ * counting the rest is a read per path), which is why the panel says "N files
513
+ * changed" about a subset and must not present the counts as whole-tree
514
+ * totals.
515
+ */
497
516
  truncated?: true
517
+ /**
518
+ * Directory names the new-file scan was told to skip (build output, caches).
519
+ *
520
+ * Present only when the exclusion ran, and listed rather than merely applied:
521
+ * a file the user expected to see must never be missing without a reason. The
522
+ * SCM panel stays the surface that shows every path.
523
+ */
524
+ excludedDirs?: string[]
498
525
  /** A scan is running right now (the slow one counts); the list will refresh. */
499
526
  pending: boolean
500
527
  /** Why this session has no ledger (local session, no git, timeout, …). */
@@ -509,6 +536,15 @@ export interface RemoteChangesDiff {
509
536
  display: string
510
537
  /** Text hunks (empty for binary/missing). */
511
538
  hunks: UnifiedHunk[]
539
+ /**
540
+ * The WHOLE file as one reverse-applicable patch (`git apply -R`).
541
+ *
542
+ * One write instead of one per hunk, which is what "revert everything this
543
+ * session did to this file" needs. Empty when the reverse is not expressible
544
+ * as a patch (see `RemoteChangedFile.revert`), which is the fail-closed answer
545
+ * the client must not try to build itself.
546
+ */
547
+ patch?: string
512
548
  /** File status at turn end (A/M/D/…), when git reported one. */
513
549
  status?: 'A' | 'M' | 'D' | 'R' | 'C' | 'T' | 'U'
514
550
  /** The diff was cut at the byte cap: `hunks` is a prefix. */