dsh-gufa-code 1.3.65 → 1.3.68

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/client.js CHANGED
@@ -16,7 +16,7 @@ const GUFA_NS = 'gufa-code'
16
16
  const G = {}
17
17
  G.NS = GUFA_NS
18
18
  /** 客户端构建标记(排查页面是否加载了新代码时看标题栏) */
19
- G.BUILD = '1.3.65'
19
+ G.BUILD = '1.3.68'
20
20
  G.PANEL_ID = 'gufa-code'
21
21
  /** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
22
22
  G.pendingEntryWorkspace = null
@@ -210,11 +210,12 @@ const DICT_ZH = {
210
210
  'search.preserveCase': '保留大小写(AB)',
211
211
  'search.replaceOne': '替换此匹配',
212
212
  'search.dismiss': '忽略此匹配',
213
+ 'search.dismissFile': '忽略该文件的所有匹配',
213
214
  'search.openInEditor': '在编辑器中打开',
214
215
  'search.stale': '匹配位置已变化,已重新搜索',
215
216
  'search.replacePlaceholder': '替换为…',
216
217
  'search.replaceAll': '全部替换',
217
- 'search.replaceThisFile': '替换此文件',
218
+ 'search.replaceThisFile': '替换该文件所有匹配',
218
219
  'search.replacing': '替换中…',
219
220
  'search.confirmReplace': '确定替换 {count} 处({files} 个文件)?直接写文件,编辑器撤销无效。',
220
221
  'search.confirmYes': '确定替换',
@@ -456,11 +457,12 @@ const DICT_EN = {
456
457
  'search.preserveCase': 'Preserve case (AB)',
457
458
  'search.replaceOne': 'Replace this match',
458
459
  'search.dismiss': 'Dismiss this match',
460
+ 'search.dismissFile': 'Dismiss all matches in this file',
459
461
  'search.openInEditor': 'Open in editor',
460
462
  'search.stale': 'Match moved; search refreshed',
461
463
  'search.replacePlaceholder': 'Replace with…',
462
464
  'search.replaceAll': 'Replace all',
463
- 'search.replaceThisFile': 'Replace in this file',
465
+ 'search.replaceThisFile': 'Replace all matches in this file',
464
466
  'search.replacing': 'Replacing…',
465
467
  'search.confirmReplace': 'Replace {count} occurrences in {files} files? This writes files directly; editor undo will not work.',
466
468
  'search.confirmYes': 'Replace',
@@ -1759,6 +1761,10 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
1759
1761
  .gufa-search-summarybar{display:flex;align-items:center;gap:8px}
1760
1762
  .gufa-search-summarybar .gufa-search-summary{flex:1 1 auto;margin-left:0}
1761
1763
  .gufa-search-summarybar .gufa-search-link{flex:0 0 auto}
1764
+ .gufa-tip{position:fixed;z-index:2147483600;max-width:320px;padding:4px 8px;border-radius:5px;background:#2c2f36;color:#f2f2f2;border:1px solid rgba(255,255,255,.18);font-size:11px;line-height:1.45;white-space:normal;pointer-events:none;box-shadow:0 4px 14px rgba(0,0,0,.4)}
1765
+ .gufa-search-file-dismiss{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;margin-left:2px;border-radius:4px;color:var(--gufa-text-dim);cursor:pointer;opacity:0;transition:opacity .12s ease}
1766
+ .gufa-search-file-head:hover .gufa-search-file-dismiss,.gufa-search-file-head:focus-within .gufa-search-file-dismiss{opacity:1}
1767
+ .gufa-search-file-dismiss:hover{background:var(--gufa-active);color:var(--gufa-text)}
1762
1768
  .gufa-search-link{border:0;background:transparent;color:var(--gufa-accent);font-size:11px;cursor:pointer;padding:0}
1763
1769
  .gufa-search-link:hover{text-decoration:underline}
1764
1770
 
@@ -2197,6 +2203,11 @@ const ICON_PATHS = {
2197
2203
  ['path', { d: 'M12 2.8l1 2.6 2.7.7 2-1.8 2.2 2.2-1.8 2 .7 2.7 2.6 1v3l-2.6 1-.7 2.7 1.8 2-2.2 2.2-2-1.8-2.7.7-1 2.6h-3l-1-2.6-2.7-.7-2 1.8-2.2-2.2 1.8-2-.7-2.7-2.6-1v-3l2.6-1 .7-2.7-1.8-2 2.2-2.2 2 1.8 2.7-.7 1-2.6h3z' }],
2198
2204
  ],
2199
2205
  code: [['path', { d: 'M8.5 6L3 12l5.5 6M15.5 6L21 12l-5.5 6' }]],
2206
+ replace: [
2207
+ ['rect', { x: 7, y: 4.5, width: 12.5, height: 15, rx: 2 }],
2208
+ ['path', { d: 'M3 12h9' }],
2209
+ ['path', { d: 'M9.5 9.5L12 12l-2.5 2.5' }],
2210
+ ],
2200
2211
  search: [['circle', { cx: 11, cy: 11, r: 6.5 }], ['path', { d: 'M16 16l4.5 4.5' }]],
2201
2212
  message: [['path', { d: 'M4 5h16a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H9l-5 4V6a1 1 0 0 1 1-1z' }]],
2202
2213
  'panel-right': [['rect', { x: 3, y: 4, width: 18, height: 16, rx: 2 }], ['path', { d: 'M14 4v16' }]],
@@ -7351,6 +7362,7 @@ G.SearchPanel = function SearchPanel(props) {
7351
7362
  const [confirming, setConfirming] = useState(null)
7352
7363
  const [replacing, setReplacing] = useState(false)
7353
7364
  const [replaceError, setReplaceError] = useState('')
7365
+ const [tip, setTip] = useState(null)
7354
7366
  const inputRef = useRef(null)
7355
7367
  const requestRef = useRef(0)
7356
7368
 
@@ -7535,6 +7547,34 @@ G.SearchPanel = function SearchPanel(props) {
7535
7547
  return next
7536
7548
  })
7537
7549
  }
7550
+ const dismissFile = (file) => {
7551
+ setIgnored((current) => {
7552
+ const next = new Set(current)
7553
+ for (const match of file.matches) next.add(matchKey(file.path, match))
7554
+ return next
7555
+ })
7556
+ }
7557
+ /* 悬停提示:鼠标进入时在图标下方显示一行说明(原生 title 在 WebView 里要等很久,体验差) */
7558
+ const tipProps = (text) => ({
7559
+ onMouseEnter: (event) => {
7560
+ try {
7561
+ const rect = event.currentTarget.getBoundingClientRect()
7562
+ setTip({ text, left: Math.min(rect.left, window.innerWidth - 330), top: Math.min(rect.bottom + 6, window.innerHeight - 40) })
7563
+ } catch {
7564
+ /* ignore */
7565
+ }
7566
+ },
7567
+ onMouseLeave: () => setTip(null),
7568
+ onFocus: (event) => {
7569
+ try {
7570
+ const rect = event.currentTarget.getBoundingClientRect()
7571
+ setTip({ text, left: Math.min(rect.left, window.innerWidth - 330), top: Math.min(rect.bottom + 6, window.innerHeight - 40) })
7572
+ } catch {
7573
+ /* ignore */
7574
+ }
7575
+ },
7576
+ onBlur: () => setTip(null),
7577
+ })
7538
7578
  const openFirst = () => {
7539
7579
  const file = view?.files?.[0]
7540
7580
  const match = file?.matches?.[0]
@@ -7589,15 +7629,31 @@ G.SearchPanel = function SearchPanel(props) {
7589
7629
  className: 'gufa-search-file-replace',
7590
7630
  title: t('search.replaceThisFile'),
7591
7631
  role: 'button',
7632
+ ...tipProps(t('search.replaceThisFile')),
7592
7633
  onClick: (event) => {
7593
7634
  event.stopPropagation()
7594
7635
  event.preventDefault()
7595
7636
  replaceFile(file)
7596
7637
  },
7597
7638
  },
7598
- h(G.Icon, { name: 'pencil', size: 11 }),
7639
+ h(G.Icon, { name: 'replace', size: 12 }),
7599
7640
  )
