dsh-gufa-code 1.3.201 → 1.3.210

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.
@@ -139,20 +139,47 @@ G.Explorer = function Explorer(props) {
139
139
  setMenuError('')
140
140
  }
141
141
 
142
+ /* 内置剪贴板(IDE 内复制/剪切)优先;没有时读系统剪贴板里的文件/文件夹路径(Finder/资源管理器复制)。 */
142
143
  const pasteInto = async (dir) => {
143
- if (clipboard === null || clipboard.entries.length === 0) return
144
144
  const target = typeof dir === 'string' ? dir : ''
145
+ if (clipboard !== null && clipboard.entries.length > 0) {
146
+ try {
147
+ await G.api('fs.copy', { root, from: clipboard.entries, to: target })
148
+ setMenuError('')
149
+ await loadDir(target)
150
+ await loadDir('')
151
+ props.onChanged?.()
152
+ } catch (error) {
153
+ setMenuError(G.errorText(error))
154
+ }
155
+ return
156
+ }
145
157
  try {
146
- await G.api('fs.copy', { root, from: clipboard.entries, to: target })
147
- setMenuError('')
148
- await loadDir(target)
149
- await loadDir('')
150
- props.onChanged?.()
158
+ const result = await G.api('fs.pasteClipboard', { root, to: target })
159
+ const copied = Array.isArray(result?.copied) ? result.copied : []
160
+ const failed = Array.isArray(result?.failed) ? result.failed : []
161
+ if (copied.length > 0) {
162
+ setMenuError('')
163
+ await loadDir(target)
164
+ await loadDir('')
165
+ props.onChanged?.()
166
+ showNotice(t('explorer.pasteDone').replace('{count}', String(copied.length)))
167
+ } else {
168
+ setMenuError(String(failed[0]?.error ?? t('explorer.pasteEmpty')))
169
+ }
151
170
  } catch (error) {
152
- setMenuError(G.errorText(error))
171
+ if (error?.code === 'clipboard-empty') showNotice(t('explorer.pasteEmpty'))
172
+ else setMenuError(G.errorText(error))
153
173
  }
154
174
  }
155
175
 
176
+ /* 切到 Finder/资源管理器复制文件时 IDE 会失焦:清掉内置剪贴板,避免 Cmd+V 粘到旧的 IDE 内复制内容 */
177
+ useEffect(() => {
178
+ const clear = () => setClipboard(null)
179
+ window.addEventListener('blur', clear)
180
+ return () => window.removeEventListener('blur', clear)
181
+ }, [])
182
+
156
183
  const noticeRef = useRef(0)
157
184
  const showNotice = (text) => {
158
185
  setNotice(text)
@@ -367,6 +394,14 @@ G.Explorer = function Explorer(props) {
367
394
  event.preventDefault()
368
395
  event.stopPropagation()
369
396
  void uploadFiles(files, selectedDir())
397
+ return
398
+ }
399
+ /* 系统剪贴板里复制的是文件/文件夹时,Chromium 的 paste 事件拿不到 files,走 Host 读剪贴板路径 */
400
+ const types = event.clipboardData?.types
401
+ if (types !== undefined && types !== null && (Array.from(types).includes('Files') || Array.from(types).includes('text/uri-list'))) {
402
+ event.preventDefault()
403
+ event.stopPropagation()
404
+ void pasteInto(selectedDir())
370
405
  }
371
406
  },
