dsh-gufa-code 1.3.189 → 1.3.193

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.189'
19
+ G.BUILD = '1.3.193'
20
20
  G.PANEL_ID = 'gufa-code'
21
21
  /** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
22
22
  G.pendingEntryWorkspace = null
@@ -1707,6 +1707,8 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
1707
1707
  .gufa-tab:hover{background:var(--gufa-hover)}
1708
1708
  .gufa-tab[data-active]{background:var(--gufa-bg);color:var(--gufa-text);box-shadow:inset 0 2px 0 var(--gufa-accent)}
1709
1709
  .gufa-tab-name{overflow:hidden;text-overflow:ellipsis}
1710
+ /* VS Code 式「临时打开/预览」标签:斜体;双击/编辑后转正体 */
1711
+ .gufa-tab[data-preview] .gufa-tab-name{font-style:italic}
1710
1712
  .gufa-tab-dot{width:7px;height:7px;border-radius:50%;background:var(--gufa-accent);flex:0 0 auto}
1711
1713
  .gufa-tab-close{width:18px;height:18px;border:0;border-radius:4px;background:transparent;color:inherit;cursor:pointer;
1712
1714
  display:flex;align-items:center;justify-content:center;opacity:.65;flex:0 0 auto}
@@ -3366,6 +3368,22 @@ const GUFA_LINT_ENABLED = true
3366
3368
 
3367
3369
  /* ── 组件 ───────────────────────────────────────────────────────────── */
3368
3370
 
