dsh-git-scm 0.1.0 → 0.2.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/lib/client.js CHANGED
@@ -83,15 +83,14 @@
83
83
  "action.deleteTag": "Delete {name}",
84
84
  "action.showMore": "Load more",
85
85
  "action.openDiff": "Show changes in {path}",
86
- "action.openNative": "Open in changes view",
87
86
  "action.moreChanges": "More change actions",
87
+ "action.viewTree": "View changes as tree",
88
+ "action.viewList": "View changes as list",
88
89
  "action.switchBranch": "Switch branch",
89
90
  "action.dockBottom": "Dock the preview below",
90
91
  "action.dockRight": "Dock the preview to the right",
91
92
  "action.search": "Find in the comparison",
92
93
  "action.back": "Back",
93
- "action.stageSelected": "Stage selected",
94
- "action.unstageSelected": "Unstage selected",
95
94
  "action.discardSelected": "Discard selected",
96
95
  "action.clearSelection": "Clear selection",
97
96
  "action.checkoutSelected": "Check out",
@@ -142,8 +141,6 @@
142
141
  "prompt.remoteField": "Remote URL",
143
142
  "prompt.remotePlaceholder": "https://github.com/owner/repo.git",
144
143
  "menu.showDiff": "Show changes",
145
- "menu.openNative": "Open in the app changes view",
146
- "menu.previewInPanel": "Preview in this panel",
147
144
  "menu.openFile": "Open file",
148
145
  "menu.fileHistory": "File history",
149
146
  "menu.discardAll": "Discard all changes",
@@ -211,6 +208,8 @@
211
208
  "diff.close": "Close comparison",
212
209
  "diff.modeSplit": "Side-by-side view",
213
210
  "diff.modeUnified": "Single-column view",
211
+ "diff.wrapOn": "Wrap lines",
212
+ "diff.wrapOff": "Turn off line wrap",
214
213
  "diff.maximize": "Expand comparison",
215
214
  "diff.restore": "Restore comparison height",
216
215
  "diff.resize": "Drag to resize the comparison",
@@ -280,7 +279,6 @@
280
279
  "toast.tagDeleted": "Tag deleted",
281
280
  "toast.copied": "Copied to the clipboard",
282
281
  "toast.copyFailed": "The clipboard is not available",
283
- "toast.nativeUnavailable": "The app changes view is not available in this profile",
284
282
  "toast.fileUnavailable": "This file cannot be opened here",
285
283
  "toast.revealed": "Revealed in the file manager",
286
284
  "toast.ignored": "Added to .gitignore",
@@ -373,15 +371,14 @@
373
371
  "action.deleteTag": "删除 {name}",
374
372
  "action.showMore": "加载更多",
375
373
  "action.openDiff": "查看 {path} 的更改",
376
- "action.openNative": "在变更视图中打开",
377
374
  "action.moreChanges": "更多操作",
375
+ "action.viewTree": "以树形式查看更改",
376
+ "action.viewList": "以列表形式查看更改",
378
377
  "action.switchBranch": "切换分支",
379
378
  "action.dockBottom": "预览停靠到下方",
380
379
  "action.dockRight": "预览停靠到右侧",
381
380
  "action.search": "在对比中查找",
382
381
  "action.back": "返回",
383
- "action.stageSelected": "暂存所选",
384
- "action.unstageSelected": "取消暂存所选",
385
382
  "action.discardSelected": "丢弃所选",
386
383
  "action.clearSelection": "取消选择",
387
384
  "action.checkoutSelected": "切换",
@@ -432,8 +429,6 @@
432
429
  "prompt.remoteField": "远程仓库地址",
433
430
  "prompt.remotePlaceholder": "https://github.com/owner/repo.git",
434
431
  "menu.showDiff": "查看更改",
435
- "menu.openNative": "在应用自带的变更视图中打开",
436
- "menu.previewInPanel": "在面板内预览",
437
432
  "menu.openFile": "打开文件",
438
433
  "menu.fileHistory": "查看文件历史",
439
434
  "menu.discardAll": "放弃所有更改",
@@ -501,6 +496,8 @@
501
496
  "diff.close": "关闭对比",
502
497
  "diff.modeSplit": "并排对比",
503
498
  "diff.modeUnified": "单栏对比",
499
+ "diff.wrapOn": "自动换行",
500
+ "diff.wrapOff": "关闭自动换行",
504
501
  "diff.maximize": "展开对比",
505
502
  "diff.restore": "还原对比高度",
506
503
  "diff.resize": "拖动调整对比区域高度",
@@ -570,7 +567,6 @@
570
567
  "toast.tagDeleted": "已删除标签",
571
568
  "toast.copied": "已复制到剪贴板",
572
569
  "toast.copyFailed": "剪贴板不可用",
573
- "toast.nativeUnavailable": "当前配置未启用应用自带的变更视图",
574
570
  "toast.fileUnavailable": "无法在此打开该文件",
575
571
  "toast.revealed": "已在访达中显示",
576
572
  "toast.ignored": "已添加到 .gitignore",
@@ -1025,8 +1021,6 @@
1025
1021
  .dgscm-branch-flag--unpublished { color: var(--dsw-alias-state-success-primary); font-family: var(--ds-font-family-code, ui-monospace, Menlo, monospace); font-size: 10px; font-weight: 700; }
1026
1022
  .dgscm-branch-flag--current { color: var(--dsw-alias-label-secondary); }
1027
1023
  .dgscm-row-chevron { display: inline-flex; flex: none; width: 14px; justify-content: center; }
1028
- .dgscm-row-check { display: inline-flex; flex: none; align-items: center; margin: 0; }
1029
- .dgscm-row-check input { width: 12px; height: 12px; margin: 0; accent-color: var(--dsw-alias-brand-primary); cursor: pointer; }
1030
1024
  .dgscm-row-mark {
1031
1025
  display: inline-flex;
1032
1026
  flex: none;
@@ -1046,6 +1040,21 @@
1046
1040
  text-overflow: ellipsis;
1047
1041
  white-space: nowrap;
1048
1042
  }
1043
+ /* A narrow change row gives up the directory suffix before the file name:
1044
+ the suffix absorbs the shortage first, and the name only truncates once it
1045
+ is gone. */
1046
+ .dgscm-row--file .dgscm-row-dir { flex-shrink: 999; }
1047
+ /* Change tree: file rows pad past the folder chevron so a file glyph lines up
1048
+ with a folder glyph at the same depth. */
1049
+ .dgscm-row--dir { cursor: pointer; }
1050
+ .dgscm-row-treepad { flex: none; width: 14px; }
1051
+ .dgscm-row-glyph--folder { color: var(--dsw-alias-label-tertiary); }
1052
+ .dgscm-row--dir .dgscm-row-name { font-weight: 500; }
1053
+ /* A directory shows its changed-file count only while hovered or focused,
1054
+ together with its actions. */
1055
+ .dgscm-row--dir .dgscm-row-note { opacity: 0; }
1056
+ .dgscm-row--dir:hover .dgscm-row-note,
1057
+ .dgscm-row--dir:focus-within .dgscm-row-note { opacity: 1; }
1049
1058
  .dgscm-row-end { display: flex; flex: none; align-items: center; gap: 4px; margin-left: auto; }