7600
7641
  : null,
7642
+ h(
7643
+ 'span',
7644
+ {
7645
+ className: 'gufa-search-file-dismiss',
7646
+ title: t('search.dismissFile'),
7647
+ role: 'button',
7648
+ ...tipProps(t('search.dismissFile')),
7649
+ onClick: (event) => {
7650
+ event.stopPropagation()
7651
+ event.preventDefault()
7652
+ dismissFile(file)
7653
+ },
7654
+ },
7655
+ h(G.Icon, { name: 'close', size: 11 }),
7656
+ ),
7601
7657
  ),
7602
7658
  isCollapsed
7603
7659
  ? null
@@ -7629,13 +7685,14 @@ G.SearchPanel = function SearchPanel(props) {
7629
7685
  className: 'gufa-search-row-action',
7630
7686
  title: t('search.replaceOne'),
7631
7687
  role: 'button',
7688
+ ...tipProps(t('search.replaceOne')),
7632
7689
  onClick: (event) => {
7633
7690
  event.stopPropagation()
7634
7691
  event.preventDefault()
7635
7692
  replaceOne(file.path, match)
7636
7693
  },
7637
7694
  },
7638
- h(G.Icon, { name: 'pencil', size: 11 }),
7695
+ h(G.Icon, { name: 'replace', size: 12 }),
7639
7696
  )
7640
7697
  : null,