372
407
  onDragOver: (event) => {
@@ -402,7 +437,7 @@ G.Explorer = function Explorer(props) {
402
437
  if (key === 'c') {
403
438
  event.preventDefault()
404
439
  copySelection(selectedPaths())
405
- } else if (key === 'v' && clipboard !== null) {
440
+ } else if (key === 'v') {
406
441
  event.preventDefault()
407
442
  void pasteInto(selectedDir())
408
443
  } else if (key === 'backspace' || event.key === 'Delete') {
@@ -463,9 +498,7 @@ G.Explorer = function Explorer(props) {
463
498
  },
464
499
  h(G.MenuItem, { icon: 'plus', label: t('explorer.newFile'), onClick: closeBlank(() => props.onNewFile?.('')) }),
465
500
  h(G.MenuItem, { icon: 'folder', label: t('explorer.newFolder'), onClick: closeBlank(() => props.onNewFolder?.('')) }),
466
- clipboard !== null
467
- ? h(G.MenuItem, { icon: 'folder-open', label: t('explorer.paste'), onClick: closeBlank(() => void pasteInto('')) })
468
- : null,
501
+ h(G.MenuItem, { icon: 'folder-open', label: t('explorer.paste'), onClick: closeBlank(() => void pasteInto('')) }),
469
502
  h(G.MenuItem, { icon: 'refresh', label: t('explorer.refresh'), onClick: closeBlank(() => refreshAll()) }),
470
503
  h(G.MenuItem, { icon: 'files', label: '全部折叠', onClick: closeBlank(() => setExpanded({})) }),
471
504
  h(G.MenuItem, { icon: 'folder-open', label: t('explorer.revealInFinder'), onClick: closeBlank(() => revealPath('')) }),
@@ -500,9 +533,7 @@ G.Explorer = function Explorer(props) {
500
533
  })
501
534
  : null,
502
535
  h(G.MenuItem, { icon: 'files', label: t('explorer.copy'), onClick: closeAnd(() => copySelection(entries.map((item) => item.path))) }),
503
- clipboard !== null
504
- ? h(G.MenuItem, { icon: 'folder-open', label: t('explorer.paste'), onClick: closeAnd(() => void pasteInto(targetDir)) })
505
- : null,
536
+ h(G.MenuItem, { icon: 'folder-open', label: t('explorer.paste'), onClick: closeAnd(() => void pasteInto(targetDir)) }),
506
537
  single
507
538
  ? h(G.MenuItem, { icon: 'folder-open', label: t('explorer.revealInFinder'), onClick: closeAnd(() => revealPath(menu.path)) })
508
539
  : null,
@@ -1084,9 +1115,12 @@ G.SearchPanel = function SearchPanel(props) {
1084
1115
  }
1085
1116
 
1086
1117
  /* ── 源代码管理(Git) ─────────────────────────────────────────────────── */
1087
- G.GitPanel = function GitPanel(props) {
1118
+ G.GitRepoDetail = function GitRepoDetail(props) {
1088
1119
  const t = G.useT()
1089
1120
  const root = props.root
1121
+ const repo = props.repo !== null && props.repo !== undefined ? props.repo : null
1122
+ const repoParam = repo !== null && typeof repo.path === 'string' && repo.path !== '' ? repo.path : undefined
1123
+ const changeWithRepo = (change) => (repoParam !== undefined && change !== null && typeof change === 'object' ? { ...change, repo: repoParam, repoRel: repo.rel ?? '' } : change)
1090
1124
  const [status, setStatus] = useState(null)
1091
1125
  const [error, setError] = useState('')
1092
1126
  const [pending, setPending] = useState(false)
@@ -1109,10 +1143,10 @@ G.GitPanel = function GitPanel(props) {
1109
1143
  }
1110
1144
  setError('')
1111
1145
  try {
1112
- const value = await G.api('git.status', { root: target })
1146
+ const value = await G.api('git.status', { root: target, repo: repoParam })
1113
1147
  setStatus(value)
1114
1148
  try {
1115
- onStatusRef.current?.(value)
1149
+ onStatusRef.current?.(repoParam !== undefined ? { ...value, repo: repoParam } : value)
1116
1150
  } catch {
1117
1151
  /* 通知失败不影响面板 */
1118
1152
  }
@@ -1121,13 +1155,13 @@ G.GitPanel = function GitPanel(props) {
1121
1155
  // 失败也不要停在「加载中」:给一个空状态让错误可见
1122
1156
  setStatus((current) => current ?? { isGit: true, branch: '', ahead: 0, behind: 0, changes: [] })
1123
1157
  }
1124
- }, [])
1158
+ }, [repoParam])
1125
1159
 
1126
1160
  /* 手动刷新:先 fetch 远端,再读 status(否则 behind 可能是 0) */
1127
1161
  const refreshRemote = useCallback(async () => {
1128
1162
  const target = rootRef.current
1129
1163
  if (target) {
1130
- try { await G.api('git.fetch', { root: target }) } catch { /* 离线等失败不打扰 */ }
1164
+ try { await G.api('git.fetch', { root: target, repo: repoParam }) } catch { /* 离线等失败不打扰 */ }
1131
1165
  }
1132
1166
  await refresh()
1133
1167
  }, [refresh])
@@ -1137,7 +1171,7 @@ G.GitPanel = function GitPanel(props) {
1137
1171
  setStatus(null)
1138
1172
  setMessage('')
1139
1173
  void refresh()
1140
- }, [root, refresh])
1174
+ }, [root, repoParam, refresh])
1141
1175
 
1142
1176
  /* 外部刷新令牌:保留当前内容,仅后台刷新 */