1050
1059
  .dgscm-row-actions {
1051
1060
  display: flex;
@@ -1153,7 +1162,7 @@
1153
1162
  .dgscm-main { display: flex; flex: 1 1 auto; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
1154
1163
  .dgscm-root--row { flex-direction: row; }
1155
1164
  .dgscm-root--row > .dgscm-main { flex: 1 1 auto; min-width: 300px; }
1156
- .dgscm-diffpane--right { height: auto !important; width: 360px; border-top: none; border-left: 0.5px solid var(--dsw-alias-border-l1); }
1165
+ .dgscm-diffpane--right { height: auto !important; width: 360px; min-width: 280px; border-top: none; border-left: 0.5px solid var(--dsw-alias-border-l1); }
1157
1166
  /* The pane's left edge is itself a resize handle, so the border can be dragged;
1158
1167
  it also overlaps the list column by 2px, so it clears the sticky headers. */
1159
1168
  .dgscm-resize-edge {
@@ -1344,6 +1353,12 @@
1344
1353
  white-space: pre-wrap;
1345
1354
  word-break: break-all;
1346
1355
  }
1356
+ /* Word-wrap toggle: without it, long lines stay on one line and scroll. */
1357
+ .dgscm-diff-body--nowrap .dgscm-difftext {
1358
+ white-space: pre;
1359
+ word-break: normal;
1360
+ overflow-wrap: normal;
1361
+ }
1347
1362
  .dgscm-diffgap {
1348
1363
  display: flex;
1349
1364
  align-items: center;
@@ -1441,9 +1456,11 @@
1441
1456
  .dgscm-review-path { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1442
1457
  .dgscm-review-dir { min-width: 0; overflow: hidden; color: var(--dsw-alias-label-tertiary); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
1443
1458
  .dgscm-review-counts { display: flex; flex: none; gap: 6px; margin-left: auto; font-family: var(--ds-font-family-code, ui-monospace, Menlo, monospace); font-size: 10px; }
1459
+ /* The review row keeps the tracking status on the right, beside the line counts. */
1460
+ .dgscm-review-end { display: flex; flex: none; align-items: center; gap: 4px; margin-left: auto; }
1444
1461
  .dgscm-review-add { color: var(--dsw-alias-state-success-primary); }
1445
1462
  .dgscm-review-del { color: var(--dsw-alias-state-error-primary); }
1446
- .dgscm-review-subject { min-width: 0; overflow: hidden; color: var(--dsw-alias-label-secondary); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
1463
+ .dgscm-review-subject { flex: 1 1 auto; min-width: 0; overflow: hidden; color: var(--dsw-alias-label-secondary); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
1447
1464
  .dgscm-review-filter { flex: none; padding: 4px 8px; border-bottom: 0.5px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-1); }
1448
1465
 
1449
1466
  .dgscm-popover {
@@ -1650,7 +1667,6 @@
1650
1667
  }
1651
1668
 
1652
1669
  @container dgscm (max-width: 340px) {
1653
- .dgscm-row-dir { display: none; }
1654
1670
  .dgscm-repo-name { max-width: 40%; }
1655
1671
  .dgscm-row-meta { display: none; }
1656
1672
  }
@@ -1932,6 +1948,10 @@
1932
1948
  function PushIcon(props) {
1933
1949
  return h(Glyph, props, h("path", { d: "M8 13.4V3.2" }), h("path", { d: "M4.3 6.9 8 3.2l3.7 3.7" }));
1934
1950
  }
1951
+ /** Word-wrap glyph: text lines with a returning arrow. */
1952
+ function WrapIcon(props) {
1953
+ return h(Glyph, props, h("path", { d: "M2.6 4h10.8" }), h("path", { d: "M2.6 8h8.6" }), h("path", { d: "M2.6 12h4.4" }), h("path", { d: "M11.2 8a2.1 2.1 0 0 1 0 4.2H8.6" }), h("path", { d: "M10 10.4 8.4 12.2l1.6 1.8" }));
1954
+ }
1935
1955
  /** Check glyph. */
1936
1956
  function CheckIcon(props) {
1937
1957
  return h(Glyph, props, h("path", { d: "M3.2 8.4 6.4 11.6 12.8 4.6" }));
@@ -1975,6 +1995,10 @@
1975
1995
  function FileIcon(props) {
1976
1996
  return h(Glyph, props, h("path", { d: "M4.2 2.6h4.9l3.1 3.1v7.7H4.2z" }), h("path", { d: "M9.1 2.6v3.1h3.1" }));
1977
1997
  }
1998
+ /** Folder glyph. */
1999
+ function FolderIcon(props) {
2000
+ return h(Glyph, props, h("path", { d: "M2.4 4.4a1 1 0 0 1 1-1h2.4l1.3 1.4h5.5a1 1 0 0 1 1 1v6.2a1 1 0 0 1-1 1H3.4a1 1 0 0 1-1-1z" }));
2001
+ }
1978
2002
  /** More (horizontal dots) glyph. */
1979
2003
  function MoreIcon(props) {
1980
2004
  return h(Glyph, {
@@ -2014,6 +2038,10 @@
2014
2038
  function RowsIcon(props) {
2015
2039
  return h(Glyph, props, h("path", { d: "M2.8 4h10.4M2.8 8h10.4M2.8 12h10.4" }));
2016
2040
  }
2041
+ /** Directory-tree glyph, for switching a change list to its tree view. */
2042
+ function TreeIcon(props) {
2043
+ return h(Glyph, props, h("path", { d: "M3.2 3.2v9.6" }), h("path", { d: "M3.2 5.2h3M3.2 8h5.4M3.2 10.8h6.8" }));
2044
+ }
2017
2045
  /** Side-by-side (two columns) glyph. */
2018
2046
  function ColumnsIcon(props) {
2019
2047
  return h(Glyph, props, h("rect", {
@@ -2099,6 +2127,7 @@
2099
2127
  PushIcon,
2100
2128
  CloudUploadIcon,
2101
2129
  SparkleIcon,
2130
+ WrapIcon,
2102
2131
  CheckIcon,
2103
2132
  PlusIcon,
2104
2133
  MinusIcon,
@@ -2109,10 +2138,12 @@
2109
2138
  CloseIcon,
2110
2139
  WarnIcon,
2111
2140
  FileIcon,
2141
+ FolderIcon,
2112
2142
  MoreIcon,
2113
2143
  CopyIcon,
2114
2144
  ExternalIcon,
2115
2145
  RowsIcon,
2146
+ TreeIcon,
2116
2147
  ColumnsIcon,
2117
2148
  MaximizeIcon,
2118
2149
  RestoreIcon,
@@ -2277,10 +2308,6 @@
2277
2308
  const normalized = path.replace(/\\/g, "/").replace(/^(?:\.\/)+/, "");
2278
2309
  return `dsh-resource://file/session/${encode(String(sessionId))}/${normalized.split("/").map(encode).join("/")}`;
2279
2310
  }
2280
- /** The app's own local-changes view: the address its router claims for one Session. */
2281
- function nativeChangesAddress(sessionId) {
2282
- return `dsh-resource://forge-changes/${encodeURIComponent(String(sessionId))}/local`;
2283
- }
2284
2311
  /** Context lines kept on each side of a collapsed unchanged run. */
2285
2312
  var DIFF_CONTEXT_KEEP = 3;
2286
2313
  /** Shortest unchanged run worth collapsing. */
@@ -2293,6 +2320,12 @@
2293
2320
  var DIFF_HEIGHT_MIN = 140;
2294
2321
  /** Room the list above the comparison keeps when the pane is dragged or expanded. */
2295
2322
  var DIFF_HEIGHT_RESERVED = 170;
2323
+ /**
2324
+ * localStorage key of the comparison pane's word-wrap preference.
2325
+ */
2326
+ var DIFF_WRAP_KEY = "dsh-git-scm.diff-wrap";
2327
+ /** Whether the comparison wraps long lines when nothing is stored. */
2328
+ var DIFF_WRAP_DEFAULT = true;
2296
2329
  /** localStorage key of the preview dock side. */
2297
2330
  var PREVIEW_LAYOUT_KEY = "dsh-git-scm.preview-layout";
2298
2331
  /** localStorage key of the preview width when docked to the right. */
@@ -2300,7 +2333,7 @@
2300
2333
  /** Width the preview opens with when docked to the right. */
2301
2334
  var PREVIEW_WIDTH_DEFAULT = 360;
2302
2335
  /** Smallest preview width when docked to the right. */
2303
- var PREVIEW_WIDTH_MIN = 160;
2336
+ var PREVIEW_WIDTH_MIN = 280;
2304
2337
  /** Narrowest left column allowed when the preview is docked to the right. */
2305
2338
  var PREVIEW_WIDTH_RESERVED = 300;
2306
2339
  /** Read the stored dock side. */
@@ -2332,6 +2365,36 @@
2332
2365
  localStorage.setItem(PREVIEW_WIDTH_KEY, String(Math.round(px)));
2333
2366
  } catch {}
2334
2367
  }
2368
+ /** Read the stored word-wrap preference, falling back to wrapping. */
2369
+ function readDiffWrap() {
2370
+ try {
2371
+ return localStorage.getItem(DIFF_WRAP_KEY) !== "0";
2372
+ } catch {
2373
+ return DIFF_WRAP_DEFAULT;
2374
+ }
2375
+ }
2376
+ /** Remember the comparison pane's word-wrap preference across mounts. */
2377
+ function storeDiffWrap(wrapped) {
2378
+ try {
2379
+ localStorage.setItem(DIFF_WRAP_KEY, wrapped ? "1" : "0");
2380
+ } catch {}
2381
+ }
2382
+ /** localStorage key of the change-list view: the flat list or the directory tree. */
2383
+ var CHANGE_VIEW_KEY = "dsh-git-scm.change-view";
2384
+ /** Read the stored change-list view; the flat list is the default. */
2385
+ function readChangeView() {
2386
+ try {
2387
+ return localStorage.getItem(CHANGE_VIEW_KEY) === "tree" ? "tree" : "list";
2388
+ } catch {
2389
+ return "list";
2390
+ }
2391
+ }
2392
+ /** Remember the change-list view across panel mounts. */
2393
+ function storeChangeView(view) {
2394
+ try {
2395
+ localStorage.setItem(CHANGE_VIEW_KEY, view);
2396
+ } catch {}
2397
+ }
2335
2398
  /** Read the stored comparison height, falling back to the default. */
2336
2399
  function readDiffHeight() {
2337
2400
  try {
@@ -2579,7 +2642,7 @@
2579
2642
  const h = React.createElement;
2580
2643
  const { useCallback, useEffect, useMemo, useRef, useState } = React;
2581
2644
  const icons = createIcons(React);
2582
- const { BranchIcon, CheckIcon, ChevronIcon, CloseIcon, CommitIcon, DiscardIcon, FetchIcon, FileIcon, MergeIcon, MinusIcon, MoreIcon, PlusIcon, PullIcon, PushIcon, RefreshIcon, RemoteIcon, RepoIcon, StashIcon, TagIcon, WarnIcon, ExternalIcon, RowsIcon, ColumnsIcon, MaximizeIcon, RestoreIcon, DockBottomIcon, DockRightIcon, SearchIcon, HistoryIcon, CaretIcon, BackIcon, CopyIcon, TrashIcon, SpinnerIcon, CloudUploadIcon, SparkleIcon } = icons;
2645
+ const { BranchIcon, CheckIcon, ChevronIcon, CloseIcon, CommitIcon, DiscardIcon, FetchIcon, FileIcon, FolderIcon, MergeIcon, MinusIcon, MoreIcon, PlusIcon, PullIcon, PushIcon, RefreshIcon, RemoteIcon, RepoIcon, StashIcon, TagIcon, WarnIcon, ExternalIcon, RowsIcon, TreeIcon, ColumnsIcon, MaximizeIcon, RestoreIcon, DockBottomIcon, DockRightIcon, SearchIcon, HistoryIcon, CaretIcon, BackIcon, CopyIcon, TrashIcon, SpinnerIcon, CloudUploadIcon, SparkleIcon, WrapIcon } = icons;
2583
2646
  const { ContextMenu } = createMenu(React, icons);
2584
2647
  /**
2585
2648
  * Build the error a failed Git call is reported with.
@@ -2634,16 +2697,77 @@
2634
2697
  * @returns {{ dir: string, base: string }} the split path.
2635
2698
  */
2636
2699
  function splitPath(path) {
2637
- const at = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
2700
+ const trimmed = String(path).replace(/[\\/]+$/, "");
2701
+ const at = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
2638
2702
  return at < 0 ? {
2639
2703
  dir: "",
2640
- base: path
2704
+ base: trimmed
2641
2705
  } : {
2642
- dir: path.slice(0, at),
2643
- base: path.slice(at + 1)
2706
+ dir: trimmed.slice(0, at),
2707
+ base: trimmed.slice(at + 1)
2644
2708
  };
2645
2709
  }
2646
2710
  /**
2711
+ * Whether a change entry names a directory rather than a file. A Host that
2712
+ * collapses untracked directories reports them with a trailing separator.
2713
+ * @param {string} path - repository-relative change path.
2714
+ * @returns {boolean} whether the entry is a directory.
2715
+ */
2716
+ function isDirectoryEntry(path) {
2717
+ return typeof path === "string" && /[\\/]$/.test(path);
2718
+ }
2719
+ /**
2720
+ * Group changed files into a directory tree.
2721
+ * @param {object[]} files - changed files carrying repository-relative paths.
2722
+ * @returns {object} the root node: `{ dirs: Map, files: object[] }`.
2723
+ */
2724
+ function buildChangeTree(files) {
2725
+ const root = {
2726
+ dirs: /* @__PURE__ */ new Map(),
2727
+ files: []
2728
+ };
2729
+ for (const file of files) {
2730
+ const segments = String(file.path).replace(/\\/g, "/").split("/").filter((segment) => segment !== "");
2731
+ let node = root;
2732
+ for (let index = 0; index < segments.length - 1; index += 1) {
2733
+ const name = segments[index];
2734
+ let child = node.dirs.get(name);
2735
+ if (child === void 0) {
2736
+ child = {
2737
+ name,
2738
+ path: segments.slice(0, index + 1).join("/"),
2739
+ dirs: /* @__PURE__ */ new Map(),
2740
+ files: []
2741
+ };
2742
+ node.dirs.set(name, child);
2743
+ }
2744
+ node = child;
2745
+ }
2746
+ node.files.push(file);
2747
+ }
2748
+ return root;
2749
+ }
2750
+ /**
2751
+ * Count the changed files of one directory subtree.
2752
+ * @param {object} node - a node of the change tree.
2753
+ * @returns {number} the number of changed files underneath.
2754
+ */
2755
+ function countTreeFiles(node) {
2756
+ let count = node.files.length;
2757
+ for (const child of node.dirs.values()) count += countTreeFiles(child);
2758
+ return count;
2759
+ }
2760
+ /**
2761
+ * Collect the changed files of one directory subtree.
2762
+ * @param {object} node - a node of the change tree.
2763
+ * @returns {object[]} the changed files underneath.
2764
+ */
2765
+ function collectTreeFiles(node) {
2766
+ const files = [...node.files];
2767
+ for (const child of node.dirs.values()) files.push(...collectTreeFiles(child));
2768
+ return files;
2769
+ }
2770
+ /**
2647
2771
  * Render a timestamp as a coarse relative time in the active language.
2648
2772
  * @param {number|null} epochMs - milliseconds since the epoch.
2649
2773
  * @param {(key: string, params?: object) => string} t - translate function.
@@ -2724,13 +2848,14 @@
2724
2848
  * @param {object} props - `label`, `onClick`, `disabled`, `busy`, and children.
2725
2849
  * @returns {object} the button.
2726
2850
  */
2727
- function IconButton({ label, onClick, disabled = false, busy = false, className = "", children }) {
2851
+ function IconButton({ label, onClick, disabled = false, busy = false, className = "", pressed = void 0, children }) {
2728
2852
  return h("button", {
2729
2853
  type: "button",
2730
2854
  className: `dgscm-icon-button${busy ? " dgscm-icon-button--spinning" : ""}${className === "" ? "" : ` ${className}`}`,
2731
2855
  title: label,
2732
2856
  "aria-label": label,
2733
2857
  "aria-busy": busy || void 0,
2858
+ "aria-pressed": pressed === void 0 ? void 0 : pressed ? "true" : "false",
2734
2859
  disabled,
2735
2860
  onClick: (event) => {
2736
2861
  event.stopPropagation();
@@ -2802,36 +2927,31 @@
2802
2927
  return { paddingLeft: `${14 + depth * 14}px` };
2803
2928
  }
2804
2929
  /**
2805
- * One change row: status letter, path, and its quick actions.
2806
- * @param {object} props - the change, its group, selection state, handlers, and copy.
2930
+ * One change row: icon, path, quick actions, and its tracking status.
2931
+ * @param {object} props - the change, its group, selection state, handlers, copy,
2932
+ * and the tree depth with whether the directory suffix is shown.
2807
2933
  * @returns {object} the row.
2808
2934
  */
2809
- function ChangeRow({ file, group, selected, disabled, t, onActivate, onToggleSelected, onContextMenu, onQuickStage, onQuickUnstage, onQuickDiscard }) {
2935
+ function ChangeRow({ file, group, selected, disabled, t, depth = 0, showDir = true, onActivate, onContextMenu, onQuickStage, onQuickUnstage, onQuickDiscard }) {
2810
2936
  const { dir, base } = splitPath(file.path);
2811
2937
  const canStage = group !== "staged";
2938
+ const FileGlyph = isDirectoryEntry(file.path) ? FolderIcon : FileIcon;
2812
2939
  return h("div", {
2813
2940
  className: `dgscm-row dgscm-row--file${selected ? " dgscm-row--selected" : ""}`,
2814
2941
  role: "button",
2815
2942
  tabIndex: 0,
2816
2943
  title: t("action.openDiff", { path: file.path }),
2944
+ style: indent(depth),
2817
2945
  onClick: onActivate,
2818
2946
  onKeyDown: activateOnKey(onActivate),
2819
2947
  onContextMenu
2820
- }, h("span", {
2821
- className: "dgscm-row-check",
2822
- onClick: (event) => {
2823
- event.stopPropagation();
2824
- }
2825
- }, h("input", {
2826
- type: "checkbox",
2827
- checked: selected,
2828
- disabled,
2829
- "aria-label": t("action.stageSelected"),
2830
- onChange: () => onToggleSelected()
2831
- })), h("span", { className: `dgscm-row-mark dgscm-status--${STATUS_CLASS[file.status] ?? "modified"}` }, statusLetter(file)), h(FileIcon, {
2948
+ }, showDir === false ? h("span", {
2949
+ className: "dgscm-row-treepad",
2950
+ "aria-hidden": true
2951
+ }) : null, h(FileGlyph, {
2832
2952
  size: 13,
2833
2953
  className: "dgscm-row-glyph"
2834
- }), h("span", { className: "dgscm-row-name" }, base), dir === "" ? null : h("span", { className: "dgscm-row-dir" }, dir), h("div", {
2954
+ }), h("span", { className: "dgscm-row-name" }, base), dir === "" || showDir === false ? null : h("span", { className: "dgscm-row-dir" }, dir), h("span", { className: "dgscm-row-end" }, h("div", {
2835
2955
  className: "dgscm-row-actions",
2836
2956
  onClick: (event) => {
2837
2957
  event.stopPropagation();
@@ -2851,7 +2971,41 @@
2851
2971
  label: t("action.discard", { path: file.path }),
2852
2972
  disabled,
2853
2973
  onClick: onQuickDiscard
2854
- }, h(DiscardIcon, { size: 13 }))));
2974
+ }, h(DiscardIcon, { size: 13 }))), h("span", { className: `dgscm-row-mark dgscm-status--${STATUS_CLASS[file.status] ?? "modified"}` }, statusLetter(file))));
2975
+ }
2976
+ /**
2977
+ * One directory row of the change tree: disclosure, folder glyph, name, hover
2978
+ * actions for the files underneath, and their count. A compacted chain shows
2979
+ * as `parent / child / grandchild`.
2980
+ * @param {object} props - directory identity, depth, disclosure state, file count,
2981
+ * hover actions, handlers, and copy.
2982
+ * @returns {object} the row.
2983
+ */
2984
+ function ChangeDirRow({ name, path, depth, open, count, t, actions, onToggle }) {
2985
+ return h("div", {
2986
+ className: "dgscm-row dgscm-row--dir",
2987
+ role: "button",
2988
+ tabIndex: 0,
2989
+ "aria-expanded": open,
2990
+ title: path,
2991
+ style: indent(depth),
2992
+ onClick: onToggle,
2993
+ onKeyDown: activateOnKey(onToggle)
2994
+ }, h("span", { className: "dgscm-row-chevron" }, h(ChevronIcon, { open })), h(FolderIcon, {
2995
+ size: 13,
2996
+ className: "dgscm-row-glyph dgscm-row-glyph--folder"
2997
+ }), h("span", { className: "dgscm-row-name" }, name), h("span", { className: "dgscm-row-end" }, h("div", {
2998
+ className: "dgscm-row-actions",
2999
+ onClick: (event) => {
3000
+ event.stopPropagation();
3001
+ },
3002
+ onKeyDown: (event) => {
3003
+ event.stopPropagation();
3004
+ }
3005
+ }, actions), h("span", {
3006
+ className: "dgscm-row-note",
3007
+ title: t("tree.fileCount", { n: count })
3008
+ }, String(count))));
2855
3009
  }
2856
3010
  /**
2857
3011
  * One branch row: disclosure, name, tracking state, quick checkout, and its
@@ -2926,7 +3080,7 @@
2926
3080
  function CommitFileRow({ file, depth, t, onOpen, onContextMenu }) {
2927
3081
  const { dir, base } = splitPath(file.path);
2928
3082
  return h("div", {
2929
- className: "dgscm-row dgscm-row--file",
3083
+ className: "dgscm-row dgscm-row--file dgscm-row--commit-file",
2930
3084
  style: indent(depth),
2931
3085
  role: "button",
2932
3086
  tabIndex: 0,
@@ -2934,10 +3088,10 @@
2934
3088
  onClick: onOpen,
2935
3089
  onKeyDown: activateOnKey(onOpen),
2936
3090
  onContextMenu
2937
- }, h("span", { className: `dgscm-row-mark dgscm-status--${STATUS_CLASS[file.status] ?? "modified"}` }, statusLetter(file)), h(FileIcon, {
3091
+ }, h(FileIcon, {
2938
3092
  size: 13,
2939
3093
  className: "dgscm-row-glyph"
2940
- }), h("span", { className: "dgscm-row-name" }, base), dir === "" ? null : h("span", { className: "dgscm-row-dir" }, dir));
3094
+ }), h("span", { className: "dgscm-row-name" }, base), dir === "" ? null : h("span", { className: "dgscm-row-dir" }, dir), h("span", { className: "dgscm-row-end" }, h("span", { className: `dgscm-row-mark dgscm-status--${STATUS_CLASS[file.status] ?? "modified"}` }, statusLetter(file))));
2941
3095
  }
2942
3096
  /**
2943
3097
  * One remote row: disclosure, name, and its URL.
@@ -3155,10 +3309,10 @@
3155
3309
  className: "dgscm-review-row",
3156
3310
  title: t("action.openDiff", { path: file.path }),
3157
3311
  onClick: () => onOpenFile(file)
3158
- }, h("span", { className: `dgscm-row-mark dgscm-status--${STATUS_CLASS[file.status] ?? "modified"}` }, statusLetter(file)), h(FileIcon, {
3312
+ }, h(FileIcon, {
3159
3313
  size: 13,
3160
3314
  className: "dgscm-row-glyph"
3161
- }), h("span", { className: "dgscm-review-path" }, base), dir === "" ? null : h("span", { className: "dgscm-review-dir" }, dir), h("span", { className: "dgscm-review-counts" }, file.additions === null || file.additions === void 0 ? null : h("span", { className: "dgscm-review-add" }, `+${file.additions}`), file.deletions === null || file.deletions === void 0 ? null : h("span", { className: "dgscm-review-del" }, `−${file.deletions}`)));
3315
+ }), h("span", { className: "dgscm-review-path" }, base), dir === "" ? null : h("span", { className: "dgscm-review-dir" }, dir), h("span", { className: "dgscm-review-end" }, h("span", { className: `dgscm-row-mark dgscm-status--${STATUS_CLASS[file.status] ?? "modified"}` }, statusLetter(file)), h("span", { className: "dgscm-review-counts" }, file.additions === null || file.additions === void 0 ? null : h("span", { className: "dgscm-review-add" }, `+${file.additions}`), file.deletions === null || file.deletions === void 0 ? null : h("span", { className: "dgscm-review-del" }, `−${file.deletions}`))));
3162
3316
  }) : null));
3163
3317
  }
3164
3318
  /**
@@ -3345,8 +3499,9 @@
3345
3499
  * @param {object} props - the opened view, display mode, dock controls, and copy.
3346
3500
  * @returns {object} the comparison pane.
3347
3501
  */
3348
- function DiffPane({ view, mode, onMode, onClose, onNative, onMaximize, maximized, layout, onLayout, onBack, backLabel, searchSignal = 0, t }) {
3502
+ function DiffPane({ view, mode, onMode, onClose, onMaximize, maximized, layout, onLayout, onBack, backLabel, searchSignal = 0, t }) {
3349
3503
  const [expanded, setExpanded] = useState(() => /* @__PURE__ */ new Set());
3504
+ const [wrap, setWrap] = useState(readDiffWrap);
3350
3505
  const [searchOpen, setSearchOpen] = useState(false);
3351
3506
  const [query, setQuery] = useState("");
3352
3507
  const [activeMatch, setActiveMatch] = useState(0);
@@ -3516,6 +3671,14 @@
3516
3671
  key,
3517
3672
  className: "dgscm-diffpair"
3518
3673
  }, diffHalf(pair.left, "left", `${key}-l`), diffHalf(pair.right, "right", `${key}-r`));
3674
+ /** Flip the pane's word-wrap preference and persist it. */
3675
+ const toggleWrap = () => {
3676
+ setWrap((current) => {
3677
+ const next = !current;
3678
+ storeDiffWrap(next);
3679
+ return next;
3680
+ });
3681
+ };
3519
3682
  const matchLabel = query.trim().length === 0 ? "" : matches.length === 0 ? t("diff.noMatches") : t("diff.matchPosition", {
3520
3683
  index: activeMatch + 1,
3521
3684
  total: matches.length
@@ -3535,10 +3698,11 @@
3535
3698
  }, h(SearchIcon, { size: 14 })), h(IconButton, {
3536
3699
  label: mode === "split" ? t("diff.modeUnified") : t("diff.modeSplit"),
3537
3700
  onClick: () => onMode(mode === "split" ? "unified" : "split")
3538
- }, mode === "split" ? h(RowsIcon, { size: 14 }) : h(ColumnsIcon, { size: 14 })), onNative === void 0 ? null : h(IconButton, {
3539
- label: t("action.openNative"),
3540
- onClick: onNative
3541
- }, h(ExternalIcon, { size: 14 })), h(IconButton, {
3701
+ }, mode === "split" ? h(RowsIcon, { size: 14 }) : h(ColumnsIcon, { size: 14 })), h(IconButton, {
3702
+ label: wrap ? t("diff.wrapOff") : t("diff.wrapOn"),
3703
+ pressed: wrap,
3704
+ onClick: toggleWrap
3705
+ }, h(WrapIcon, { size: 14 })), h(IconButton, {
3542
3706
  label: layout === "right" ? t("action.dockBottom") : t("action.dockRight"),
3543
3707
  onClick: () => onLayout(layout === "right" ? "bottom" : "right")
3544
3708
  }, layout === "right" ? h(DockBottomIcon, { size: 14 }) : h(DockRightIcon, { size: 14 })), h(IconButton, {
@@ -3580,7 +3744,7 @@
3580
3744
  onClick: closeSearch
3581
3745
  }, h(CloseIcon, { size: 12 }))) : null, h("div", {
3582
3746
  ref: bodyRef,
3583
- className: `dgscm-diff-body${mode === "split" ? " dgscm-diff-body--split" : ""}`
3747
+ className: `dgscm-diff-body${mode === "split" ? " dgscm-diff-body--split" : ""}${wrap ? "" : " dgscm-diff-body--nowrap"}`
3584
3748
  }, view.loading === true ? h("div", { className: "dgscm-diff-note" }, t("diff.loading")) : null, view.error !== null && view.error !== void 0 ? h("div", {
3585
3749
  className: "dgscm-diff-note",
3586
3750
  style: { color: "var(--dsw-alias-state-error-primary)" }
@@ -3591,7 +3755,8 @@
3591
3755
  * @param {object} props - the tab's `sessionId` and localized `t`.
3592
3756
  * @returns {object} the panel.
3593
3757
  */
3594
- function ScmPanel({ sessionId, t, openNativeChanges, openFile, localeId }) {
3758
+ function ScmPanel({ sessionId, t, openFile, localeId, useTabInfo }) {
3759
+ const tabActions = typeof useTabInfo === "function" ? useTabInfo().tab.actions : void 0;
3595
3760
  const [phase, setPhase] = useState("loading");
3596
3761
  const [summary, setSummary] = useState(null);
3597
3762
  const [failure, setFailure] = useState(null);
@@ -3613,6 +3778,8 @@
3613
3778
  stashes: false,
3614
3779
  tags: false
3615
3780
  });
3781
+ const [changeView, setChangeView] = useState(readChangeView);
3782
+ const [collapsedDirs, setCollapsedDirs] = useState({});
3616
3783
  const [nodes, setNodes] = useState({});
3617
3784
  const [selection, setSelection] = useState({
3618
3785
  group: null,
@@ -3719,6 +3886,7 @@
3719
3886
  setMessage("");
3720
3887
  setAmend(false);
3721
3888
  setNodes({});
3889
+ setCollapsedDirs({});
3722
3890
  setSelection({
3723
3891
  group: null,
3724
3892
  paths: [],
@@ -3913,6 +4081,21 @@
3913
4081
  [key]: !current[key]
3914
4082
  }));
3915
4083
  }, []);
4084
+ /** Switch the change sections between the flat list and the directory tree. */
4085
+ const toggleChangeView = useCallback(() => {
4086
+ setChangeView((current) => {
4087
+ const next = current === "list" ? "tree" : "list";
4088
+ storeChangeView(next);
4089
+ return next;
4090
+ });
4091
+ }, []);
4092
+ /** Collapse or expand one directory of the change tree. */
4093
+ const toggleChangeDir = useCallback((key) => {
4094
+ setCollapsedDirs((current) => ({
4095
+ ...current,
4096
+ [key]: current[key] !== true
4097
+ }));
4098
+ }, []);
3916
4099
  /**
3917
4100
  * Run one mutating Git operation, then re-read the snapshot.
3918
4101
  * @param {string} operation - the Host operation name.
@@ -3971,33 +4154,18 @@
3971
4154
  onConfirm
3972
4155
  });
3973
4156
  }, []);
3974
- /**
3975
- * Hand one working-tree file to the app's own changes view (the rich
3976
- * side-by-side diff), scrolled to that file. A profile without that view
3977
- * answers false, which this reports instead of failing silently.
3978
- * @param {string} path - repository-relative path.
3979
- */
3980
- const openNative = useCallback((path) => {
3981
- if (typeof openNativeChanges !== "function") {
3982
- setNotice({
3983
- tone: "error",
3984
- title: t("toast.nativeUnavailable")
3985
- });
3986
- return;
3987
- }
3988
- if (openNativeChanges(path) !== true) setNotice({
3989
- tone: "error",
3990
- title: t("toast.nativeUnavailable")
3991
- });
3992
- }, [openNativeChanges, t]);
3993
4157
  /** Open one working-tree file in the app's own code view (line numbers + highlighting). */
3994
4158
  const openFileAt = useCallback((path) => {
3995
- if (typeof openFile === "function" && openFile(path) === true) return;
4159
+ if (typeof openFile === "function" && openFile(path, tabActions) === true) return;
3996
4160
  setNotice({
3997
4161
  tone: "error",
3998
4162
  title: t("toast.fileUnavailable")
3999
4163
  });
4000
- }, [openFile, t]);
4164
+ }, [
4165
+ openFile,
4166
+ t,
4167
+ tabActions
4168
+ ]);
4001
4169
  /** Copy text and report the outcome. */
4002
4170
  const copy = useCallback(async (text) => {
4003
4171
  const ok = await copyText(text);
@@ -4769,11 +4937,14 @@
4769
4937
  const total = rootRef.current?.clientHeight ?? 600;
4770
4938
  return Math.max(DIFF_HEIGHT_MIN, Math.min(value, Math.max(DIFF_HEIGHT_MIN, total - DIFF_HEIGHT_RESERVED)));
4771
4939
  };
4772
- /** Clamp a requested pane width so the list never drops below its 300px minimum. */
4940
+ /**
4941
+ * Clamp a requested pane width: the right dock keeps at least 280px, and
4942
+ * stops widening once the list would drop below its 300px reservation.
4943
+ */
4773
4944
  const clampPaneWidth = (value) => {
4774
4945
  const total = rootRef.current?.clientWidth ?? 800;
4775
- const available = Math.max(0, total - PREVIEW_WIDTH_RESERVED);
4776
- return Math.min(Math.max(value, Math.min(PREVIEW_WIDTH_MIN, available)), available);
4946
+ const maximum = Math.max(PREVIEW_WIDTH_MIN, total - PREVIEW_WIDTH_RESERVED);
4947
+ return Math.min(Math.max(value, PREVIEW_WIDTH_MIN), maximum);
4777
4948
  };
4778
4949
  const previewOpen = view !== null || review !== null || history !== null;
4779
4950
  const paneHeight = diffMaximized ? clampPaneHeight((rootRef.current?.clientHeight ?? 600) - DIFF_HEIGHT_RESERVED) : clampPaneHeight(diffHeight);
@@ -4978,56 +5149,157 @@
4978
5149
  run("stageAll", {}, t("toast.staged"));
4979
5150
  }
4980
5151
  }, h(PlusIcon, { size: 13 })));
4981
- /** Rows of one change section. */
4982
- const changeRows = (section, list) => {
4983
- const selected = selectedSet(section);
4984
- return list.map((file) => {
4985
- const kind = kindOf(section, file);
4986
- return h(ChangeRow, {
5152
+ /**
5153
+ * One change row; `list` is the section order selection ranges use.
5154
+ * @param {string} section - `staged` or `changes`.
5155
+ * @param {object} file - the changed file.
5156
+ * @param {object[]} list - visible files of the section, in visual order.
5157
+ * @param {number} depth - tree indentation depth.
5158
+ * @param {boolean} showDir - whether the row appends the directory suffix.
5159
+ * @returns {object} the row element.
5160
+ */
5161
+ const fileChangeRow = (section, file, list, depth = 0, showDir = true) => {
5162
+ const kind = kindOf(section, file);
5163
+ return h(ChangeRow, {
5164
+ key: `${section}:${file.path}`,
5165
+ file,
5166
+ group: kind,
5167
+ selected: selectedSet(section).has(file.path),
5168
+ disabled: working,
5169
+ t,
5170
+ depth,
5171
+ showDir,
5172
+ onActivate: (event) => {
5173
+ if (event?.metaKey === true || event?.ctrlKey === true) {
5174
+ togglePath(section, file.path);
5175
+ return;
5176
+ }
5177
+ if (event?.shiftKey === true) {
5178
+ extendSelection(section, file.path, list);
5179
+ return;
5180
+ }
5181
+ select(section, [file.path], file.path);
5182
+ if (isDirectoryEntry(file.path)) return;
5183
+ openWorktreeDiff(file, kind);
5184
+ },
5185
+ onContextMenu: (event) => openMenu(event, fileMenu(file, kind, section, list)),
5186
+ onQuickStage: () => {
5187
+ run("stage", { paths: targetFiles(section, file.path, list).map((entry) => entry.path) }, t("toast.staged"));
5188
+ },
5189
+ onQuickUnstage: () => {
5190
+ run("unstage", { paths: targetFiles(section, file.path, list).map((entry) => entry.path) }, t("toast.unstaged"));
5191
+ },
5192
+ onQuickDiscard: () => discardFiles(targetFiles(section, file.path, list))
5193
+ });
5194
+ };
5195
+ /** Rows of one change section as a flat list. */
5196
+ const changeRows = (section, list) => list.map((file) => fileChangeRow(section, file, list));
5197
+ /**
5198
+ * Rows of one change section as a directory tree. Directories sort before
5199
+ * their files; the visible file order becomes the selection range.
5200
+ * @param {string} section - `staged` or `changes`.
5201
+ * @param {object[]} list - the section's changed files.
5202
+ * @returns {object[]} directory and file rows in display order.
5203
+ */
5204
+ const changeTreeRows = (section, list) => {
5205
+ const entries = [];
5206
+ /**
5207
+ * Merge a single-child directory chain into one row, the way the Explorer
5208
+ * compacts folders: a directory with no files and exactly one child joins
5209
+ * that child, repeating until a branch or a file stops the chain.
5210
+ * @param {object} dir - the first directory of the chain.
5211
+ * @returns {{ node: object, name: string }} the deepest directory and its
5212
+ * combined label.
5213
+ */
5214
+ const compactChain = (dir) => {
5215
+ let node = dir;
5216
+ const names = [dir.name];
5217
+ while (node.files.length === 0 && node.dirs.size === 1) {
5218
+ node = [...node.dirs.values()][0];
5219
+ names.push(node.name);
5220
+ }
5221
+ return {
5222
+ node,
5223
+ name: names.join(" / ")
5224
+ };
5225
+ };
5226
+ const walk = (node, depth) => {
5227
+ const dirs = [...node.dirs.values()].sort((left, right) => left.name.localeCompare(right.name));
5228
+ for (const dir of dirs) {
5229
+ const chain = compactChain(dir);
5230
+ const key = `${section}:${chain.node.path}`;
5231
+ const open = collapsedDirs[key] !== true;
5232
+ entries.push({
5233
+ kind: "dir",
5234
+ key: `dir:${key}`,
5235
+ dir: chain.node,
5236
+ name: chain.name,
5237
+ depth,
5238
+ open,
5239
+ count: countTreeFiles(chain.node),
5240
+ files: collectTreeFiles(chain.node)
5241
+ });
5242
+ if (open) walk(chain.node, depth + 1);
5243
+ }
5244
+ const files = node.files.slice().sort((left, right) => left.path.localeCompare(right.path));
5245
+ for (const file of files) entries.push({
5246
+ kind: "file",
4987
5247
  key: `${section}:${file.path}`,
4988
5248
  file,
4989
- group: kind,
4990
- selected: selected.has(file.path),
5249
+ depth
5250
+ });
5251
+ };
5252
+ walk(buildChangeTree(list), 0);
5253
+ const ordered = entries.filter((entry) => entry.kind === "file").map((entry) => entry.file);
5254
+ return entries.map((entry) => {
5255
+ if (entry.kind === "file") return fileChangeRow(section, entry.file, ordered, entry.depth, false);
5256
+ const paths = entry.files.map((file) => file.path);
5257
+ const actions = section === "staged" ? [h(IconButton, {
5258
+ key: "unstage",
5259
+ label: t("action.unstage", { path: entry.dir.path }),
5260
+ disabled: working,
5261
+ onClick: () => {
5262
+ run("unstage", { paths }, t("toast.unstaged"));
5263
+ }
5264
+ }, h(MinusIcon, { size: 13 }))] : [h(IconButton, {
5265
+ key: "stage",
5266
+ label: t("action.stage", { path: entry.dir.path }),
4991
5267
  disabled: working,
5268
+ onClick: () => {
5269
+ run("stage", { paths }, t("toast.staged"));
5270
+ }
5271
+ }, h(PlusIcon, { size: 13 })), h(IconButton, {
5272
+ key: "discard",
5273
+ label: t("action.discard", { path: entry.dir.path }),
5274
+ disabled: working,
5275
+ onClick: () => discardFiles(entry.files)
5276
+ }, h(DiscardIcon, { size: 13 }))];
5277
+ return h(ChangeDirRow, {
5278
+ key: entry.key,
5279
+ name: entry.name,
5280
+ path: entry.dir.path,
5281
+ depth: entry.depth,
5282
+ open: entry.open,
5283
+ count: entry.count,
4992
5284
  t,
4993
- onActivate: (event) => {
4994
- if (event?.metaKey === true || event?.ctrlKey === true) {
4995
- togglePath(section, file.path);
4996
- return;
4997
- }
4998
- if (event?.shiftKey === true) {
4999
- extendSelection(section, file.path, list);
5000
- return;
5001
- }
5002
- select(section, [file.path], file.path);
5003
- openWorktreeDiff(file, kind);
5004
- },
5005
- onToggleSelected: () => togglePath(section, file.path),
5006
- onContextMenu: (event) => openMenu(event, fileMenu(file, kind, section, list)),
5007
- onQuickStage: () => {
5008
- run("stage", { paths: targetFiles(section, file.path, list).map((entry) => entry.path) }, t("toast.staged"));
5009
- },
5010
- onQuickUnstage: () => {
5011
- run("unstage", { paths: targetFiles(section, file.path, list).map((entry) => entry.path) }, t("toast.unstaged"));
5012
- },
5013
- onQuickDiscard: () => discardFiles(targetFiles(section, file.path, list))
5285
+ actions,
5286
+ onToggle: () => toggleChangeDir(`${section}:${entry.dir.path}`)
5014
5287
  });
5015
5288
  });
5016
5289
  };
5290
+ /** Rows of one change section in the selected view. */
5291
+ const changeSectionRows = (section, list) => changeView === "tree" ? changeTreeRows(section, list) : changeRows(section, list);
5017
5292
  /** Context menu of one change row. */
5018
5293
  const fileMenu = (file, kind, section, list) => {
5019
5294
  const files = targetFiles(section, file.path, list);
5020
5295
  const paths = files.map((entry) => entry.path);
5021
5296
  const untrackedOnly = files.length > 0 && files.every((entry) => entry.status === "untracked");
5297
+ const directoryRow = isDirectoryEntry(file.path);
5022
5298
  return [
5023
5299
  {
5024
5300
  label: t("menu.showDiff"),
5025
- icon: h(ExternalIcon, { size: 14 }),
5026
- run: () => openNative(file.path)
5027
- },
5028
- {
5029
- label: t("menu.previewInPanel"),
5030
5301
  icon: h(RowsIcon, { size: 14 }),
5302
+ disabled: directoryRow,
5031
5303
  run: () => {
5032
5304
  openWorktreeDiff(file, kind);
5033
5305
  }
@@ -5035,12 +5307,13 @@
5035
5307
  {
5036
5308
  label: t("menu.openFile"),
5037
5309
  icon: h(ExternalIcon, { size: 14 }),
5038
- disabled: file.status === "deleted",
5310
+ disabled: directoryRow || file.status === "deleted",
5039
5311
  run: () => openFileAt(file.path)
5040
5312
  },
5041
5313
  {
5042
5314
  label: t("menu.fileHistory"),
5043
5315
  icon: h(HistoryIcon, { size: 14 }),
5316
+ disabled: directoryRow,
5044
5317
  run: () => {
5045
5318
  openFileHistory(file.path);
5046
5319
  }
@@ -5537,6 +5810,9 @@
5537
5810
  else run("push", {}, t("toast.pushed"));
5538
5811
  }
5539
5812
  }, h(unpublished ? CloudUploadIcon : PushIcon, { size: 15 })), h(IconButton, {
5813
+ label: changeView === "tree" ? t("action.viewList") : t("action.viewTree"),
5814
+ onClick: toggleChangeView
5815
+ }, h(changeView === "tree" ? RowsIcon : TreeIcon, { size: 15 })), h(IconButton, {
5540
5816
  label: t("action.moreChanges"),
5541
5817
  disabled: working,
5542
5818
  onClick: (event) => openMenu(event, changesMoreMenuItems())
@@ -5680,7 +5956,7 @@
5680
5956
  open: sections.staged,
5681
5957
  onToggle: () => toggleSection("staged"),
5682
5958
  actions: stagedActions()
5683
- }, changeRows("staged", staged)), h(Section, {
5959
+ }, changeSectionRows("staged", staged)), h(Section, {
5684
5960
  id: "changes",
5685
5961
  title: t("section.changes"),
5686
5962
  count: workingChanges.length,
@@ -5688,7 +5964,7 @@
5688
5964
  open: sections.changes,
5689
5965
  onToggle: () => toggleSection("changes"),
5690
5966
  actions: changesActions()
5691
- }, workingChanges.length === 0 ? h("div", { className: "dgscm-section-note" }, t("empty.changes")) : changeRows("changes", workingChanges)), h(Group, {
5967
+ }, workingChanges.length === 0 ? h("div", { className: "dgscm-section-note" }, t("empty.changes")) : changeSectionRows("changes", workingChanges)), h(Group, {
5692
5968
  id: "repositories",
5693
5969
  title: t("group.repositories"),
5694
5970
  open: sections.groupRepositories,
@@ -5840,7 +6116,6 @@
5840
6116
  mode: diffMode,
5841
6117
  onMode: setDiffMode,
5842
6118
  onClose: closePreview,
5843
- onNative: view.source.kind === "worktree" || view.source.kind === "staged" || view.source.kind === "untracked" ? () => openNative(view.path) : void 0,
5844
6119
  onMaximize: () => setDiffMaximized((current) => !current),
5845
6120
  maximized: diffMaximized,
5846
6121
  searchSignal,
@@ -5958,6 +6233,80 @@
5958
6233
  */
5959
6234
  function apply(ctx) {
5960
6235
  const t = ctx.locale.bind(NS);
6236
+ /**
6237
+ * Preview tabs this panel opened, by Session id, so later opens update the
6238
+ * same tab instead of stacking one tab per file.
6239
+ * @type {Map<string, string>}
6240
+ */
6241
+ const previewTabs = /* @__PURE__ */ new Map();
6242
+ /**
6243
+ * Opens whose preview tab the right Sidebar has not published yet.
6244
+ * @type {Map<string, { address: string, before: Set<string> }>}
6245
+ */
6246
+ const pendingPreviewOpens = /* @__PURE__ */ new Map();
6247
+ /**
6248
+ * Record the tab the right Sidebar published for one Session and file address.
6249
+ * @param {string} sessionId - the Session that owns the file.
6250
+ * @param {string} address - the resource address that was opened.
6251
+ * @param {Set<string>} before - tab ids present before the open.
6252
+ * @returns {boolean} whether a matching tab was found.
6253
+ */
6254
+ const rememberPreviewTab = (sessionId, address, before) => {
6255
+ const snapshot = ctx.sidebarRight?.openTabs?.getSnapshot?.();
6256
+ if (!Array.isArray(snapshot)) return false;
6257
+ const matches = snapshot.filter((tab) => tab.sessionId === sessionId && tab.contentId === address);
6258
+ const chosen = matches.find((tab) => !before.has(tab.tabId)) ?? matches[0];
6259
+ if (chosen === void 0) return false;
6260
+ previewTabs.set(sessionId, chosen.tabId);
6261
+ return true;
6262
+ };
6263
+ ctx.effect(() => {
6264
+ const source = ctx.sidebarRight?.openTabs;
6265
+ if (typeof source?.subscribe !== "function" || typeof source?.getSnapshot !== "function") return void 0;
6266
+ const sync = () => {
6267
+ for (const [sessionId, pending] of pendingPreviewOpens) if (rememberPreviewTab(sessionId, pending.address, pending.before)) pendingPreviewOpens.delete(sessionId);
6268
+ };
6269
+ const unsubscribe = source.subscribe(sync);
6270
+ sync();
6271
+ return unsubscribe;
6272
+ }, "dsh-git-scm: file preview tracking");
6273
+ /**
6274
+ * Open one Session-relative file in the app's code view. The first open
6275
+ * splits the panel's docked pane (change list left, preview right); later
6276
+ * opens replace the preview tab this panel opened.
6277
+ * @param {string} sessionId - the Session that owns the file.
6278
+ * @param {string} path - repository-relative file path.
6279
+ * @param {object} [actions] - the tab's own navigation actions, when supplied.
6280
+ * @returns {boolean} whether an installed view claimed the file address.
6281
+ */
6282
+ const openFilePreview = (sessionId, path, actions) => {
6283
+ const address = fileAddressOf(sessionId, path);
6284
+ const snapshot = ctx.sidebarRight?.openTabs?.getSnapshot?.();
6285
+ const before = new Set(Array.isArray(snapshot) ? snapshot.filter((tab) => tab.sessionId === sessionId).map((tab) => tab.tabId) : []);
6286
+ const tracked = previewTabs.get(sessionId);
6287
+ const trackedAlive = tracked !== void 0 && before.has(tracked);
6288
+ try {
6289
+ if (trackedAlive) ctx.sidebarRight.openResource(address, {
6290
+ replaceTab: tracked,
6291
+ revealIfOpened: true
6292
+ });
6293
+ else if (typeof actions?.openResource === "function") actions.openResource(address, {
6294
+ preferNewPane: true,
6295
+ revealIfOpened: true
6296
+ });
6297
+ else ctx.sidebarRight.openResource(address, {
6298
+ preferNewPane: true,
6299
+ revealIfOpened: true
6300
+ });
6301
+ } catch {
6302
+ return false;
6303
+ }
6304
+ if (!rememberPreviewTab(sessionId, address, before)) pendingPreviewOpens.set(sessionId, {
6305
+ address,
6306
+ before
6307
+ });
6308
+ return true;
6309
+ };
5961
6310
  ctx.effect(() => ctx.locale.register(NS, "en", EN), "dsh-git-scm: copy en");
5962
6311
  ctx.effect(() => ctx.locale.register(NS, "zh", ZH), "dsh-git-scm: copy zh");
5963
6312
  ctx.effect(() => {
@@ -5986,31 +6335,13 @@
5986
6335
  inject: (sessionId) => ({
5987
6336
  localeId: () => ctx.locale.getLocale().active,
5988
6337
  /**
5989
- * Open the app's own local-changes view scrolled to one file.
5990
- * @param {string} path - repository-relative path.
5991
- * @returns {boolean} whether the address was claimed by an installed view.
5992
- */
5993
- openNativeChanges: (path) => {
5994
- try {
5995
- ctx.sidebarRight.openResource(nativeChangesAddress(sessionId), { params: { path } });
5996
- return true;
5997
- } catch {
5998
- return false;
5999
- }
6000
- },
6001
- /**
6002
- * Open one Session-relative file in the app's own code view.
6338
+ * Open one Session-relative file in the app's own code view, reusing the
6339
+ * preview tab this panel opened.
6003
6340
  * @param {string} path - repository-relative file path.
6341
+ * @param {object} [actions] - the enclosing tab's navigation actions.
6004
6342
  * @returns {boolean} whether the address was claimed by an installed view.
6005
6343
  */
6006
- openFile: (path) => {
6007
- try {
6008
- ctx.sidebarRight.openResource(fileAddressOf(sessionId, path));
6009
- return true;
6010
- } catch {
6011
- return false;
6012
- }
6013
- }
6344
+ openFile: (path, actions) => openFilePreview(sessionId, path, actions)
6014
6345
  })
6015
6346
  }, ScmPanel)), "dsh-git-scm: tab body");
6016
6347
  ctx.effect(() => ctx.slots.inject("sidebar.right.pane.tab.title", () => ctx.slots.register({