7641
7698
  h(
@@ -7644,6 +7701,7 @@ G.SearchPanel = function SearchPanel(props) {
7644
7701
  className: 'gufa-search-row-action',
7645
7702
  title: t('search.dismiss'),
7646
7703
  role: 'button',
7704
+ ...tipProps(t('search.dismiss')),
7647
7705
  onClick: (event) => {
7648
7706
  event.stopPropagation()
7649
7707
  event.preventDefault()
@@ -7693,7 +7751,11 @@ G.SearchPanel = function SearchPanel(props) {
7693
7751
  query === ''
7694
7752
  ? null
7695
7753
  : h(G.IconButton, { title: t('search.clear'), onClick: () => { setQuery(''); focusInput() } }, h(G.Icon, { name: 'close', size: 11 })),
7696
- h(G.IconButton, { title: t('search.replaceToggle'), onClick: () => setReplaceOpen((value) => !value) }, h(G.Icon, { name: replaceOpen ? 'chevron-up' : 'chevron-down', size: 12 })),
7754
+ h(
7755
+ 'span',
7756
+ { style: { display: 'inline-flex' }, ...tipProps(t('search.replaceToggle')) },
7757
+ h(G.IconButton, { title: t('search.replaceToggle'), onClick: () => setReplaceOpen((value) => !value) }, h(G.Icon, { name: replaceOpen ? 'chevron-up' : 'chevron-down', size: 12 })),
7758
+ ),
7697
7759
  ),
7698
7760
  h(
7699
7761
  'div',
@@ -7739,6 +7801,7 @@ G.SearchPanel = function SearchPanel(props) {
7739
7801
  className: 'gufa-search-toggle',
7740
7802
  'data-active': preserveCase ? '' : undefined,
7741
7803
  title: t('search.preserveCase'),
7804
+ ...tipProps(t('search.preserveCase')),
7742
7805
  onClick: () => setPreserveCase((value) => !value),
7743
7806
  }, 'AB'),
7744
7807
  ),
@@ -7809,6 +7872,7 @@ G.SearchPanel = function SearchPanel(props) {
7809
7872
  replaceError !== '' ? h('div', { className: 'gufa-search-error' }, `${t('search.replaceError')}:${replaceError}`) : null,
7810
7873
  ),
7811
7874
  h('div', { className: 'gufa-panel-body gufa-scroll' }, body),
7875
+ tip !== null ? h('div', { className: 'gufa-tip', style: { left: `${tip.left}px`, top: `${tip.top}px` } }, tip.text) : null,
7812
7876
  )
7813
7877
  }
7814
7878
 
@@ -8116,6 +8180,20 @@ G.GitPanel = function GitPanel(props) {
8116
8180
  h(G.Button, { disabled: pending || message.trim() === '', primary: true, onClick: commit }, pending ? h(G.Spinner) : null, t('git.commit')),
8117
8181
  )
8118
8182
  : null,
8183
+ staged.length > 0 ? h('div', { className: 'gufa-hint' }, `${t('git.staged')} (${staged.length})`) : null,
8184
+ ...staged.map((change) =>
8185
+ h(G.GitChangeRow, {
8186
+ key: `s:${change.path}`,
8187
+ change,
8188
+ pending,
8189
+ staged: true,
8190
+ onOpen: () => props.onOpenDiff?.(change),
8191
+ onContextMenu: (event, rowChange) => setRowMenu({ ...clampMenuPosition(event.clientX, event.clientY, 200, 200), change: rowChange }),
8192
+ onAction: () => void act(async () => G.api('git.unstage', { root, paths: [change.path] })),
8193
+ actionLabel: t('git.unstage'),
8194
+ actionIcon: 'minus',
8195
+ }),
8196
+ ),
8119
8197
  unstaged.length > 0 ? h('div', { className: 'gufa-hint' }, `${t('git.unstaged')} (${unstaged.length})`) : null,
8120
8198
  ...unstaged.map((change) =>
8121
8199
  h(G.GitChangeRow, {
@@ -8131,20 +8209,6 @@ G.GitPanel = function GitPanel(props) {
8131
8209
  actionIcon: 'plus',
8132
8210
  }),
8133
8211
  ),
8134
- staged.length > 0 ? h('div', { className: 'gufa-hint' }, `${t('git.staged')} (${staged.length})`) : null,
8135
- ...staged.map((change) =>
8136
- h(G.GitChangeRow, {
8137
- key: `s:${change.path}`,
8138
- change,
8139
- pending,
8140
- staged: true,
8141
- onOpen: () => props.onOpenDiff?.(change),
8142
- onContextMenu: (event, rowChange) => setRowMenu({ ...clampMenuPosition(event.clientX, event.clientY, 200, 200), change: rowChange }),
8143
- onAction: () => void act(async () => G.api('git.unstage', { root, paths: [change.path] })),
8144
- actionLabel: t('git.unstage'),
8145
- actionIcon: 'minus',
8146
- }),
8147
- ),
8148
8212
  ),
8149
8213
  ),
8150
8214
  headMenu === null
@@ -10752,6 +10816,25 @@ G.GufaApp = function GufaApp(props) {
10752
10816
  return map
10753
10817
  }, [gitStatus])
10754
10818
 