1143
1177
  useEffect(() => {
@@ -1161,18 +1195,18 @@ G.GitPanel = function GitPanel(props) {
1161
1195
 
1162
1196
  /* 推送 / 拉取:点 ↑/↓ 直接执行 */
1163
1197
  const push = () => void act(async () => {
1164
- await G.api('git.push', { root })
1198
+ await G.api('git.push', { root, repo: repoParam })
1165
1199
  })
1166
1200
  const pull = () => void act(async () => {
1167
- await G.api('git.pull', { root })
1201
+ await G.api('git.pull', { root, repo: repoParam })
1168
1202
  })
1169
1203
 
1170
1204
  /* 推送 / 拉取(新建分支还没有上游时也能直接发布:Host 会自动 -u <remote> <branch>) */
1171
1205
  const pushBranch = () => void act(async () => {
1172
- await G.api('git.push', { root })
1206
+ await G.api('git.push', { root, repo: repoParam })
1173
1207
  })
1174
1208
  const pullBranch = () => void act(async () => {
1175
- await G.api('git.pull', { root })
1209
+ await G.api('git.pull', { root, repo: repoParam })
1176
1210
  })
1177
1211
 
1178
1212
  /* 一键撤销所有未暂存改动:第一次点击进入「再点确认」,3 秒后自动取消 */
@@ -1184,7 +1218,7 @@ G.GitPanel = function GitPanel(props) {
1184
1218
  }
1185
1219
  setDiscardArmed(false)
1186
1220
  void act(async () => {
1187
- await G.api('git.discardAll', { root })
1221
+ await G.api('git.discardAll', { root, repo: repoParam })
1188
1222
  })
1189
1223
  }
1190
1224
 
@@ -1210,9 +1244,9 @@ G.GitPanel = function GitPanel(props) {
1210
1244
  /* 有已暂存改动时只提交暂存内容;一个都没暂存时才自动全部暂存再提交(快捷模式) */
1211
1245
  if (staged.length === 0) {
1212
1246
  const toStage = changes.filter((item) => item.staged !== true).map((item) => item.path)
1213
- if (toStage.length > 0) await G.api('git.stage', { root, paths: toStage })
1247
+ if (toStage.length > 0) await G.api('git.stage', { root, repo: repoParam, paths: toStage })
1214
1248
  }
1215
- await G.api('git.commit', { root, message: text })
1249
+ await G.api('git.commit', { root, repo: repoParam, message: text })
1216
1250
  setMessage('')
1217
1251
  })
1218
1252
  }
