dsh-gufa-code 1.3.189 → 1.3.192
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 +166 -18
- package/package.json +1 -1
- package/src/client/00-core.js +2 -0
- package/src/client/50-panels.js +42 -2
- package/src/client/90-app.js +121 -15
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.
|
|
19
|
+
G.BUILD = '1.3.192'
|
|
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}
|
|
@@ -8277,7 +8279,10 @@ G.Explorer = function Explorer(props) {
|
|
|
8277
8279
|
setMulti([])
|
|
8278
8280
|
setSelected({ path: entry.path, kind: entry.kind })
|
|
8279
8281
|
if (isDir) toggleDir(entry.path)
|
|
8280
|
-
else props.onOpenFile?.(entry.path)
|
|
8282
|
+
else props.onOpenFile?.(entry.path, { preview: true })
|
|
8283
|
+
},
|
|
8284
|
+
onDoubleClick: () => {
|
|
8285
|
+
if (!isDir) props.onOpenFile?.(entry.path, { preview: false })
|
|
8281
8286
|
},
|
|
8282
8287
|
onContextMenu: (event) => openContextMenu(event, entry),
|
|
8283
8288
|
},
|
|
@@ -8376,7 +8381,22 @@ G.Explorer = function Explorer(props) {
|
|
|
8376
8381
|
: null,
|
|
8377
8382
|
h(
|
|
8378
8383
|
'div',
|
|
8379
|
-
{
|
|
8384
|
+
{
|
|
8385
|
+
className: 'gufa-panel-body gufa-scroll',
|
|
8386
|
+
onContextMenu: (event) => {
|
|
8387
|
+
try {
|
|
8388
|
+
if (event.target !== null && event.target !== undefined && typeof event.target.closest === 'function' && event.target.closest('.gufa-tree-row') !== null) return
|
|
8389
|
+
} catch {
|
|
8390
|
+
/* ignore */
|
|
8391
|
+
}
|
|
8392
|
+
if (!root) return
|
|
8393
|
+
event.preventDefault()
|
|
8394
|
+
event.stopPropagation()
|
|
8395
|
+
setMulti([])
|
|
8396
|
+
setSelected(null)
|
|
8397
|
+
setMenu({ x: event.clientX, y: event.clientY, path: '', kind: 'dir', entries: [], blank: true })
|
|
8398
|
+
},
|
|
8399
|
+
},
|
|
8380
8400
|
menuError !== ''
|
|
8381
8401
|
? 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
8402
|
: null,
|
|
@@ -8385,6 +8405,28 @@ G.Explorer = function Explorer(props) {
|
|
|
8385
8405
|
menu === null
|
|
8386
8406
|
? null
|
|
8387
8407
|
: (() => {
|
|
8408
|
+
if (menu.blank === true) {
|
|
8409
|
+
const closeBlank = (fn) => () => {
|
|
8410
|
+
setMenu(null)
|
|
8411
|
+
fn()
|
|
8412
|
+
}
|
|
8413
|
+
return G.portal(h(
|
|
8414
|
+
'div',
|
|
8415
|
+
{
|
|
8416
|
+
className: 'gufa-menu',
|
|
8417
|
+
style: { left: menu.x, top: menu.y, position: 'fixed', minWidth: 180 },
|
|
8418
|
+
onMouseDown: (event) => event.stopPropagation(),
|
|
8419
|
+
},
|
|
8420
|
+
h(G.MenuItem, { icon: 'plus', label: t('explorer.newFile'), onClick: closeBlank(() => props.onNewFile?.('')) }),
|
|
8421
|
+
h(G.MenuItem, { icon: 'folder', label: t('explorer.newFolder'), onClick: closeBlank(() => props.onNewFolder?.('')) }),
|
|
8422
|
+
clipboard !== null
|
|
8423
|
+
? h(G.MenuItem, { icon: 'folder-open', label: t('explorer.paste'), onClick: closeBlank(() => void pasteInto('')) })
|
|
8424
|
+
: null,
|
|
8425
|
+
h(G.MenuItem, { icon: 'refresh', label: t('explorer.refresh'), onClick: closeBlank(() => refreshAll()) }),
|
|
8426
|
+
h(G.MenuItem, { icon: 'files', label: '全部折叠', onClick: closeBlank(() => setExpanded({})) }),
|
|
8427
|
+
h(G.MenuItem, { icon: 'folder-open', label: t('explorer.revealInFinder'), onClick: closeBlank(() => revealPath('')) }),
|
|
8428
|
+
))
|
|
8429
|
+
}
|
|
8388
8430
|
const entries = Array.isArray(menu.entries) && menu.entries.length > 0 ? menu.entries : [{ path: menu.path, kind: menu.kind }]
|
|
8389
8431
|
const files = entries.filter((item) => item.kind === 'file')
|
|
8390
8432
|
const single = entries.length === 1
|
|
@@ -12931,6 +12973,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
12931
12973
|
const gitInFlightRef = useRef(false)
|
|
12932
12974
|
const gitFetchRef = useRef({ root: '', at: 0 })
|
|
12933
12975
|
const [modal, setModal] = useState(null)
|
|
12976
|
+
const [tabMenu, setTabMenu] = useState(null)
|
|
12934
12977
|
const [shortcutsOpen, setShortcutsOpen] = useState(false)
|
|
12935
12978
|
const [definitionPicker, setDefinitionPicker] = useState(null)
|
|
12936
12979
|
const [trashUndo, setTrashUndo] = useState([])
|
|
@@ -13159,36 +13202,71 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13159
13202
|
}, [gitStatus, project])
|
|
13160
13203
|
|
|
13161
13204
|
/* ── 文件打开 / 保存 / 关闭 ─────────────────────────────────────────── */
|
|
13162
|
-
|
|
13205
|
+
/**
|
|
13206
|
+
* 打开文件。preview=true 为「临时打开」(VS Code 预览标签,斜体):
|
|
13207
|
+
* 单点文件树只产生一个预览标签,再点其他文件会原地替换它;
|
|
13208
|
+
* 双击文件/标签或编辑内容后由调用方/changeFile 固定成普通标签。
|
|
13209
|
+
*/
|
|
13210
|
+
const openFile = useCallback(async (rawPath, options) => {
|
|
13163
13211
|
if (project === null) return
|
|
13164
13212
|
const path = gufaNormalizeProjectPath(rawPath)
|
|
13165
13213
|
if (path === '') return
|
|
13214
|
+
const preview = options !== null && options !== undefined && options.preview === true
|
|
13166
13215
|
flushBuffersRef.current?.()
|
|
13167
13216
|
const existing = tabs.find((tab) => gufaNormalizeProjectPath(tab.path) === path)
|
|
13168
13217
|
if (existing !== undefined) {
|
|
13218
|
+
if (preview !== true && existing.preview === true) {
|
|
13219
|
+
setTabs((current) => current.map((tab) => (tab.path === existing.path ? { ...tab, preview: false } : tab)))
|
|
13220
|
+
}
|
|
13169
13221
|
/* 已经打开的文件再次点击:先对齐磁盘最新版本(AI/外部修改后不用关掉重开) */
|
|
13170
13222
|
try {
|
|
13171
|
-
await reloadTabFromDiskRef.current?.(path)
|
|
13223
|
+
await reloadTabFromDiskRef.current?.(existing.path)
|
|
13172
13224
|
} catch {
|
|
13173
13225
|
/* ignore */
|
|
13174
13226
|
}
|
|
13175
|
-
setActivePath(path)
|
|
13227
|
+
setActivePath(existing.path)
|
|
13176
13228
|
return
|
|
13177
13229
|
}
|
|
13178
13230
|
try {
|
|
13179
13231
|
const doc = await G.api('fs.read', { root: project.root, path })
|
|
13180
|
-
|
|
13181
|
-
|
|
13182
|
-
|
|
13183
|
-
|
|
13184
|
-
|
|
13185
|
-
|
|
13186
|
-
|
|
13232
|
+
const nextTab = { ...doc, savedContent: doc.content, dirty: false, savedRevision: doc.revision }
|
|
13233
|
+
if (preview === true) {
|
|
13234
|
+
/* 预览标签全局只有一个:找到干净的那个原地替换,不新增标签 */
|
|
13235
|
+
const previewTab = tabs.find((tab) => tab.preview === true && tab.dirty !== true && tab.kind !== 'diff')
|
|
13236
|
+
if (previewTab !== undefined) {
|
|
13237
|
+
editorBuffersRef.current.delete(previewTab.path)
|
|
13238
|
+
const replacedPath = gufaNormalizeProjectPath(doc.path ?? path)
|
|
13239
|
+
setTabs((current) => current.map((tab) => (
|
|
13240
|
+
tab.path === previewTab.path ? { ...nextTab, preview: true } : tab
|
|
13241
|
+
)))
|
|
13242
|
+
setActivePath(replacedPath)
|
|
13243
|
+
return
|
|
13244
|
+
}
|
|
13245
|
+
setTabs((current) => (
|
|
13246
|
+
current.some((tab) => gufaNormalizeProjectPath(tab.path) === gufaNormalizeProjectPath(doc.path ?? path))
|
|
13247
|
+
? current
|
|
13248
|
+
: [...current, { ...nextTab, preview: true }]
|
|
13249
|
+
))
|
|
13250
|
+
} else {
|
|
13251
|
+
/* 用函数式更新去重:并发/恢复场景下闭包里的 tabs 可能还没刷新,直接追加会产生重复标签 */
|
|
13252
|
+
setTabs((current) => (
|
|
13253
|
+
current.some((tab) => gufaNormalizeProjectPath(tab.path) === gufaNormalizeProjectPath(doc.path ?? path))
|
|
13254
|
+
? current
|
|
13255
|
+
: [...current, nextTab]
|
|
13256
|
+
))
|
|
13257
|
+
}
|
|
13258
|
+
setActivePath(gufaNormalizeProjectPath(doc.path ?? path))
|
|
13187
13259
|
} catch (error) {
|
|
13188
13260
|
setBanner(G.errorText(error))
|
|
13189
13261
|
}
|
|
13190
13262
|
}, [project, tabs])
|
|
13191
13263
|
|
|
13264
|
+
/** 双击标签/文件:把预览标签固定成普通标签。 */
|
|
13265
|
+
const pinTab = useCallback((rawPath) => {
|
|
13266
|
+
const path = gufaNormalizeProjectPath(rawPath)
|
|
13267
|
+
setTabs((current) => current.map((tab) => (tab.path === path && tab.preview === true ? { ...tab, preview: false } : tab)))
|
|
13268
|
+
}, [])
|
|
13269
|
+
|
|
13192
13270
|
/* 从搜索/定位结果打开文件并跳到指定行列(等 tab 切换完成后再触发编辑器 reveal) */
|
|
13193
13271
|
const openFileAt = useCallback(async (rawPath, line, column) => {
|
|
13194
13272
|
if (typeof rawPath !== 'string' || rawPath === '') return
|
|
@@ -13347,9 +13425,10 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13347
13425
|
if (tab === null || !buffers.has(tab.path)) return tab
|
|
13348
13426
|
const content = buffers.get(tab.path)
|
|
13349
13427
|
const dirty = content !== tab.savedContent
|
|
13350
|
-
|
|
13428
|
+
const preview = dirty ? false : tab.preview
|
|
13429
|
+
if (tab.content === content && tab.dirty === dirty && tab.preview === preview) return tab
|
|
13351
13430
|
changed = true
|
|
13352
|
-
return { ...tab, content, dirty }
|
|
13431
|
+
return { ...tab, content, dirty, preview }
|
|
13353
13432
|
})
|
|
13354
13433
|
if (!changed) return current
|
|
13355
13434
|
tabsRef.current = next
|
|
@@ -13379,9 +13458,10 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13379
13458
|
/* 用缓冲里的最新内容而不是本次按键的内容:避免 React 批处理时把「第一次按键」的旧内容回灌给编辑器。 */
|
|
13380
13459
|
const latest = editorBuffersRef.current.has(path) ? editorBuffersRef.current.get(path) : content
|
|
13381
13460
|
const dirty = latest !== item.savedContent
|
|
13382
|
-
|
|
13461
|
+
const preview = dirty ? false : item.preview
|
|
13462
|
+
if (item.dirty === dirty && item.preview === preview) return item
|
|
13383
13463
|
changed = true
|
|
13384
|
-
return { ...item, content: latest, dirty }
|
|
13464
|
+
return { ...item, content: latest, dirty, preview }
|
|
13385
13465
|
})
|
|
13386
13466
|
if (!changed) return current
|
|
13387
13467
|
tabsRef.current = next
|
|
@@ -13494,6 +13574,37 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13494
13574
|
closeTab(path)
|
|
13495
13575
|
}, [tabs, closeTab])
|
|
13496
13576
|
|
|
13577
|
+
/** 关闭当前标签外的其他标签;有未保存改动时先确认。 */
|
|
13578
|
+
const closeOtherTabs = useCallback((path) => {
|
|
13579
|
+
const others = tabs.filter((tab) => tab.path !== path)
|
|
13580
|
+
if (others.length === 0) return
|
|
13581
|
+
if (others.some((tab) => tab.dirty === true) && window.confirm('有未保存的改动,仍要关闭其他标签页吗?') !== true) return
|
|
13582
|
+
for (const tab of others) editorBuffersRef.current.delete(tab.path)
|
|
13583
|
+
setTabs((current) => current.filter((tab) => tab.path === path))
|
|
13584
|
+
setActivePath(path)
|
|
13585
|
+
}, [tabs])
|
|
13586
|
+
|
|
13587
|
+
/** 关闭全部标签;有未保存改动时先确认。 */
|
|
13588
|
+
const closeAllTabs = useCallback(() => {
|
|
13589
|
+
if (tabs.length === 0) return
|
|
13590
|
+
if (tabs.some((tab) => tab.dirty === true) && window.confirm('有未保存的改动,仍要关闭全部标签页吗?') !== true) return
|
|
13591
|
+
editorBuffersRef.current.clear()
|
|
13592
|
+
setTabs([])
|
|
13593
|
+
setActivePath(null)
|
|
13594
|
+
}, [tabs])
|
|
13595
|
+
|
|
13596
|
+
/** 标签右键菜单用:绝对路径 / 相对路径复制。 */
|
|
13597
|
+
const tabAbsolutePath = useCallback((path) => {
|
|
13598
|
+
const root = project !== null && typeof project.root === 'string' ? project.root.replace(/[\\/]+$/, '') : ''
|
|
13599
|
+
if (root === '') return path
|
|
13600
|
+
const sep = root.includes('\\') ? '\\' : '/'
|
|
13601
|
+
return `${root}${sep}${String(path).split('/').join(sep)}`
|
|
13602
|
+
}, [project])
|
|
13603
|
+
|
|
13604
|
+
const copyText = useCallback((text) => {
|
|
13605
|
+
try { void navigator.clipboard?.writeText(String(text)) } catch { /* ignore */ }
|
|
13606
|
+
}, [])
|
|
13607
|
+
|
|
13497
13608
|
/* ── Git Graph(提交图标签页) ─────────────────────────────────────── */
|
|
13498
13609
|
const openGitGraph = useCallback(() => {
|
|
13499
13610
|
if (project === null) return
|
|
@@ -15043,6 +15154,17 @@ G.GufaApp = function GufaApp(props) {
|
|
|
15043
15154
|
return () => window.removeEventListener('keydown', onKey, true)
|
|
15044
15155
|
}, [shortcutsOpen])
|
|
15045
15156
|
|
|
15157
|
+
useEffect(() => {
|
|
15158
|
+
if (tabMenu === null) return undefined
|
|
15159
|
+
const close = () => setTabMenu(null)
|
|
15160
|
+
window.addEventListener('mousedown', close)
|
|
15161
|
+
window.addEventListener('blur', close)
|
|
15162
|
+
return () => {
|
|
15163
|
+
window.removeEventListener('mousedown', close)
|
|
15164
|
+
window.removeEventListener('blur', close)
|
|
15165
|
+
}
|
|
15166
|
+
}, [tabMenu])
|
|
15167
|
+
|
|
15046
15168
|
/* ── 渲染 ─────────────────────────────────────────────────────────── */
|
|
15047
15169
|
const activityItems = [
|
|
15048
15170
|
{ id: 'explorer', icon: 'files', label: t('activity.explorer'), onClick: () => patchUi({ view: 'explorer', sidebarOpen: true }) },
|
|
@@ -15061,7 +15183,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
15061
15183
|
activePath,
|
|
15062
15184
|
refreshToken,
|
|
15063
15185
|
gitStatuses,
|
|
15064
|
-
onOpenFile: (path) => void openFile(path),
|
|
15186
|
+
onOpenFile: (path, options) => void openFile(path, options),
|
|
15065
15187
|
onChanged: () => {
|
|
15066
15188
|
setRefreshToken((token) => token + 1)
|
|
15067
15189
|
setGitRefreshToken((token) => token + 1)
|
|
@@ -15112,7 +15234,14 @@ G.GufaApp = function GufaApp(props) {
|
|
|
15112
15234
|
role: 'tab',
|
|
15113
15235
|
tabIndex: 0,
|
|
15114
15236
|
title: tab.title !== undefined && tab.title !== null ? tab.title : tab.path,
|
|
15237
|
+
'data-preview': tab.preview === true ? '' : undefined,
|
|
15115
15238
|
onClick: () => handleSelectTab(tab.path),
|
|
15239
|
+
onDoubleClick: () => pinTab(tab.path),
|
|
15240
|
+
onContextMenu: (event) => {
|
|
15241
|
+
event.preventDefault()
|
|
15242
|
+
event.stopPropagation()
|
|
15243
|
+
setTabMenu({ x: event.clientX, y: event.clientY, path: tab.path })
|
|
15244
|
+
},
|
|
15116
15245
|
onAuxClick: (event) => { if (event.button === 1) closeTabWithConfirm(tab.path) },
|
|
15117
15246
|
},
|
|
15118
15247
|
h(G.Icon, { name: 'file', size: 13 }),
|
|
@@ -15657,6 +15786,25 @@ G.GufaApp = function GufaApp(props) {
|
|
|
15657
15786
|
),
|
|
15658
15787
|
),
|
|
15659
15788
|
),
|
|
15789
|
+
/* 标签页右键菜单 */
|
|
15790
|
+
tabMenu === null
|
|
15791
|
+
? null
|
|
15792
|
+
: G.portal(h(
|
|
15793
|
+
'div',
|
|
15794
|
+
{
|
|
15795
|
+
className: 'gufa-menu',
|
|
15796
|
+
style: { left: tabMenu.x, top: tabMenu.y, position: 'fixed', minWidth: 190, zIndex: 2147483050 },
|
|
15797
|
+
onMouseDown: (event) => event.stopPropagation(),
|
|
15798
|
+
},
|
|
15799
|
+
h(G.MenuItem, { icon: 'close', label: t('editor.close'), onClick: () => { setTabMenu(null); closeTabWithConfirm(tabMenu.path) } }),
|
|
15800
|
+
h(G.MenuItem, { icon: 'files', label: '关闭其他', onClick: () => { setTabMenu(null); closeOtherTabs(tabMenu.path) } }),
|
|
15801
|
+
h(G.MenuItem, { icon: 'trash', label: '关闭全部', onClick: () => { setTabMenu(null); closeAllTabs() } }),
|
|
15802
|
+
h(G.MenuItem, { icon: 'file', label: '复制路径', onClick: () => { setTabMenu(null); copyText(tabAbsolutePath(tabMenu.path)) } }),
|
|
15803
|
+
h(G.MenuItem, { icon: 'code', label: '复制相对路径', onClick: () => { setTabMenu(null); copyText(tabMenu.path) } }),
|
|
15804
|
+
tabMenu.path === activePath && activeTab !== null && activeTab.preview === true
|
|
15805
|
+
? h(G.MenuItem, { icon: 'check', label: '固定为常驻标签', onClick: () => { setTabMenu(null); pinTab(tabMenu.path) } })
|
|
15806
|
+
: null,
|
|
15807
|
+
)),
|
|
15660
15808
|
/* 弹窗 */
|
|
15661
15809
|
G.portal(modal === null ? null : renderModal()),
|
|
15662
15810
|
G.portal(floatPicker !== null
|
package/package.json
CHANGED
package/src/client/00-core.js
CHANGED
|
@@ -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}
|
package/src/client/50-panels.js
CHANGED
|
@@ -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
|
-
{
|
|
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
|
package/src/client/90-app.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|