3371
+ /** 显式绑定 Cmd/Ctrl+Shift+L = 选中当前词在文件里的所有匹配项(VS Code/Cursor 习惯)。 */
3372
+ function gufaBindSelectAllOccurrences(monacoInstance, editor) {
3373
+ try {
3374
+ editor.addAction({
3375
+ id: 'gufa.selectAllOccurrences',
3376
+ label: '选中所有匹配项',
3377
+ keybindings: [monacoInstance.KeyMod.CtrlCmd | monacoInstance.KeyMod.Shift | monacoInstance.KeyCode.KeyL],
3378
+ run: (target) => {
3379
+ try { target.trigger('gufa-select-occurrences', 'editor.action.selectHighlights', null) } catch { /* ignore */ }
3380
+ },
3381
+ })
3382
+ } catch {
3383
+ /* ignore */
3384
+ }
3385
+ }
3386
+
3369
3387
  function GufaEditorPaneComponent(props) {
3370
3388
  const tabs = useMemo(() => (Array.isArray(props.tabs) ? props.tabs : []), [props.tabs])
3371
3389
  const activePath = typeof props.activePath === 'string' ? props.activePath : null
@@ -3614,6 +3632,7 @@ const GUFA_LINT_ENABLED = true
3614
3632
  const instance = monaco.editor.create(host, gufaEditorOptions(propsRef.current.theme))
3615
3633
  editor = instance
3616
3634
  editorRef.current = instance
3635
+ gufaBindSelectAllOccurrences(monaco, instance)
3617
3636
  try {
3618
3637
  try {
3619
3638
  G.__gufaEditorController = {
@@ -4542,6 +4561,7 @@ const GUFA_LINT_ENABLED = true
4542
4561
  scrollbar: { verticalScrollbarSize: 10, horizontalScrollbarSize: 10 },
4543
4562
  })
4544
4563
  instance.setModel({ original: originalModel, modified: modifiedModel })
4564
+ try { gufaBindSelectAllOccurrences(monaco, instance.getModifiedEditor()) } catch { /* ignore */ }
4545
4565
  } catch (error) {
4546
4566
  try {
4547
4567
  originalModel.dispose()
@@ -8277,7 +8297,10 @@ G.Explorer = function Explorer(props) {
8277
8297
  setMulti([])
8278
8298
  setSelected({ path: entry.path, kind: entry.kind })
8279
8299
  if (isDir) toggleDir(entry.path)
8280
- else props.onOpenFile?.(entry.path)
8300
+ else props.onOpenFile?.(entry.path, { preview: true })
8301
+ },
8302
+ onDoubleClick: () => {
8303
+ if (!isDir) props.onOpenFile?.(entry.path, { preview: false })
8281
8304
  },
8282
8305
  onContextMenu: (event) => openContextMenu(event, entry),
8283
8306
  },
@@ -8376,7 +8399,22 @@ G.Explorer = function Explorer(props) {
8376
8399
  : null,
8377
8400
  h(
8378
8401
  'div',
8379
- { className: 'gufa-panel-body gufa-scroll' },
8402
+ {
8403
+ className: 'gufa-panel-body gufa-scroll',
8404
+ onContextMenu: (event) => {
8405
+ try {
8406
+ if (event.target !== null && event.target !== undefined && typeof event.target.closest === 'function' && event.target.closest('.gufa-tree-row') !== null) return
8407
+ } catch {
8408
+ /* ignore */
8409
+ }
8410
+ if (!root) return
8411
+ event.preventDefault()
8412
+ event.stopPropagation()
8413
+ setMulti([])
8414
+ setSelected(null)
8415
+ setMenu({ x: event.clientX, y: event.clientY, path: '', kind: 'dir', entries: [], blank: true })
8416
+ },
8417
+ },
8380
8418
  menuError !== ''
8381
8419
  ? h('div', { className: 'gufa-error-banner' }, h(G.Icon, { name: 'warn', size: 13 }), h('span', { style: { flex: '1 1 auto' } }, menuError), h(G.IconButton, { title: t('common.close'), onClick: () => setMenuError('') }, h(G.Icon, { name: 'close', size: 11 })))
8382
8420
  : null,
@@ -8385,6 +8423,28 @@ G.Explorer = function Explorer(props) {
8385
8423
  menu === null
8386
8424
  ? null
8387
8425
  : (() => {
8426
+ if (menu.blank === true) {
8427
+ const closeBlank = (fn) => () => {
8428
+ setMenu(null)
8429
+ fn()
8430
+ }
8431
+ return G.portal(h(
8432
+ 'div',
8433
+ {
8434
+ className: 'gufa-menu',
8435
+ style: { left: menu.x, top: menu.y, position: 'fixed', minWidth: 180 },
8436
+ onMouseDown: (event) => event.stopPropagation(),
8437
+ },
8438
+ h(G.MenuItem, { icon: 'plus', label: t('explorer.newFile'), onClick: closeBlank(() => props.onNewFile?.('')) }),
8439
+ h(G.MenuItem, { icon: 'folder', label: t('explorer.newFolder'), onClick: closeBlank(() => props.onNewFolder?.('')) }),
8440
+ clipboard !== null
8441
+ ? h(G.MenuItem, { icon: 'folder-open', label: t('explorer.paste'), onClick: closeBlank(() => void pasteInto('')) })
8442
+ : null,
8443
+ h(G.MenuItem, { icon: 'refresh', label: t('explorer.refresh'), onClick: closeBlank(() => refreshAll()) }),
8444
+ h(G.MenuItem, { icon: 'files', label: '全部折叠', onClick: closeBlank(() => setExpanded({})) }),
8445
+ h(G.MenuItem, { icon: 'folder-open', label: t('explorer.revealInFinder'), onClick: closeBlank(() => revealPath('')) }),
8446
+ ))
8447
+ }
8388
8448
  const entries = Array.isArray(menu.entries) && menu.entries.length > 0 ? menu.entries : [{ path: menu.path, kind: menu.kind }]
8389
8449
  const files = entries.filter((item) => item.kind === 'file')
8390
8450
  const single = entries.length === 1
@@ -12931,6 +12991,7 @@ G.GufaApp = function GufaApp(props) {
12931
12991
  const gitInFlightRef = useRef(false)
12932
12992
  const gitFetchRef = useRef({ root: '', at: 0 })
12933
12993
  const [modal, setModal] = useState(null)
12994
+ const [tabMenu, setTabMenu] = useState(null)
12934
12995
  const [shortcutsOpen, setShortcutsOpen] = useState(false)
12935
12996
  const [definitionPicker, setDefinitionPicker] = useState(null)
12936
12997
  const [trashUndo, setTrashUndo] = useState([])
@@ -13159,36 +13220,71 @@ G.GufaApp = function GufaApp(props) {
13159
13220
  }, [gitStatus, project])
13160
13221
 
13161
13222
  /* ── 文件打开 / 保存 / 关闭 ─────────────────────────────────────────── */
13162
- const openFile = useCallback(async (rawPath) => {
13223
+ /**
13224
+ * 打开文件。preview=true 为「临时打开」(VS Code 预览标签,斜体):
13225
+ * 单点文件树只产生一个预览标签,再点其他文件会原地替换它;
13226
+ * 双击文件/标签或编辑内容后由调用方/changeFile 固定成普通标签。
13227
+ */
13228
+ const openFile = useCallback(async (rawPath, options) => {
13163
13229
  if (project === null) return
13164
13230
  const path = gufaNormalizeProjectPath(rawPath)
13165
13231
  if (path === '') return
13232
+ const preview = options !== null && options !== undefined && options.preview === true
13166
13233
  flushBuffersRef.current?.()
13167
13234
  const existing = tabs.find((tab) => gufaNormalizeProjectPath(tab.path) === path)
13168
13235
  if (existing !== undefined) {
13236
+ if (preview !== true && existing.preview === true) {
13237
+ setTabs((current) => current.map((tab) => (tab.path === existing.path ? { ...tab, preview: false } : tab)))
13238
+ }
13169
13239
  /* 已经打开的文件再次点击:先对齐磁盘最新版本(AI/外部修改后不用关掉重开) */
13170
13240
  try {
13171
- await reloadTabFromDiskRef.current?.(path)
13241
+ await reloadTabFromDiskRef.current?.(existing.path)
13172
13242
  } catch {
13173
13243
  /* ignore */
13174
13244
  }
13175
- setActivePath(path)
13245
+ setActivePath(existing.path)
13176
13246
  return
13177
13247
  }
13178
13248
  try {
13179
13249
  const doc = await G.api('fs.read', { root: project.root, path })
13180
- /* 用函数式更新去重:并发/恢复场景下闭包里的 tabs 可能还没刷新,直接追加会产生重复标签 */
13181
- setTabs((current) => (
13182
- current.some((tab) => gufaNormalizeProjectPath(tab.path) === gufaNormalizeProjectPath(doc.path ?? path))
13183
- ? current
13184
- : [...current, { ...doc, savedContent: doc.content, dirty: false, savedRevision: doc.revision }]
13185
- ))
13186
- setActivePath(path)
13250
+ const nextTab = { ...doc, savedContent: doc.content, dirty: false, savedRevision: doc.revision }
13251
+ if (preview === true) {
13252
+ /* 预览标签全局只有一个:找到干净的那个原地替换,不新增标签 */
13253
+ const previewTab = tabs.find((tab) => tab.preview === true && tab.dirty !== true && tab.kind !== 'diff')
13254
+ if (previewTab !== undefined) {
13255
+ editorBuffersRef.current.delete(previewTab.path)
13256
+ const replacedPath = gufaNormalizeProjectPath(doc.path ?? path)
13257
+ setTabs((current) => current.map((tab) => (
13258
+ tab.path === previewTab.path ? { ...nextTab, preview: true } : tab
13259
+ )))
13260
+ setActivePath(replacedPath)
13261
+ return
13262
+ }
13263
+ setTabs((current) => (
13264
+ current.some((tab) => gufaNormalizeProjectPath(tab.path) === gufaNormalizeProjectPath(doc.path ?? path))
13265
+ ? current
13266
+ : [...current, { ...nextTab, preview: true }]
13267
+ ))
13268
+ } else {
13269
+ /* 用函数式更新去重:并发/恢复场景下闭包里的 tabs 可能还没刷新,直接追加会产生重复标签 */
13270
+ setTabs((current) => (
13271
+ current.some((tab) => gufaNormalizeProjectPath(tab.path) === gufaNormalizeProjectPath(doc.path ?? path))
13272
+ ? current
13273
+ : [...current, nextTab]
13274
+ ))
13275
+ }
13276
+ setActivePath(gufaNormalizeProjectPath(doc.path ?? path))
13187
13277
  } catch (error) {
13188
13278
  setBanner(G.errorText(error))
13189
13279
  }
13190
13280
  }, [project, tabs])
13191
13281
 
13282
+ /** 双击标签/文件:把预览标签固定成普通标签。 */
13283
+ const pinTab = useCallback((rawPath) => {
13284
+ const path = gufaNormalizeProjectPath(rawPath)
13285
+ setTabs((current) => current.map((tab) => (tab.path === path && tab.preview === true ? { ...tab, preview: false } : tab)))
13286
+ }, [])
13287
+
13192
13288
  /* 从搜索/定位结果打开文件并跳到指定行列(等 tab 切换完成后再触发编辑器 reveal) */
13193
13289
  const openFileAt = useCallback(async (rawPath, line, column) => {
13194
13290
  if (typeof rawPath !== 'string' || rawPath === '') return
@@ -13347,9 +13443,10 @@ G.GufaApp = function GufaApp(props) {
13347
13443
  if (tab === null || !buffers.has(tab.path)) return tab
13348
13444
  const content = buffers.get(tab.path)
13349
13445
  const dirty = content !== tab.savedContent
13350
- if (tab.content === content && tab.dirty === dirty) return tab
13446
+ const preview = dirty ? false : tab.preview
13447
+ if (tab.content === content && tab.dirty === dirty && tab.preview === preview) return tab
13351
13448
  changed = true
13352
- return { ...tab, content, dirty }
13449
+ return { ...tab, content, dirty, preview }
13353
13450
  })
13354
13451
  if (!changed) return current
13355
13452
  tabsRef.current = next
@@ -13379,9 +13476,10 @@ G.GufaApp = function GufaApp(props) {
13379
13476
  /* 用缓冲里的最新内容而不是本次按键的内容:避免 React 批处理时把「第一次按键」的旧内容回灌给编辑器。 */
13380
13477
  const latest = editorBuffersRef.current.has(path) ? editorBuffersRef.current.get(path) : content
13381
13478
  const dirty = latest !== item.savedContent
13382
- if (item.dirty === dirty) return item
13479
+ const preview = dirty ? false : item.preview
13480
+ if (item.dirty === dirty && item.preview === preview) return item
13383
13481
  changed = true
13384
- return { ...item, content: latest, dirty }
13482
+ return { ...item, content: latest, dirty, preview }
13385
13483
  })
13386
13484
  if (!changed) return current
13387
13485
  tabsRef.current = next
@@ -13494,6 +13592,37 @@ G.GufaApp = function GufaApp(props) {
13494
13592
  closeTab(path)
13495
13593
  }, [tabs, closeTab])
13496
13594
 
13595
+ /** 关闭当前标签外的其他标签;有未保存改动时先确认。 */
13596
+ const closeOtherTabs = useCallback((path) => {
13597
+ const others = tabs.filter((tab) => tab.path !== path)
13598
+ if (others.length === 0) return
13599
+ if (others.some((tab) => tab.dirty === true) && window.confirm('有未保存的改动,仍要关闭其他标签页吗?') !== true) return
13600
+ for (const tab of others) editorBuffersRef.current.delete(tab.path)
13601
+ setTabs((current) => current.filter((tab) => tab.path === path))
13602
+ setActivePath(path)
13603
+ }, [tabs])
13604
+
13605
+ /** 关闭全部标签;有未保存改动时先确认。 */
13606
+ const closeAllTabs = useCallback(() => {
13607
+ if (tabs.length === 0) return
13608
+ if (tabs.some((tab) => tab.dirty === true) && window.confirm('有未保存的改动,仍要关闭全部标签页吗?') !== true) return
13609
+ editorBuffersRef.current.clear()
13610
+ setTabs([])
13611
+ setActivePath(null)
13612
+ }, [tabs])
13613
+
13614
+ /** 标签右键菜单用:绝对路径 / 相对路径复制。 */
13615
+ const tabAbsolutePath = useCallback((path) => {
13616
+ const root = project !== null && typeof project.root === 'string' ? project.root.replace(/[\\/]+$/, '') : ''
13617
+ if (root === '') return path
13618
+ const sep = root.includes('\\') ? '\\' : '/'
13619
+ return `${root}${sep}${String(path).split('/').join(sep)}`
13620
+ }, [project])
13621
+
13622
+ const copyText = useCallback((text) => {
13623
+ try { void navigator.clipboard?.writeText(String(text)) } catch { /* ignore */ }
13624
+ }, [])
13625
+
13497
13626
  /* ── Git Graph(提交图标签页) ─────────────────────────────────────── */
13498
13627
  const openGitGraph = useCallback(() => {
13499
13628
  if (project === null) return
@@ -15043,6 +15172,17 @@ G.GufaApp = function GufaApp(props) {
15043
15172
  return () => window.removeEventListener('keydown', onKey, true)
15044
15173
  }, [shortcutsOpen])
15045
15174
 
15175
+ useEffect(() => {
15176
+ if (tabMenu === null) return undefined
15177
+ const close = () => setTabMenu(null)
15178
+ window.addEventListener('mousedown', close)
15179
+ window.addEventListener('blur', close)
15180
+ return () => {
15181
+ window.removeEventListener('mousedown', close)
15182
+ window.removeEventListener('blur', close)
15183
+ }
15184
+ }, [tabMenu])
15185
+
15046
15186
  /* ── 渲染 ─────────────────────────────────────────────────────────── */
15047
15187
  const activityItems = [
15048
15188
  { id: 'explorer', icon: 'files', label: t('activity.explorer'), onClick: () => patchUi({ view: 'explorer', sidebarOpen: true }) },
@@ -15061,7 +15201,7 @@ G.GufaApp = function GufaApp(props) {
15061
15201
  activePath,
15062
15202
  refreshToken,
15063
15203
  gitStatuses,
15064
- onOpenFile: (path) => void openFile(path),
15204
+ onOpenFile: (path, options) => void openFile(path, options),
15065
15205
  onChanged: () => {
15066
15206
  setRefreshToken((token) => token + 1)
15067
15207
  setGitRefreshToken((token) => token + 1)
@@ -15112,7 +15252,14 @@ G.GufaApp = function GufaApp(props) {
15112
15252
  role: 'tab',
15113
15253
  tabIndex: 0,
15114
15254
  title: tab.title !== undefined && tab.title !== null ? tab.title : tab.path,
15255
+ 'data-preview': tab.preview === true ? '' : undefined,
15115
15256
  onClick: () => handleSelectTab(tab.path),
15257
+ onDoubleClick: () => pinTab(tab.path),
15258
+ onContextMenu: (event) => {
15259
+ event.preventDefault()
15260
+ event.stopPropagation()
15261
+ setTabMenu({ x: event.clientX, y: event.clientY, path: tab.path })
15262
+ },
15116
15263
  onAuxClick: (event) => { if (event.button === 1) closeTabWithConfirm(tab.path) },
15117
15264
  },
15118
15265
  h(G.Icon, { name: 'file', size: 13 }),
@@ -15657,6 +15804,25 @@ G.GufaApp = function GufaApp(props) {
15657
15804
  ),
15658
15805
  ),
15659
15806
  ),
15807
+ /* 标签页右键菜单 */
15808
+ tabMenu === null
15809
+ ? null
15810
+ : G.portal(h(
15811
+ 'div',
15812
+ {
15813
+ className: 'gufa-menu',
15814
+ style: { left: tabMenu.x, top: tabMenu.y, position: 'fixed', minWidth: 190, zIndex: 2147483050 },
15815
+ onMouseDown: (event) => event.stopPropagation(),
15816
+ },
15817
+ h(G.MenuItem, { icon: 'close', label: t('editor.close'), onClick: () => { setTabMenu(null); closeTabWithConfirm(tabMenu.path) } }),
15818
+ h(G.MenuItem, { icon: 'files', label: '关闭其他', onClick: () => { setTabMenu(null); closeOtherTabs(tabMenu.path) } }),
15819
+ h(G.MenuItem, { icon: 'trash', label: '关闭全部', onClick: () => { setTabMenu(null); closeAllTabs() } }),
15820
+ h(G.MenuItem, { icon: 'file', label: '复制路径', onClick: () => { setTabMenu(null); copyText(tabAbsolutePath(tabMenu.path)) } }),
15821
+ h(G.MenuItem, { icon: 'code', label: '复制相对路径', onClick: () => { setTabMenu(null); copyText(tabMenu.path) } }),
15822
+ tabMenu.path === activePath && activeTab !== null && activeTab.preview === true
15823
+ ? h(G.MenuItem, { icon: 'check', label: '固定为常驻标签', onClick: () => { setTabMenu(null); pinTab(tabMenu.path) } })
15824
+ : null,
15825
+ )),
15660
15826
  /* 弹窗 */
15661
15827
  G.portal(modal === null ? null : renderModal()),
15662
15828
  G.portal(floatPicker !== null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.189",
3
+ "version": "1.3.193",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -1699,6 +1699,8 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
1699
1699
  .gufa-tab:hover{background:var(--gufa-hover)}
1700
1700
  .gufa-tab[data-active]{background:var(--gufa-bg);color:var(--gufa-text);box-shadow:inset 0 2px 0 var(--gufa-accent)}
1701
1701
  .gufa-tab-name{overflow:hidden;text-overflow:ellipsis}
1702
+ /* VS Code 式「临时打开/预览」标签:斜体;双击/编辑后转正体 */
1703
+ .gufa-tab[data-preview] .gufa-tab-name{font-style:italic}
1702
1704
  .gufa-tab-dot{width:7px;height:7px;border-radius:50%;background:var(--gufa-accent);flex:0 0 auto}
1703
1705
  .gufa-tab-close{width:18px;height:18px;border:0;border-radius:4px;background:transparent;color:inherit;cursor:pointer;
1704
1706
  display:flex;align-items:center;justify-content:center;opacity:.65;flex:0 0 auto}
@@ -714,6 +714,22 @@ const GUFA_LINT_ENABLED = true
714
714
 
715
715
  /* ── 组件 ───────────────────────────────────────────────────────────── */
716
716
 
717
+ /** 显式绑定 Cmd/Ctrl+Shift+L = 选中当前词在文件里的所有匹配项(VS Code/Cursor 习惯)。 */
718
+ function gufaBindSelectAllOccurrences(monacoInstance, editor) {
719
+ try {
720
+ editor.addAction({
721
+ id: 'gufa.selectAllOccurrences',
722
+ label: '选中所有匹配项',
723
+ keybindings: [monacoInstance.KeyMod.CtrlCmd | monacoInstance.KeyMod.Shift | monacoInstance.KeyCode.KeyL],
724
+ run: (target) => {
725
+ try { target.trigger('gufa-select-occurrences', 'editor.action.selectHighlights', null) } catch { /* ignore */ }
726
+ },
727
+ })
728
+ } catch {
729
+ /* ignore */
730
+ }
731
+ }
732
+
717
733
  function GufaEditorPaneComponent(props) {
718
734
  const tabs = useMemo(() => (Array.isArray(props.tabs) ? props.tabs : []), [props.tabs])
719
735
  const activePath = typeof props.activePath === 'string' ? props.activePath : null
@@ -962,6 +978,7 @@ const GUFA_LINT_ENABLED = true
962
978
  const instance = monaco.editor.create(host, gufaEditorOptions(propsRef.current.theme))
963
979
  editor = instance
964
980
  editorRef.current = instance
981
+ gufaBindSelectAllOccurrences(monaco, instance)
965
982
  try {
966
983
  try {
967
984
  G.__gufaEditorController = {
@@ -1890,6 +1907,7 @@ const GUFA_LINT_ENABLED = true
1890
1907
  scrollbar: { verticalScrollbarSize: 10, horizontalScrollbarSize: 10 },
1891
1908
  })
1892
1909
  instance.setModel({ original: originalModel, modified: modifiedModel })
1910
+ try { gufaBindSelectAllOccurrences(monaco, instance.getModifiedEditor()) } catch { /* ignore */ }
1893
1911
  } catch (error) {
1894
1912
  try {
1895
1913
  originalModel.dispose()
@@ -323,7 +323,10 @@ G.Explorer = function Explorer(props) {
323
323
  setMulti([])
324
324
  setSelected({ path: entry.path, kind: entry.kind })
325
325
  if (isDir) toggleDir(entry.path)
326
- else props.onOpenFile?.(entry.path)
326
+ else props.onOpenFile?.(entry.path, { preview: true })
327
+ },
328
+ onDoubleClick: () => {
329
+ if (!isDir) props.onOpenFile?.(entry.path, { preview: false })
327
330
  },
328
331
  onContextMenu: (event) => openContextMenu(event, entry),
329
332
  },
@@ -422,7 +425,22 @@ G.Explorer = function Explorer(props) {
422
425
  : null,
423
426
  h(
424
427
  'div',
425
- { className: 'gufa-panel-body gufa-scroll' },
428
+ {
429
+ className: 'gufa-panel-body gufa-scroll',
430
+ onContextMenu: (event) => {
431
+ try {
432
+ if (event.target !== null && event.target !== undefined && typeof event.target.closest === 'function' && event.target.closest('.gufa-tree-row') !== null) return
433
+ } catch {
434
+ /* ignore */
435
+ }
436
+ if (!root) return
437
+ event.preventDefault()
438
+ event.stopPropagation()
439
+ setMulti([])
440
+ setSelected(null)
441
+ setMenu({ x: event.clientX, y: event.clientY, path: '', kind: 'dir', entries: [], blank: true })
442
+ },
443
+ },
426
444
  menuError !== ''
427
445
  ? h('div', { className: 'gufa-error-banner' }, h(G.Icon, { name: 'warn', size: 13 }), h('span', { style: { flex: '1 1 auto' } }, menuError), h(G.IconButton, { title: t('common.close'), onClick: () => setMenuError('') }, h(G.Icon, { name: 'close', size: 11 })))
428
446
  : null,
@@ -431,6 +449,28 @@ G.Explorer = function Explorer(props) {
431
449
  menu === null
432
450
  ? null
433
451
  : (() => {
452
+ if (menu.blank === true) {
453
+ const closeBlank = (fn) => () => {
454
+ setMenu(null)
455
+ fn()
456
+ }
457
+ return G.portal(h(
458
+ 'div',
459
+ {
460
+ className: 'gufa-menu',
461
+ style: { left: menu.x, top: menu.y, position: 'fixed', minWidth: 180 },
462
+ onMouseDown: (event) => event.stopPropagation(),
463
+ },
464
+ h(G.MenuItem, { icon: 'plus', label: t('explorer.newFile'), onClick: closeBlank(() => props.onNewFile?.('')) }),
465
+ 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,
469
+ h(G.MenuItem, { icon: 'refresh', label: t('explorer.refresh'), onClick: closeBlank(() => refreshAll()) }),
470
+ h(G.MenuItem, { icon: 'files', label: '全部折叠', onClick: closeBlank(() => setExpanded({})) }),
471
+ h(G.MenuItem, { icon: 'folder-open', label: t('explorer.revealInFinder'), onClick: closeBlank(() => revealPath('')) }),
472
+ ))
473
+ }
434
474
  const entries = Array.isArray(menu.entries) && menu.entries.length > 0 ? menu.entries : [{ path: menu.path, kind: menu.kind }]
435
475
  const files = entries.filter((item) => item.kind === 'file')
436
476
  const single = entries.length === 1
@@ -368,6 +368,7 @@ G.GufaApp = function GufaApp(props) {
368
368
  const gitInFlightRef = useRef(false)
369
369
  const gitFetchRef = useRef({ root: '', at: 0 })
370
370
  const [modal, setModal] = useState(null)
371
+ const [tabMenu, setTabMenu] = useState(null)
371
372
  const [shortcutsOpen, setShortcutsOpen] = useState(false)
372
373
  const [definitionPicker, setDefinitionPicker] = useState(null)
373
374
  const [trashUndo, setTrashUndo] = useState([])
@@ -596,36 +597,71 @@ G.GufaApp = function GufaApp(props) {
596
597
  }, [gitStatus, project])
597
598
 
598
599
  /* ── 文件打开 / 保存 / 关闭 ─────────────────────────────────────────── */
599
- const openFile = useCallback(async (rawPath) => {
600
+ /**
601
+ * 打开文件。preview=true 为「临时打开」(VS Code 预览标签,斜体):
602
+ * 单点文件树只产生一个预览标签,再点其他文件会原地替换它;
603
+ * 双击文件/标签或编辑内容后由调用方/changeFile 固定成普通标签。
604
+ */
605
+ const openFile = useCallback(async (rawPath, options) => {
600
606
  if (project === null) return
601
607
  const path = gufaNormalizeProjectPath(rawPath)
602
608
  if (path === '') return
609
+ const preview = options !== null && options !== undefined && options.preview === true
603
610
  flushBuffersRef.current?.()
604
611
  const existing = tabs.find((tab) => gufaNormalizeProjectPath(tab.path) === path)
605
612
  if (existing !== undefined) {
613
+ if (preview !== true && existing.preview === true) {
614
+ setTabs((current) => current.map((tab) => (tab.path === existing.path ? { ...tab, preview: false } : tab)))
615
+ }
606
616
  /* 已经打开的文件再次点击:先对齐磁盘最新版本(AI/外部修改后不用关掉重开) */
607
617
  try {
608
- await reloadTabFromDiskRef.current?.(path)
618
+ await reloadTabFromDiskRef.current?.(existing.path)
609
619
  } catch {
610
620
  /* ignore */
611
621
  }
612
- setActivePath(path)
622
+ setActivePath(existing.path)
613
623
  return
614
624
  }
615
625
  try {
616
626
  const doc = await G.api('fs.read', { root: project.root, path })
617
- /* 用函数式更新去重:并发/恢复场景下闭包里的 tabs 可能还没刷新,直接追加会产生重复标签 */
618
- setTabs((current) => (
619
- current.some((tab) => gufaNormalizeProjectPath(tab.path) === gufaNormalizeProjectPath(doc.path ?? path))
620
- ? current
621
- : [...current, { ...doc, savedContent: doc.content, dirty: false, savedRevision: doc.revision }]
622
- ))
623
- setActivePath(path)
627
+ const nextTab = { ...doc, savedContent: doc.content, dirty: false, savedRevision: doc.revision }
628
+ if (preview === true) {
629
+ /* 预览标签全局只有一个:找到干净的那个原地替换,不新增标签 */
630
+ const previewTab = tabs.find((tab) => tab.preview === true && tab.dirty !== true && tab.kind !== 'diff')
631
+ if (previewTab !== undefined) {
632
+ editorBuffersRef.current.delete(previewTab.path)
633
+ const replacedPath = gufaNormalizeProjectPath(doc.path ?? path)
634
+ setTabs((current) => current.map((tab) => (
635
+ tab.path === previewTab.path ? { ...nextTab, preview: true } : tab
636
+ )))
637
+ setActivePath(replacedPath)
638
+ return
639
+ }
640
+ setTabs((current) => (
641
+ current.some((tab) => gufaNormalizeProjectPath(tab.path) === gufaNormalizeProjectPath(doc.path ?? path))
642
+ ? current
643
+ : [...current, { ...nextTab, preview: true }]
644
+ ))
645
+ } else {
646
+ /* 用函数式更新去重:并发/恢复场景下闭包里的 tabs 可能还没刷新,直接追加会产生重复标签 */
647
+ setTabs((current) => (
648
+ current.some((tab) => gufaNormalizeProjectPath(tab.path) === gufaNormalizeProjectPath(doc.path ?? path))
649
+ ? current
650
+ : [...current, nextTab]
651
+ ))
652
+ }
653
+ setActivePath(gufaNormalizeProjectPath(doc.path ?? path))
624
654
  } catch (error) {
625
655
  setBanner(G.errorText(error))
626
656
  }
627
657
  }, [project, tabs])
628
658
 
659
+ /** 双击标签/文件:把预览标签固定成普通标签。 */
660
+ const pinTab = useCallback((rawPath) => {
661
+ const path = gufaNormalizeProjectPath(rawPath)
662
+ setTabs((current) => current.map((tab) => (tab.path === path && tab.preview === true ? { ...tab, preview: false } : tab)))
663
+ }, [])
664
+
629
665
  /* 从搜索/定位结果打开文件并跳到指定行列(等 tab 切换完成后再触发编辑器 reveal) */
630
666
  const openFileAt = useCallback(async (rawPath, line, column) => {
631
667
  if (typeof rawPath !== 'string' || rawPath === '') return
@@ -784,9 +820,10 @@ G.GufaApp = function GufaApp(props) {
784
820
  if (tab === null || !buffers.has(tab.path)) return tab
785
821
  const content = buffers.get(tab.path)
786
822
  const dirty = content !== tab.savedContent
787
- if (tab.content === content && tab.dirty === dirty) return tab
823
+ const preview = dirty ? false : tab.preview
824
+ if (tab.content === content && tab.dirty === dirty && tab.preview === preview) return tab
788
825
  changed = true
789
- return { ...tab, content, dirty }
826
+ return { ...tab, content, dirty, preview }
790
827
  })
791
828
  if (!changed) return current
792
829
  tabsRef.current = next
@@ -816,9 +853,10 @@ G.GufaApp = function GufaApp(props) {
816
853
  /* 用缓冲里的最新内容而不是本次按键的内容:避免 React 批处理时把「第一次按键」的旧内容回灌给编辑器。 */
817
854
  const latest = editorBuffersRef.current.has(path) ? editorBuffersRef.current.get(path) : content
818
855
  const dirty = latest !== item.savedContent
819
- if (item.dirty === dirty) return item
856
+ const preview = dirty ? false : item.preview
857
+ if (item.dirty === dirty && item.preview === preview) return item
820
858
  changed = true
821
- return { ...item, content: latest, dirty }
859
+ return { ...item, content: latest, dirty, preview }
822
860
  })
823
861
  if (!changed) return current
824
862
  tabsRef.current = next
@@ -931,6 +969,37 @@ G.GufaApp = function GufaApp(props) {
931
969
  closeTab(path)
932
970
  }, [tabs, closeTab])
933
971
 
972
+ /** 关闭当前标签外的其他标签;有未保存改动时先确认。 */
973
+ const closeOtherTabs = useCallback((path) => {
974
+ const others = tabs.filter((tab) => tab.path !== path)
975
+ if (others.length === 0) return
976
+ if (others.some((tab) => tab.dirty === true) && window.confirm('有未保存的改动,仍要关闭其他标签页吗?') !== true) return
977
+ for (const tab of others) editorBuffersRef.current.delete(tab.path)
978
+ setTabs((current) => current.filter((tab) => tab.path === path))
979
+ setActivePath(path)
980
+ }, [tabs])
981
+
982
+ /** 关闭全部标签;有未保存改动时先确认。 */
983
+ const closeAllTabs = useCallback(() => {
984
+ if (tabs.length === 0) return
985
+ if (tabs.some((tab) => tab.dirty === true) && window.confirm('有未保存的改动,仍要关闭全部标签页吗?') !== true) return
986
+ editorBuffersRef.current.clear()
987
+ setTabs([])
988
+ setActivePath(null)
989
+ }, [tabs])
990
+
991
+ /** 标签右键菜单用:绝对路径 / 相对路径复制。 */
992
+ const tabAbsolutePath = useCallback((path) => {
993
+ const root = project !== null && typeof project.root === 'string' ? project.root.replace(/[\\/]+$/, '') : ''
994
+ if (root === '') return path
995
+ const sep = root.includes('\\') ? '\\' : '/'
996
+ return `${root}${sep}${String(path).split('/').join(sep)}`
997
+ }, [project])
998
+
999
+ const copyText = useCallback((text) => {
1000
+ try { void navigator.clipboard?.writeText(String(text)) } catch { /* ignore */ }
1001
+ }, [])
1002
+
934
1003
  /* ── Git Graph(提交图标签页) ─────────────────────────────────────── */
935
1004
  const openGitGraph = useCallback(() => {
936
1005
  if (project === null) return
@@ -2480,6 +2549,17 @@ G.GufaApp = function GufaApp(props) {
2480
2549
  return () => window.removeEventListener('keydown', onKey, true)
2481
2550
  }, [shortcutsOpen])
2482
2551
 
2552
+ useEffect(() => {
2553
+ if (tabMenu === null) return undefined
2554
+ const close = () => setTabMenu(null)
2555
+ window.addEventListener('mousedown', close)
2556
+ window.addEventListener('blur', close)
2557
+ return () => {
2558
+ window.removeEventListener('mousedown', close)
2559
+ window.removeEventListener('blur', close)
2560
+ }
2561
+ }, [tabMenu])
2562
+
2483
2563
  /* ── 渲染 ─────────────────────────────────────────────────────────── */
2484
2564
  const activityItems = [
2485
2565
  { id: 'explorer', icon: 'files', label: t('activity.explorer'), onClick: () => patchUi({ view: 'explorer', sidebarOpen: true }) },
@@ -2498,7 +2578,7 @@ G.GufaApp = function GufaApp(props) {
2498
2578
  activePath,
2499
2579
  refreshToken,
2500
2580
  gitStatuses,
2501
- onOpenFile: (path) => void openFile(path),
2581
+ onOpenFile: (path, options) => void openFile(path, options),
2502
2582
  onChanged: () => {
2503
2583
  setRefreshToken((token) => token + 1)
2504
2584
  setGitRefreshToken((token) => token + 1)
@@ -2549,7 +2629,14 @@ G.GufaApp = function GufaApp(props) {
2549
2629
  role: 'tab',
2550
2630
  tabIndex: 0,
2551
2631
  title: tab.title !== undefined && tab.title !== null ? tab.title : tab.path,
2632
+ 'data-preview': tab.preview === true ? '' : undefined,
2552
2633
  onClick: () => handleSelectTab(tab.path),
2634
+ onDoubleClick: () => pinTab(tab.path),
2635
+ onContextMenu: (event) => {
2636
+ event.preventDefault()
2637
+ event.stopPropagation()
2638
+ setTabMenu({ x: event.clientX, y: event.clientY, path: tab.path })
2639
+ },
2553
2640
  onAuxClick: (event) => { if (event.button === 1) closeTabWithConfirm(tab.path) },
2554
2641
  },
2555
2642
  h(G.Icon, { name: 'file', size: 13 }),
@@ -3094,6 +3181,25 @@ G.GufaApp = function GufaApp(props) {
3094
3181
  ),
3095
3182
  ),
3096
3183
  ),
3184
+ /* 标签页右键菜单 */
3185
+ tabMenu === null
3186
+ ? null
3187
+ : G.portal(h(
3188
+ 'div',
3189
+ {
3190
+ className: 'gufa-menu',
3191
+ style: { left: tabMenu.x, top: tabMenu.y, position: 'fixed', minWidth: 190, zIndex: 2147483050 },
3192
+ onMouseDown: (event) => event.stopPropagation(),
3193
+ },
3194
+ h(G.MenuItem, { icon: 'close', label: t('editor.close'), onClick: () => { setTabMenu(null); closeTabWithConfirm(tabMenu.path) } }),
3195
+ h(G.MenuItem, { icon: 'files', label: '关闭其他', onClick: () => { setTabMenu(null); closeOtherTabs(tabMenu.path) } }),
3196
+ h(G.MenuItem, { icon: 'trash', label: '关闭全部', onClick: () => { setTabMenu(null); closeAllTabs() } }),
3197
+ h(G.MenuItem, { icon: 'file', label: '复制路径', onClick: () => { setTabMenu(null); copyText(tabAbsolutePath(tabMenu.path)) } }),
3198
+ h(G.MenuItem, { icon: 'code', label: '复制相对路径', onClick: () => { setTabMenu(null); copyText(tabMenu.path) } }),
3199
+ tabMenu.path === activePath && activeTab !== null && activeTab.preview === true
3200
+ ? h(G.MenuItem, { icon: 'check', label: '固定为常驻标签', onClick: () => { setTabMenu(null); pinTab(tabMenu.path) } })
3201
+ : null,
3202
+ )),
3097
3203
  /* 弹窗 */
3098
3204
  G.portal(modal === null ? null : renderModal()),
3099
3205
  G.portal(floatPicker !== null