@@ -1266,20 +1300,20 @@ G.GitPanel = function GitPanel(props) {
1266
1300
  h(
1267
1301
  'div',
1268
1302
  { className: 'gufa-panel-head' },
1269
- h('span', { className: 'gufa-panel-head-title' }, t('activity.git')),
1303
+ h('span', { className: 'gufa-panel-head-title' }, repo !== null && repo.rel ? repo.rel : t('activity.git')),
1270
1304
  changes.length > 0 ? h('span', { className: 'gufa-badge' }, String(changes.length)) : null,
1271
1305
  unstaged.length > 0
1272
1306
  ? h(G.IconButton, {
1273
1307
  title: t('git.stageAll'),
1274
1308
  disabled: pending,
1275
- onClick: () => void act(async () => { await G.api('git.stage', { root, paths: unstaged.map((item) => item.path) }) }),
1309
+ onClick: () => void act(async () => { await G.api('git.stage', { root, repo: repoParam, paths: unstaged.map((item) => item.path) }) }),
1276
1310
  }, h(G.Icon, { name: 'plus', size: 13 }))
1277
1311
  : null,
1278
1312
  staged.length > 0
1279
1313
  ? h(G.IconButton, {
1280
1314
  title: t('git.unstageAll'),
1281
1315
  disabled: pending,
1282
- onClick: () => void act(async () => { await G.api('git.unstage', { root, paths: staged.map((item) => item.path) }) }),
1316
+ onClick: () => void act(async () => { await G.api('git.unstage', { root, repo: repoParam, paths: staged.map((item) => item.path) }) }),
1283
1317
  }, h(G.Icon, { name: 'minus', size: 13 }))
1284
1318
  : null,
1285
1319
  unstaged.length > 0
@@ -1320,7 +1354,7 @@ G.GitPanel = function GitPanel(props) {
1320
1354
  h('span', { className: 'gufa-git-sync-count' }, String(status?.behind ?? 0)),
1321
1355
  )
1322
1356
  : null,
1323
- h(G.IconButton, { title: t('graph.open'), onClick: () => props.onOpenGraph?.() }, h(G.Icon, { name: 'graph', size: 13 })),
1357
+ h(G.IconButton, { title: t('graph.open'), onClick: () => props.onOpenGraph?.(repo) }, h(G.Icon, { name: 'graph', size: 13 })),
1324
1358
  h(G.IconButton, { title: t('git.refresh'), disabled: pending, onClick: () => void refreshRemote() }, h(G.Icon, { name: 'refresh', size: 13 })),
1325
1359
  h(G.IconButton, {
1326
1360
  title: t('git.more'),
@@ -1350,7 +1384,7 @@ G.GitPanel = function GitPanel(props) {
1350
1384
  className: 'gufa-row',
1351
1385
  style: { color: 'var(--gufa-text-dim)', fontSize: 11.5, cursor: 'pointer' },
1352
1386
  title: t('git.branchSwitchHint'),
1353
- onClick: (event) => props.onOpenBranches?.(event),
1387
+ onClick: (event) => props.onOpenBranches?.(event, repo),
1354
1388
  },
1355
1389
  h(G.Icon, { name: 'branch', size: 13 }),
1356
1390
  h('span', { style: { color: 'var(--gufa-text)', fontWeight: 600 } }, status.branch || '—'),
@@ -1416,9 +1450,9 @@ G.GitPanel = function GitPanel(props) {
1416
1450
  change,
1417
1451
  pending,
1418
1452
  staged: true,
1419
- onOpen: () => props.onOpenDiff?.(change),
1453
+ onOpen: () => props.onOpenDiff?.(changeWithRepo(change)),
1420
1454
  onContextMenu: (event, rowChange) => setRowMenu({ ...clampMenuPosition(event.clientX, event.clientY, 200, 200), change: rowChange }),
1421
- onAction: () => void act(async () => G.api('git.unstage', { root, paths: [change.path] })),
1455
+ onAction: () => void act(async () => G.api('git.unstage', { root, repo: repoParam, paths: [change.path] })),
1422
1456
  actionLabel: t('git.unstage'),
1423
1457
  actionIcon: 'minus',
1424
1458
  }),
@@ -1429,11 +1463,15 @@ G.GitPanel = function GitPanel(props) {
1429
1463
  key: `u:${change.path}`,
1430
1464
  change,
1431
1465
  pending,
1432
- onOpen: () => props.onOpenDiff?.(change),
1466
+ onOpen: () => props.onOpenDiff?.(changeWithRepo(change)),
1433
1467
  onContextMenu: (event, rowChange) => setRowMenu({ ...clampMenuPosition(event.clientX, event.clientY, 200, 200), change: rowChange }),
1434
- onRevert: () => void act(async () => G.api('git.discard', { root, paths: [change.path] })),
1435
- revertLabel: t('git.discardFile'),
1436
- onAction: () => void act(async () => G.api('git.stage', { root, paths: [change.path] })),
1468
+ onRevert: () => {
1469
+ if (change.untracked === true
1470
+ && window.confirm(t('git.deleteUntrackedConfirm').replace('{path}', change.path)) !== true) return
1471
+ void act(async () => G.api('git.discard', { root, repo: repoParam, paths: [change.path] }))
1472
+ },
1473
+ revertLabel: change.untracked === true ? t('git.deleteUntrackedFile') : t('git.discardFile'),
1474
+ onAction: () => void act(async () => G.api('git.stage', { root, repo: repoParam, paths: [change.path] })),
1437
1475
  actionLabel: t('git.stage'),
1438
1476
  actionIcon: 'plus',
1439
1477
  }),
@@ -1453,14 +1491,14 @@ G.GitPanel = function GitPanel(props) {
1453
1491
  ? h(G.MenuItem, {
1454
1492
  icon: 'plus',
1455
1493
  label: t('git.stageAll'),
1456
- onClick: menuAction(() => void act(async () => { await G.api('git.stage', { root, paths: unstaged.map((item) => item.path) }) })),
1494
+ onClick: menuAction(() => void act(async () => { await G.api('git.stage', { root, repo: repoParam, paths: unstaged.map((item) => item.path) }) })),
1457
1495
  })
1458
1496
  : null,
1459
1497
  staged.length > 0
1460
1498
  ? h(G.MenuItem, {
1461
1499
  icon: 'minus',
1462
1500
  label: t('git.unstageAll'),
1463
- onClick: menuAction(() => void act(async () => { await G.api('git.unstage', { root, paths: staged.map((item) => item.path) }) })),
1501
+ onClick: menuAction(() => void act(async () => { await G.api('git.unstage', { root, repo: repoParam, paths: staged.map((item) => item.path) }) })),
1464
1502
  })
1465
1503
  : null,
1466
1504
  unstaged.length > 0
@@ -1468,18 +1506,18 @@ G.GitPanel = function GitPanel(props) {
1468
1506
  icon: 'undo',
1469
1507
  label: t('git.discardAll'),
1470
1508
  danger: true,
1471
- onClick: menuAction(() => void act(async () => { await G.api('git.discardAll', { root }) })),
1509
+ onClick: menuAction(() => void act(async () => { await G.api('git.discardAll', { root, repo: repoParam }) })),
1472
1510
  })
1473
1511
  : null,
1474
1512
  h(G.MenuItem, {
1475
1513
  icon: 'arrow-left',
1476
1514
  label: t('git.undoLastCommit'),
1477
- onClick: menuAction(() => void act(async () => { await G.api('git.undoLastCommit', { root }) })),
1515
+ onClick: menuAction(() => void act(async () => { await G.api('git.undoLastCommit', { root, repo: repoParam }) })),
1478
1516
  }),
1479
1517
  h(G.MenuItem, {
1480
1518
  icon: 'graph',
1481
1519
  label: t('graph.open'),
1482
- onClick: menuAction(() => props.onOpenGraph?.()),
1520
+ onClick: menuAction(() => props.onOpenGraph?.(repo)),
1483
1521
  }),
1484
1522
  )),