10819
+ /* 暂存/取消暂存/提交后,已失效的 diff 标签自动关闭:
10820
+ 工作树 diff 只在文件仍有未暂存改动时有效,暂存区 diff 只在文件仍在暂存区时有效。 */
10821
+ useEffect(() => {
10822
+ if (project === null || project.isGit !== true || gitStatus === null) return
10823
+ const changes = Array.isArray(gitStatus.changes) ? gitStatus.changes : []
10824
+ const stagedPaths = new Set(changes.filter((item) => item?.staged === true).map((item) => item.path))
10825
+ const unstagedPaths = new Set(changes.filter((item) => item?.staged !== true).map((item) => item.path))
10826
+ const current = tabsRef.current ?? []
10827
+ const kept = current.filter((tab) => {
10828
+ if (tab === null || tab === undefined || tab.kind !== 'diff') return true
10829
+ if (tab.diff === null || tab.diff === undefined || tab.diff.compare === true) return true
10830
+ if (tab.diff.staged === true) return stagedPaths.has(tab.path)
10831
+ return unstagedPaths.has(tab.path)
10832
+ })
10833
+ if (kept.length === current.length) return
10834
+ setTabs(kept)
10835
+ setActivePath((active) => (active !== null && kept.some((tab) => tab.path === active) ? active : (kept.length > 0 ? kept[kept.length - 1].path : null)))
10836
+ }, [gitStatus, project])
10837
+
10755
10838
  /* ── 文件打开 / 保存 / 关闭 ─────────────────────────────────────────── */