1485
1523
  rowMenu === null
@@ -1491,24 +1529,29 @@ G.GitPanel = function GitPanel(props) {
1491
1529
  style: { left: rowMenu.x, top: rowMenu.y, position: 'fixed', minWidth: 190 },
1492
1530
  onMouseDown: (event) => event.stopPropagation(),
1493
1531
  },
1494
- h(G.MenuItem, { icon: 'code', label: t('git.viewDiff'), onClick: menuAction(() => props.onOpenDiff?.(rowMenu.change)) }),
1532
+ h(G.MenuItem, { icon: 'code', label: t('git.viewDiff'), onClick: menuAction(() => props.onOpenDiff?.(changeWithRepo(rowMenu.change))) }),
1495
1533
  rowMenu.change.staged === true
1496
1534
  ? h(G.MenuItem, {
1497
1535
  icon: 'minus',
1498
1536
  label: t('git.unstage'),
1499
- onClick: menuAction(() => void act(async () => { await G.api('git.unstage', { root, paths: [rowMenu.change.path] }) })),
1537
+ onClick: menuAction(() => void act(async () => { await G.api('git.unstage', { root, repo: repoParam, paths: [rowMenu.change.path] }) })),
1500
1538
  })
1501
1539
  : h(G.MenuItem, {
1502
1540
  icon: 'plus',
1503
1541
  label: t('git.stage'),
1504
- onClick: menuAction(() => void act(async () => { await G.api('git.stage', { root, paths: [rowMenu.change.path] }) })),
1542
+ onClick: menuAction(() => void act(async () => { await G.api('git.stage', { root, repo: repoParam, paths: [rowMenu.change.path] }) })),
1505
1543
  }),
1506
1544
  rowMenu.change.staged !== true
1507
1545
  ? h(G.MenuItem, {
1508
1546
  icon: 'undo',
1509
- label: t('git.discardFile'),
1547
+ label: rowMenu.change.untracked === true ? t('git.deleteUntrackedFile') : t('git.discardFile'),
1510
1548
  danger: true,
1511
- onClick: menuAction(() => void act(async () => { await G.api('git.discard', { root, paths: [rowMenu.change.path] }) })),
1549
+ onClick: menuAction(() => {
1550
+ const change = rowMenu.change
1551
+ if (change.untracked === true
1552
+ && window.confirm(t('git.deleteUntrackedConfirm').replace('{path}', change.path)) !== true) return
1553
+ void act(async () => { await G.api('git.discard', { root, repo: repoParam, paths: [change.path] }) })
1554
+ }),
1512
1555
  })
1513
1556
  : null,
1514
1557
  h(G.MenuItem, { icon: 'files', label: t('git.copyPath'), onClick: menuAction(() => copyText(rowMenu.change.path)) }),
@@ -1516,8 +1559,159 @@ G.GitPanel = function GitPanel(props) {
1516
1559
  )
1517
1560
  }
1518
1561
 
1562
+ /* ── 源代码管理:工作区内所有 Git 仓库列表(根仓库 + 子目录仓库),逐仓库操作 ── */
1563
+ G.GitPanel = function GitPanel(props) {
1564
+ const t = G.useT()
1565
+ const workspaceRoot = props.root
1566
+ const [repos, setRepos] = useState(null)
1567
+ const [activePath, setActivePath] = useState(null)
1568
+ const [summaries, setSummaries] = useState({})
1569
+ const [reloadToken, setReloadToken] = useState(0)
1570
+ const [summaryTick, setSummaryTick] = useState(0)
1571
+
1572
+ useEffect(() => {
1573
+ let cancelled = false
1574
+ setRepos(null)
1575
+ if (!workspaceRoot) {
1576
+ setRepos([])
1577
+ return () => { cancelled = true }
1578
+ }
1579
+ void G.api('git.repos', { root: workspaceRoot })
1580
+ .then((value) => {
1581
+ if (cancelled) return
1582
+ const list = Array.isArray(value?.repos) ? value.repos : []
1583
+ setRepos(list)
1584
+ setActivePath((current) => (list.some((item) => item.path === current) ? current : (list[0]?.path ?? null)))
1585
+ })
1586
+ .catch(() => {
1587
+ if (cancelled) return
1588
+ /* 旧 Host 没有 git.repos:退回原来的单仓库模式 */
1589
+ const fallback = [{ path: workspaceRoot, rel: '', name: G.basename(workspaceRoot), isRoot: true }]
1590
+ setRepos(fallback)
1591
+ setActivePath(workspaceRoot)
1592
+ })
1593
+ return () => { cancelled = true }
1594
+ }, [workspaceRoot, props.refreshToken, reloadToken])
1595
+
1596
+ useEffect(() => {
1597
+ if (!workspaceRoot || repos === null || repos.length === 0) return undefined
1598
+ let cancelled = false
1599
+ void Promise.all(repos.map(async (repo) => {
1600
+ try {
1601
+ const status = await G.api('git.status', { root: workspaceRoot, repo: repo.path })
1602
+ return [repo.path, status]
1603
+ } catch {
1604
+ return [repo.path, null]
1605
+ }
1606
+ })).then((entries) => {
1607
+ if (cancelled) return
1608
+ setSummaries(Object.fromEntries(entries))
1609
+ })
1610
+ return () => { cancelled = true }
1611
+ }, [workspaceRoot, repos, props.refreshToken, summaryTick])
1612
+
1613
+ /* 子目录仓库的变化不会被工作区根目录的轮询发现,面板打开时每 5s 刷新一次各仓库摘要 */
1614
+ useEffect(() => {
1615
+ if (!workspaceRoot) return undefined
1616
+ const timer = window.setInterval(() => setSummaryTick((tick) => tick + 1), 5000)
1617
+ return () => window.clearInterval(timer)
1618
+ }, [workspaceRoot])
1619
+
1620
+ const handleStatus = (value) => {
1621
+ const repoPath = typeof value?.repo === 'string' ? value.repo : null
1622
+ if (repoPath !== null) setSummaries((current) => ({ ...current, [repoPath]: value }))
1623
+ let forwarded = value
1624
+ if (repoPath !== null && Array.isArray(value?.changes)) {
1625
+ const repo = repos?.find((item) => item.path === repoPath)
1626
+ if (repo !== undefined && repo.rel !== '') {
1627
+ forwarded = { ...value, changes: value.changes.map((change) => ({ ...change, path: `${repo.rel}/${change.path}` })) }
1628
+ }
1629
+ }
1630
+ props.onStatus?.(forwarded)
1631
+ }
1632
+
1633
+ const activeRepo = repos !== null && activePath !== null
1634
+ ? repos.find((item) => item.path === activePath) ?? null
1635
+ : null
1636
+ const showList = repos !== null && repos.length > 1
1637
+ const detailProps = {
1638
+ root: workspaceRoot,
1639
+ refreshToken: props.refreshToken,
1640
+ onStatus: handleStatus,
1641
+ onOpenFile: props.onOpenFile,
1642
+ onOpenDiff: props.onOpenDiff,
1643
+ onOpenBranches: props.onOpenBranches,
1644
+ onOpenGraph: props.onOpenGraph,
1645
+ onChanged: props.onChanged,
1646
+ }
1647
+
1648
+ return h(
1649
+ 'div',
1650
+ { style: { display: 'flex', flexDirection: 'column', height: '100%', minHeight: 0 } },
1651
+ showList
1652
+ ? h(
1653
+ 'div',
1654
+ { className: 'gufa-git-repos' },
1655
+ h(
1656
+ 'div',
1657
+ { className: 'gufa-git-repos-head' },
1658
+ h('span', null, `${t('git.repos')} (${repos.length})`),
1659
+ h(G.IconButton, {
1660
+ title: t('git.refresh'),
1661
+ onClick: () => setReloadToken((token) => token + 1),
1662
+ }, h(G.Icon, { name: 'refresh', size: 12 })),
1663
+ ),
1664
+ h(
1665
+ 'div',
1666
+ { className: 'gufa-git-repos-list gufa-scroll' },
1667
+ ...repos.map((repo) => {
1668
+ const summary = summaries[repo.path]
1669
+ const changeCount = Array.isArray(summary?.changes) ? summary.changes.length : 0
1670
+ const ahead = Number(summary?.ahead ?? 0)
1671
+ const behind = Number(summary?.behind ?? 0)
1672
+ return h(
1673
+ 'button',
1674
+ {
1675
+ key: repo.path,
1676
+ type: 'button',
1677
+ className: 'gufa-git-repo-row',
1678
+ 'data-active': repo.path === activePath ? '' : undefined,
1679
+ title: repo.path,
1680
+ onClick: () => setActivePath(repo.path),
1681
+ },
1682
+ h(G.Icon, { name: 'git', size: 13 }),
1683
+ h(
1684
+ 'span',
1685
+ { className: 'gufa-git-repo-meta' },
1686
+ h('span', { className: 'gufa-git-repo-name' }, repo.rel === '' ? t('git.workspaceRoot') : repo.rel),
1687
+ h('span', { className: 'gufa-git-repo-branch' }, summary?.branch || '—'),
1688
+ ),
1689
+ changeCount > 0 ? h('span', { className: 'gufa-badge' }, String(changeCount)) : null,
1690
+ ahead > 0 ? h('span', { className: 'gufa-git-repo-sync' }, `↑${ahead}`) : null,
1691
+ behind > 0 ? h('span', { className: 'gufa-git-repo-sync' }, `↓${behind}`) : null,
1692
+ )
1693
+ }),
1694
+ ),
1695
+ )
1696
+ : null,
1697
+ h(
1698
+ 'div',
1699
+ { style: { flex: '1 1 auto', minHeight: 0, display: 'flex', flexDirection: 'column' } },
1700
+ repos === null
1701
+ ? h('div', { className: 'gufa-panel-body' }, h(G.Empty, { title: t('common.loading') }))
1702
+ : h(G.GitRepoDetail, {
1703
+ key: activeRepo !== null ? activeRepo.path : 'root',
1704
+ ...detailProps,
1705
+ repo: activeRepo,
1706
+ }),
1707
+ ),
1708
+ )
1709
+ }
1710
+
1519
1711
  G.GitChangeRow = function GitChangeRow(props) {
1520
1712
  const change = props.change
1713
+ /* 未跟踪文件在 git porcelain 里是 ??,面板里显示成更直观的 U(Untracked) */
1714
+ const displayStatus = change.untracked === true || change.status === '??' ? 'U' : change.status
1521
1715
  return h(
1522
1716
  'div',
1523
1717
  {
@@ -1531,7 +1725,7 @@ G.GitChangeRow = function GitChangeRow(props) {
1531
1725
  },
1532
1726
  style: { cursor: 'pointer' },
1533
1727
  },
1534
- h('span', { className: 'gufa-git-status', 'data-kind': change.status }, change.status),
1728
+ h('span', { className: 'gufa-git-status', 'data-kind': displayStatus }, displayStatus),
1535
1729
  h('span', { className: 'gufa-git-path', style: { flex: '1 1 auto' } }, change.path),
1536
1730
  props.staged !== true && typeof props.onRevert === 'function'
1537
1731
  ? h(
@@ -257,6 +257,12 @@ G.installShortcutIntegration = function installShortcutIntegration(service) {
257
257
 
258
258
  // 经典模式:不碰任何 DSH 原生命令
259
259
  if (G.mode.get() !== true) {
260
+ /* IDE 模式退出时把 dispatch 补丁还原,经典模式继续走 DSH 原生派发 */
261
+ if (registry.__gufaDispatchPatched === true && typeof registry.__gufaOriginalDispatch === 'function') {
262
+ registry.dispatch = registry.__gufaOriginalDispatch
263
+ delete registry.__gufaOriginalDispatch
264
+ delete registry.__gufaDispatchPatched
265
+ }
260
266
  try {
261
267
  if (window !== undefined && window !== null) {
262
268
  if (window.__gufaClassicShortcutLogs === undefined) window.__gufaClassicShortcutLogs = 3
@@ -296,6 +302,22 @@ G.installShortcutIntegration = function installShortcutIntegration(service) {
296
302
  'edrv.prevTab': 'prevTab',
297
303
  'edrv.nextTab': 'nextTab',
298
304
  }
305
+ /* DSH 升级/用户自定义可能把 Cmd+K 改绑到别的命令 id:以当前快捷键目录为准,
306
+ 把实际占用「主修饰键+K」的命令也改派成 clearTerminal(默认仍是 session.search)。 */
307
+ try {
308
+ const rows = registry.catalog !== null && registry.catalog !== undefined && typeof registry.catalog.getSnapshot === 'function'
309
+ ? registry.catalog.getSnapshot()
310
+ : []
311
+ const wanted = G.isMacPlatform() ? '⌘K' : 'Ctrl+K'
312
+ for (const row of Array.isArray(rows) ? rows : []) {
313
+ const keys = Array.isArray(row?.keys) ? row.keys : []
314
+ if (keys.join('') !== wanted) continue
315
+ if (typeof row?.id !== 'string' || row.id === '') continue
316
+ if (typeof commandActions[row.id] !== 'string') commandActions[row.id] = 'clearTerminal'
317
+ }
318
+ } catch {
319
+ /* ignore */
320
+ }
299
321
  service.__gufaCommandActions = commandActions
300
322
  const wrapped = []
301
323
  const commands = registry.commands
@@ -312,6 +334,10 @@ G.installShortcutIntegration = function installShortcutIntegration(service) {
312
334
  status: 'handled',
313
335
  run: () => {
314
336
  try {
337
+ if ((window.__gufaCommandRemapLogs ?? 0) < 20) {
338
+ window.__gufaCommandRemapLogs = (window.__gufaCommandRemapLogs ?? 0) + 1
339
+ void G.api('dev.log', { message: `command-remap ${id} -> ${mapped}` }).catch(() => {})
340
+ }
315
341
  if (mapped.startsWith('editor:')) {
316
342
  if (G.bus !== null && G.bus !== undefined) G.bus.emit('editor:command', mapped.slice('editor:'.length))
317
343
  return
@@ -352,7 +378,79 @@ G.installShortcutIntegration = function installShortcutIntegration(service) {
352
378
  service.__gufaPatchedCommands.push({ command, originalResolve })
353
379
  wrapped.push(id)
354
380
  }
381
+ /* 懒加载的命令(例如 workspace 的 session.search 可能晚于插件初始化才注册):
382
+ 包一次 commands.set,注册时立即补上 resolve 改派,避免 Cmd+K 又退回原生搜索。 */
383
+ try {
384
+ if (typeof commands.set === 'function' && commands.__gufaSetPatched !== true) {
385
+ const originalSet = commands.set
386
+ commands.set = function gufaShortcutCommandsSet(id, command) {
387
+ const result = originalSet.call(this, id, command)
388
+ try {
389
+ const mapped = service.__gufaCommandActions === null || service.__gufaCommandActions === undefined
390
+ ? undefined
391
+ : service.__gufaCommandActions[id]
392
+ if (typeof mapped === 'string' && command !== null && command !== undefined
393
+ && typeof command.resolve === 'function' && command.__gufaWrapped !== true) {
394
+ const originalResolve = command.resolve
395
+ try {
396
+ Object.defineProperty(command, '__gufaOriginalResolve', { value: originalResolve, configurable: true })
397
+ } catch {
398
+ /* ignore */
399
+ }
400
+ command.resolve = makeResolve(id, originalResolve)
401
+ try {
402
+ Object.defineProperty(command, '__gufaWrapped', { value: true, configurable: true })
403
+ } catch {
404
+ /* ignore */
405
+ }
406
+ if (Array.isArray(service.__gufaPatchedCommands) !== true) service.__gufaPatchedCommands = []
407
+ service.__gufaPatchedCommands.push({ command, originalResolve })
408
+ }
409
+ } catch {
410
+ /* ignore */
411
+ }
412
+ return result
413
+ }
414
+ commands.__gufaSetPatched = true
415
+ }
416
+ } catch {
417
+ /* ignore */
418
+ }
419
+ }
420
+ /* 兜底:如果 Cmd+K 在 DSH 里存在快捷键冲突,dispatch 会在调用 command.resolve 之前就
421
+ 把按键 consume 掉(表现为快捷键完全没反应)。IDE 模式下直接在 dispatch 最前面接管
422
+ 主修饰键+K → 清空终端,不依赖具体 command id 是否被包到。 */
423
+ try {
424
+ if (typeof registry.dispatch === 'function' && registry.__gufaDispatchPatched !== true) {
425
+ const originalDispatch = registry.dispatch
426
+ registry.dispatch = function gufaIdeDispatch(gesture, context, consume) {
427
+ try {
428
+ if (G.mode.get() === true
429
+ && typeof document !== 'undefined'
430
+ && document.querySelector('.gufa-overlay-root') !== null
431
+ && typeof window.__gufaIdeShortcutDispatch === 'function') {
432
+ const mac = G.isMacPlatform()
433
+ const primary = mac ? gesture?.meta === true && gesture?.control !== true : gesture?.control === true
434
+ if (primary && gesture?.code === 'KeyK' && gesture?.shift !== true && gesture?.alt !== true) {
435
+ if (typeof consume === 'function') consume()
436
+ if (gesture?.repeat !== true) {
437
+ try { window.__gufaIdeShortcutDispatch('clearTerminal') } catch { /* ignore */ }
438
+ }
439
+ return { status: 'handled', commandId: 'gufa.ide.clearTerminal' }
440
+ }
441
+ }
442
+ } catch {
443
+ /* ignore */
444
+ }
445
+ return originalDispatch.call(this, gesture, context, consume)
446
+ }
447
+ registry.__gufaOriginalDispatch = originalDispatch
448
+ registry.__gufaDispatchPatched = true
449
+ }
450
+ } catch {
451
+ /* ignore */
355
452
  }
453
+
356
454
  // ── 命令表/配置尚未就绪时重试(插件加载可能早于 ui-layout 注册命令)──
357
455
  const expected = Object.keys(commandActions).length
358
456
  try {