10756
10839
  const openFile = useCallback(async (path) => {
10757
10840
  if (project === null) return
@@ -11179,7 +11262,13 @@ G.GufaApp = function GufaApp(props) {
11179
11262
  return
11180
11263
  }
11181
11264
  try {
11182
- const file = await G.api('fs.read', { root: project.root, path: change.path })
11265
+ /* 文件可能已删除(工作树删掉/暂存区删除):读不到就按空处理,仍然展示差异 */
11266
+ let file = null
11267
+ try {
11268
+ file = await G.api('fs.read', { root: project.root, path: change.path })
11269
+ } catch {
11270
+ file = null
11271
+ }
11183
11272
  let left = ''
11184
11273
  try {
11185
11274
  const shown = await G.api('git.show', {
@@ -11191,16 +11280,26 @@ G.GufaApp = function GufaApp(props) {
11191
11280
  } catch {
11192
11281
  left = ''
11193
11282
  }
11283
+ let rightContent = typeof file?.content === 'string' ? file.content : ''
11284
+ if (change.staged === true) {
11285
+ /* 暂存区 diff = HEAD ↔ 索引;右侧必须用索引内容,而不是工作树(工作树可能还有未暂存改动) */
11286
+ try {
11287
+ const indexDoc = await G.api('git.show', { root: project.root, path: change.path, rev: 'index' })
11288
+ rightContent = typeof indexDoc.text === 'string' ? indexDoc.text : ''
11289
+ } catch {
11290
+ rightContent = ''
11291
+ }
11292
+ }
11194
11293
  const tab = {
11195
11294
  path: change.path,
11196
11295
  title: `${G.basename(change.path)}(${change.staged === true ? '暂存区' : '工作树'})`,
11197
11296
  kind: 'diff',
11198
- content: file.content ?? '',
11199
- savedContent: file.content ?? '',
11200
- revision: file.revision,
11297
+ content: rightContent,
11298
+ savedContent: rightContent,
11299
+ revision: file?.revision,
11201
11300
  dirty: false,
11202
- language: file.language ?? 'plaintext',
11203
- size: file.size,
11301
+ language: file?.language ?? 'plaintext',
11302
+ size: file?.size,
11204
11303
  diff: { left, staged: change.staged === true, editable: change.staged !== true },
11205
11304
  diffKey: Date.now(),
11206
11305
  }
@@ -11274,6 +11373,9 @@ G.GufaApp = function GufaApp(props) {
11274
11373
  if (project === null) return
11275
11374
  try {
11276
11375
  await G.api('git.stage', { root: project.root, paths: [path] })
11376
+ /* 暂存后这个文件已经没有「工作树 vs 索引」差异:关掉当前 diff 标签,刷新后也不会再出现在未暂存区 */
11377
+ setTabs((current) => current.filter((tab) => !(tab.path === path && tab.kind === 'diff' && tab.diff !== null && tab.diff !== undefined && tab.diff.staged !== true)))
11378
+ setActivePath((active) => (active === path ? null : active))
11277
11379
  setGitRefreshToken((token) => token + 1)
11278
11380
  void refreshGit()
11279
11381
  } catch (error) {
@@ -7,8 +7,8 @@
7
7
  <key>CFBundleDisplayName</key><string>古法编程悬浮层</string>
8
8
  <key>CFBundleExecutable</key><string>gufa-float</string>
9
9
  <key>CFBundlePackageType</key><string>APPL</string>
10
- <key>CFBundleShortVersionString</key><string>1.3.65</string>
11
- <key>CFBundleVersion</key><string>1.3.65</string>
10
+ <key>CFBundleShortVersionString</key><string>1.3.68</string>
11
+ <key>CFBundleVersion</key><string>1.3.68</string>
12
12
  <key>LSUIElement</key><true/>
13
13
  <key>NSHighResolutionCapable</key><true/>
14
14
  <key>NSPrincipalClass</key><string>NSApplication</string>
package/host/git.js CHANGED
@@ -217,7 +217,7 @@ export function register(router, env) {
217
217
  const project = await projectOf(env, body)
218
218
  const path = typeof body.path === 'string' ? body.path : ''
219
219
  if (path === '' || path.startsWith('/') || path.includes('..')) throw badRequest('path is invalid')
220
- const rev = body.rev === 'head' ? 'HEAD' : ':'
220
+ const rev = body.rev === 'head' ? 'HEAD:' : ':'
221
221
  let text = ''
222
222
  let missing = false
223
223
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.65",
3
+ "version": "1.3.68",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -152,6 +152,10 @@ try {
152
152
  check('working tree clean after commit', clean.changes.length === 0, JSON.stringify(clean.changes))
153
153
  const log = await call(router, 'git.log', { root, limit: 5 })
154
154
  check('commit in log', log.commits.length === 1 && log.commits[0].subject === 'feat: selftest')
155
+ const headShow = await call(router, 'git.show', { root, path: 'src/main.ts', rev: 'head' })
156
+ check('git.show HEAD content', headShow.text === 'const answer = 42\n', JSON.stringify(headShow.text))
157
+ const indexShow = await call(router, 'git.show', { root, path: 'src/main.ts', rev: 'index' })
158
+ check('git.show index content', indexShow.text === 'const answer = 42\n', JSON.stringify(indexShow.text))
155
159
  const gitSearch = await call(router, 'fs.search', { root, query: 'answer' })
156
160
  check('search uses git file list', gitSearch.viaGit === true, String(gitSearch.viaGit))
157
161
  check('search finds committed file', gitSearch.files.some((file) => file.path === 'src/main.ts'))
@@ -202,11 +202,12 @@ const DICT_ZH = {
202
202
  'search.preserveCase': '保留大小写(AB)',
203
203
  'search.replaceOne': '替换此匹配',
204
204
  'search.dismiss': '忽略此匹配',
205
+ 'search.dismissFile': '忽略该文件的所有匹配',
205
206
  'search.openInEditor': '在编辑器中打开',
206
207
  'search.stale': '匹配位置已变化,已重新搜索',
207
208
  'search.replacePlaceholder': '替换为…',
208
209
  'search.replaceAll': '全部替换',
209
- 'search.replaceThisFile': '替换此文件',
210
+ 'search.replaceThisFile': '替换该文件所有匹配',
210
211
  'search.replacing': '替换中…',
211
212
  'search.confirmReplace': '确定替换 {count} 处({files} 个文件)?直接写文件,编辑器撤销无效。',
212
213
  'search.confirmYes': '确定替换',
@@ -448,11 +449,12 @@ const DICT_EN = {
448
449
  'search.preserveCase': 'Preserve case (AB)',
449
450
  'search.replaceOne': 'Replace this match',
450
451
  'search.dismiss': 'Dismiss this match',
452
+ 'search.dismissFile': 'Dismiss all matches in this file',
451
453
  'search.openInEditor': 'Open in editor',
452
454
  'search.stale': 'Match moved; search refreshed',
453
455
  'search.replacePlaceholder': 'Replace with…',
454
456
  'search.replaceAll': 'Replace all',
455
- 'search.replaceThisFile': 'Replace in this file',
457
+ 'search.replaceThisFile': 'Replace all matches in this file',
456
458
  'search.replacing': 'Replacing…',
457
459
  'search.confirmReplace': 'Replace {count} occurrences in {files} files? This writes files directly; editor undo will not work.',
458
460
  'search.confirmYes': 'Replace',
@@ -1751,6 +1753,10 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
1751
1753
  .gufa-search-summarybar{display:flex;align-items:center;gap:8px}
1752
1754
  .gufa-search-summarybar .gufa-search-summary{flex:1 1 auto;margin-left:0}
1753
1755
  .gufa-search-summarybar .gufa-search-link{flex:0 0 auto}
1756
+ .gufa-tip{position:fixed;z-index:2147483600;max-width:320px;padding:4px 8px;border-radius:5px;background:#2c2f36;color:#f2f2f2;border:1px solid rgba(255,255,255,.18);font-size:11px;line-height:1.45;white-space:normal;pointer-events:none;box-shadow:0 4px 14px rgba(0,0,0,.4)}
1757
+ .gufa-search-file-dismiss{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;margin-left:2px;border-radius:4px;color:var(--gufa-text-dim);cursor:pointer;opacity:0;transition:opacity .12s ease}
1758
+ .gufa-search-file-head:hover .gufa-search-file-dismiss,.gufa-search-file-head:focus-within .gufa-search-file-dismiss{opacity:1}
1759
+ .gufa-search-file-dismiss:hover{background:var(--gufa-active);color:var(--gufa-text)}
1754
1760
  .gufa-search-link{border:0;background:transparent;color:var(--gufa-accent);font-size:11px;cursor:pointer;padding:0}
1755
1761
  .gufa-search-link:hover{text-decoration:underline}
1756
1762
 
@@ -74,6 +74,11 @@ const ICON_PATHS = {
74
74
  ['path', { d: 'M12 2.8l1 2.6 2.7.7 2-1.8 2.2 2.2-1.8 2 .7 2.7 2.6 1v3l-2.6 1-.7 2.7 1.8 2-2.2 2.2-2-1.8-2.7.7-1 2.6h-3l-1-2.6-2.7-.7-2 1.8-2.2-2.2 1.8-2-.7-2.7-2.6-1v-3l2.6-1 .7-2.7-1.8-2 2.2-2.2 2 1.8 2.7-.7 1-2.6h3z' }],
75
75
  ],
76
76
  code: [['path', { d: 'M8.5 6L3 12l5.5 6M15.5 6L21 12l-5.5 6' }]],
77
+ replace: [
78
+ ['rect', { x: 7, y: 4.5, width: 12.5, height: 15, rx: 2 }],
79
+ ['path', { d: 'M3 12h9' }],
80
+ ['path', { d: 'M9.5 9.5L12 12l-2.5 2.5' }],
81
+ ],
77
82
  search: [['circle', { cx: 11, cy: 11, r: 6.5 }], ['path', { d: 'M16 16l4.5 4.5' }]],
78
83
  message: [['path', { d: 'M4 5h16a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H9l-5 4V6a1 1 0 0 1 1-1z' }]],
79
84
  'panel-right': [['rect', { x: 3, y: 4, width: 18, height: 16, rx: 2 }], ['path', { d: 'M14 4v16' }]],
@@ -529,6 +529,7 @@ G.SearchPanel = function SearchPanel(props) {
529
529
  const [confirming, setConfirming] = useState(null)
530
530
  const [replacing, setReplacing] = useState(false)
531
531
  const [replaceError, setReplaceError] = useState('')
532
+ const [tip, setTip] = useState(null)
532
533
  const inputRef = useRef(null)
533
534
  const requestRef = useRef(0)
534
535
 
@@ -713,6 +714,34 @@ G.SearchPanel = function SearchPanel(props) {
713
714
  return next
714
715
  })
715
716
  }
717
+ const dismissFile = (file) => {
718
+ setIgnored((current) => {
719
+ const next = new Set(current)
720
+ for (const match of file.matches) next.add(matchKey(file.path, match))
721
+ return next
722
+ })
723
+ }
724
+ /* 悬停提示:鼠标进入时在图标下方显示一行说明(原生 title 在 WebView 里要等很久,体验差) */
725
+ const tipProps = (text) => ({
726
+ onMouseEnter: (event) => {
727
+ try {
728
+ const rect = event.currentTarget.getBoundingClientRect()
729
+ setTip({ text, left: Math.min(rect.left, window.innerWidth - 330), top: Math.min(rect.bottom + 6, window.innerHeight - 40) })
730
+ } catch {
731
+ /* ignore */
732
+ }
733
+ },
734
+ onMouseLeave: () => setTip(null),
735
+ onFocus: (event) => {
736
+ try {
737
+ const rect = event.currentTarget.getBoundingClientRect()
738
+ setTip({ text, left: Math.min(rect.left, window.innerWidth - 330), top: Math.min(rect.bottom + 6, window.innerHeight - 40) })
739
+ } catch {
740
+ /* ignore */
741
+ }
742
+ },
743
+ onBlur: () => setTip(null),
744
+ })
716
745
  const openFirst = () => {
717
746
  const file = view?.files?.[0]
718
747
  const match = file?.matches?.[0]
@@ -767,15 +796,31 @@ G.SearchPanel = function SearchPanel(props) {
767
796
  className: 'gufa-search-file-replace',
768
797
  title: t('search.replaceThisFile'),
769
798
  role: 'button',
799
+ ...tipProps(t('search.replaceThisFile')),
770
800
  onClick: (event) => {
771
801
  event.stopPropagation()
772
802
  event.preventDefault()
773
803
  replaceFile(file)
774
804
  },
775
805
  },
776
- h(G.Icon, { name: 'pencil', size: 11 }),
806
+ h(G.Icon, { name: 'replace', size: 12 }),
777
807
  )
778
808
  : null,
809
+ h(
810
+ 'span',
811
+ {
812
+ className: 'gufa-search-file-dismiss',
813
+ title: t('search.dismissFile'),
814
+ role: 'button',
815
+ ...tipProps(t('search.dismissFile')),
816
+ onClick: (event) => {
817
+ event.stopPropagation()
818
+ event.preventDefault()
819
+ dismissFile(file)
820
+ },
821
+ },
822
+ h(G.Icon, { name: 'close', size: 11 }),
823
+ ),
779
824
  ),
780
825
  isCollapsed
781
826
  ? null
@@ -807,13 +852,14 @@ G.SearchPanel = function SearchPanel(props) {
807
852
  className: 'gufa-search-row-action',
808
853
  title: t('search.replaceOne'),
809
854
  role: 'button',
855
+ ...tipProps(t('search.replaceOne')),
810
856
  onClick: (event) => {
811
857
  event.stopPropagation()
812
858
  event.preventDefault()
813
859
  replaceOne(file.path, match)
814
860
  },
815
861
  },
816
- h(G.Icon, { name: 'pencil', size: 11 }),
862
+ h(G.Icon, { name: 'replace', size: 12 }),
817
863
  )
818
864
  : null,
819
865
  h(
@@ -822,6 +868,7 @@ G.SearchPanel = function SearchPanel(props) {
822
868
  className: 'gufa-search-row-action',
823
869
  title: t('search.dismiss'),
824
870
  role: 'button',
871
+ ...tipProps(t('search.dismiss')),
825
872
  onClick: (event) => {
826
873
  event.stopPropagation()
827
874
  event.preventDefault()
@@ -871,7 +918,11 @@ G.SearchPanel = function SearchPanel(props) {
871
918
  query === ''
872
919
  ? null
873
920
  : h(G.IconButton, { title: t('search.clear'), onClick: () => { setQuery(''); focusInput() } }, h(G.Icon, { name: 'close', size: 11 })),
874
- h(G.IconButton, { title: t('search.replaceToggle'), onClick: () => setReplaceOpen((value) => !value) }, h(G.Icon, { name: replaceOpen ? 'chevron-up' : 'chevron-down', size: 12 })),
921
+ h(
922
+ 'span',
923
+ { style: { display: 'inline-flex' }, ...tipProps(t('search.replaceToggle')) },
924
+ h(G.IconButton, { title: t('search.replaceToggle'), onClick: () => setReplaceOpen((value) => !value) }, h(G.Icon, { name: replaceOpen ? 'chevron-up' : 'chevron-down', size: 12 })),
925
+ ),
875
926
  ),
876
927
  h(
877
928
  'div',
@@ -917,6 +968,7 @@ G.SearchPanel = function SearchPanel(props) {
917
968
  className: 'gufa-search-toggle',
918
969
  'data-active': preserveCase ? '' : undefined,
919
970
  title: t('search.preserveCase'),
971
+ ...tipProps(t('search.preserveCase')),
920
972
  onClick: () => setPreserveCase((value) => !value),
921
973
  }, 'AB'),
922
974
  ),
@@ -987,6 +1039,7 @@ G.SearchPanel = function SearchPanel(props) {
987
1039
  replaceError !== '' ? h('div', { className: 'gufa-search-error' }, `${t('search.replaceError')}:${replaceError}`) : null,
988
1040
  ),
989
1041
  h('div', { className: 'gufa-panel-body gufa-scroll' }, body),
1042
+ tip !== null ? h('div', { className: 'gufa-tip', style: { left: `${tip.left}px`, top: `${tip.top}px` } }, tip.text) : null,
990
1043
  )
991
1044
  }
992
1045
 
@@ -1294,6 +1347,20 @@ G.GitPanel = function GitPanel(props) {
1294
1347
  h(G.Button, { disabled: pending || message.trim() === '', primary: true, onClick: commit }, pending ? h(G.Spinner) : null, t('git.commit')),
1295
1348
  )
1296
1349
  : null,
1350
+ staged.length > 0 ? h('div', { className: 'gufa-hint' }, `${t('git.staged')} (${staged.length})`) : null,
1351
+ ...staged.map((change) =>
1352
+ h(G.GitChangeRow, {
1353
+ key: `s:${change.path}`,
1354
+ change,
1355
+ pending,
1356
+ staged: true,
1357
+ onOpen: () => props.onOpenDiff?.(change),
1358
+ onContextMenu: (event, rowChange) => setRowMenu({ ...clampMenuPosition(event.clientX, event.clientY, 200, 200), change: rowChange }),
1359
+ onAction: () => void act(async () => G.api('git.unstage', { root, paths: [change.path] })),
1360
+ actionLabel: t('git.unstage'),
1361
+ actionIcon: 'minus',
1362
+ }),
1363
+ ),
1297
1364
  unstaged.length > 0 ? h('div', { className: 'gufa-hint' }, `${t('git.unstaged')} (${unstaged.length})`) : null,
1298
1365
  ...unstaged.map((change) =>
1299
1366
  h(G.GitChangeRow, {
@@ -1309,20 +1376,6 @@ G.GitPanel = function GitPanel(props) {
1309
1376
  actionIcon: 'plus',
1310
1377
  }),
1311
1378
  ),
1312
- staged.length > 0 ? h('div', { className: 'gufa-hint' }, `${t('git.staged')} (${staged.length})`) : null,
1313
- ...staged.map((change) =>
1314
- h(G.GitChangeRow, {
1315
- key: `s:${change.path}`,
1316
- change,
1317
- pending,
1318
- staged: true,
1319
- onOpen: () => props.onOpenDiff?.(change),
1320
- onContextMenu: (event, rowChange) => setRowMenu({ ...clampMenuPosition(event.clientX, event.clientY, 200, 200), change: rowChange }),
1321
- onAction: () => void act(async () => G.api('git.unstage', { root, paths: [change.path] })),
1322
- actionLabel: t('git.unstage'),
1323
- actionIcon: 'minus',
1324
- }),
1325
- ),
1326
1379
  ),
1327
1380
  ),
1328
1381
  headMenu === null
@@ -453,6 +453,25 @@ G.GufaApp = function GufaApp(props) {
453
453
  return map
454
454
  }, [gitStatus])
455
455
 
456
+ /* 暂存/取消暂存/提交后,已失效的 diff 标签自动关闭:
457
+ 工作树 diff 只在文件仍有未暂存改动时有效,暂存区 diff 只在文件仍在暂存区时有效。 */
458
+ useEffect(() => {
459
+ if (project === null || project.isGit !== true || gitStatus === null) return
460
+ const changes = Array.isArray(gitStatus.changes) ? gitStatus.changes : []
461
+ const stagedPaths = new Set(changes.filter((item) => item?.staged === true).map((item) => item.path))
462
+ const unstagedPaths = new Set(changes.filter((item) => item?.staged !== true).map((item) => item.path))
463
+ const current = tabsRef.current ?? []
464
+ const kept = current.filter((tab) => {
465
+ if (tab === null || tab === undefined || tab.kind !== 'diff') return true
466
+ if (tab.diff === null || tab.diff === undefined || tab.diff.compare === true) return true
467
+ if (tab.diff.staged === true) return stagedPaths.has(tab.path)
468
+ return unstagedPaths.has(tab.path)
469
+ })
470
+ if (kept.length === current.length) return
471
+ setTabs(kept)
472
+ setActivePath((active) => (active !== null && kept.some((tab) => tab.path === active) ? active : (kept.length > 0 ? kept[kept.length - 1].path : null)))
473
+ }, [gitStatus, project])
474
+
456
475
  /* ── 文件打开 / 保存 / 关闭 ─────────────────────────────────────────── */
457
476
  const openFile = useCallback(async (path) => {
458
477
  if (project === null) return
@@ -880,7 +899,13 @@ G.GufaApp = function GufaApp(props) {
880
899
  return
881
900
  }
882
901
  try {
883
- const file = await G.api('fs.read', { root: project.root, path: change.path })
902
+ /* 文件可能已删除(工作树删掉/暂存区删除):读不到就按空处理,仍然展示差异 */
903
+ let file = null
904
+ try {
905
+ file = await G.api('fs.read', { root: project.root, path: change.path })
906
+ } catch {
907
+ file = null
908
+ }
884
909
  let left = ''
885
910
  try {
886
911
  const shown = await G.api('git.show', {
@@ -892,16 +917,26 @@ G.GufaApp = function GufaApp(props) {
892
917
  } catch {
893
918
  left = ''
894
919
  }
920
+ let rightContent = typeof file?.content === 'string' ? file.content : ''
921
+ if (change.staged === true) {
922
+ /* 暂存区 diff = HEAD ↔ 索引;右侧必须用索引内容,而不是工作树(工作树可能还有未暂存改动) */
923
+ try {
924
+ const indexDoc = await G.api('git.show', { root: project.root, path: change.path, rev: 'index' })
925
+ rightContent = typeof indexDoc.text === 'string' ? indexDoc.text : ''
926
+ } catch {
927
+ rightContent = ''
928
+ }
929
+ }
895
930
  const tab = {
896
931
  path: change.path,
897
932
  title: `${G.basename(change.path)}(${change.staged === true ? '暂存区' : '工作树'})`,
898
933
  kind: 'diff',
899
- content: file.content ?? '',
900
- savedContent: file.content ?? '',
901
- revision: file.revision,
934
+ content: rightContent,
935
+ savedContent: rightContent,
936
+ revision: file?.revision,
902
937
  dirty: false,
903
- language: file.language ?? 'plaintext',
904
- size: file.size,
938
+ language: file?.language ?? 'plaintext',
939
+ size: file?.size,
905
940
  diff: { left, staged: change.staged === true, editable: change.staged !== true },
906
941
  diffKey: Date.now(),
907
942
  }
@@ -975,6 +1010,9 @@ G.GufaApp = function GufaApp(props) {
975
1010
  if (project === null) return
976
1011
  try {
977
1012
  await G.api('git.stage', { root: project.root, paths: [path] })
1013
+ /* 暂存后这个文件已经没有「工作树 vs 索引」差异:关掉当前 diff 标签,刷新后也不会再出现在未暂存区 */
1014
+ setTabs((current) => current.filter((tab) => !(tab.path === path && tab.kind === 'diff' && tab.diff !== null && tab.diff !== undefined && tab.diff.staged !== true)))
1015
+ setActivePath((active) => (active === path ? null : active))
978
1016
  setGitRefreshToken((token) => token + 1)
979
1017
  void refreshGit()
980
1018
  } catch (error) {