dsh-gufa-code 1.3.213 → 1.3.218
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/README.md +59 -18
- package/client.js +348 -46
- package/docs/screenshot-git.jpg +0 -0
- package/docs/screenshot-main.jpg +0 -0
- package/docs/screenshot-moyu.jpg +0 -0
- package/host/code.js +86 -5
- package/host/fs.js +98 -3
- package/host/git.js +43 -2
- package/package.json +1 -1
- package/screenshots.json +3 -1
- package/scripts/selftest-host.mjs +63 -0
- package/src/client/00-core.js +12 -0
- package/src/client/10-icons.js +1 -0
- package/src/client/20-editor.js +68 -15
- package/src/client/50-panels.js +116 -5
- package/src/client/58b-drag-ref.js +3 -0
- package/src/client/85-shortcuts.js +67 -0
- package/src/client/90-app.js +80 -25
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.218'
|
|
20
20
|
G.PANEL_ID = 'gufa-code'
|
|
21
21
|
/** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
|
|
22
22
|
G.pendingEntryWorkspace = null
|
|
@@ -299,6 +299,9 @@ const DICT_ZH = {
|
|
|
299
299
|
'git.branchCurrent': '当前',
|
|
300
300
|
'git.branchNamePlaceholder': '新分支名',
|
|
301
301
|
'git.branchCreate': '新建并切换',
|
|
302
|
+
'git.branchesLocal': '本地分支',
|
|
303
|
+
'git.branchesRemote': '远程分支',
|
|
304
|
+
'git.branchRemoteTag': '远端',
|
|
302
305
|
'git.undoLastCommit': '撤回上次提交(保留改动)',
|
|
303
306
|
'diff.prev': '上一处差异',
|
|
304
307
|
'diff.next': '下一处差异',
|
|
@@ -565,6 +568,9 @@ const DICT_EN = {
|
|
|
565
568
|
'git.branchCurrent': 'current',
|
|
566
569
|
'git.branchNamePlaceholder': 'New branch name',
|
|
567
570
|
'git.branchCreate': 'Create & switch',
|
|
571
|
+
'git.branchesLocal': 'Local branches',
|
|
572
|
+
'git.branchesRemote': 'Remote branches',
|
|
573
|
+
'git.branchRemoteTag': 'remote',
|
|
568
574
|
'git.undoLastCommit': 'Undo last commit (keep changes)',
|
|
569
575
|
'diff.prev': 'Previous change',
|
|
570
576
|
'diff.next': 'Next change',
|
|
@@ -1788,6 +1794,8 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
|
|
|
1788
1794
|
color:var(--gufa-text);cursor:pointer;text-align:left;font-size:12.5px;white-space:nowrap;min-width:0;width:100%}
|
|
1789
1795
|
.gufa-tree-row:hover{background:var(--gufa-hover)}
|
|
1790
1796
|
.gufa-tree-row[data-selected]{background:var(--gufa-active)}
|
|
1797
|
+
.gufa-tree-row[data-drop]{background:color-mix(in srgb, var(--gufa-accent) 18%, transparent);outline:1px dashed var(--gufa-accent);outline-offset:-1px;border-radius:6px}
|
|
1798
|
+
.gufa-panel-body[data-drop-root]{box-shadow:inset 0 0 0 2px color-mix(in srgb, var(--gufa-accent) 55%, transparent)}
|
|
1791
1799
|
.gufa-tree-row[data-kind="dir"]{color:var(--gufa-text)}
|
|
1792
1800
|
.gufa-tree-name{overflow:hidden;text-overflow:ellipsis;flex:1 1 auto;min-width:0}
|
|
1793
1801
|
.gufa-explorer-notice{margin:4px 10px 0;padding:3px 8px;border-radius:6px;font-size:11px;line-height:1.5;color:var(--gufa-text);
|
|
@@ -1947,6 +1955,10 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
|
|
|
1947
1955
|
.gufa-branch-row{display:flex;align-items:center;gap:8px;width:100%;height:30px;padding:0 8px;border:0;border-radius:7px;
|
|
1948
1956
|
background:transparent;color:var(--gufa-text);cursor:pointer;font-size:12px;text-align:left}
|
|
1949
1957
|
.gufa-branch-row:hover{background:var(--gufa-hover)}
|
|
1958
|
+
.gufa-branch-group{padding:8px 10px 3px;font-size:10.5px;font-weight:600;letter-spacing:.03em;color:var(--gufa-text-dim);text-transform:uppercase}
|
|
1959
|
+
.gufa-branch-row[data-remote]{color:var(--gufa-text-dim)}
|
|
1960
|
+
.gufa-branch-row[data-remote]:hover{color:var(--gufa-text)}
|
|
1961
|
+
.gufa-branch-tag[data-kind="remote"]{color:var(--gufa-text-dim);border:0.5px solid var(--gufa-border);background:transparent}
|
|
1950
1962
|
.gufa-branch-row[data-current]{background:color-mix(in srgb, var(--gufa-accent) 16%, transparent)}
|
|
1951
1963
|
.gufa-branch-name{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1952
1964
|
.gufa-branch-tag{font-size:10px;padding:1px 6px;border-radius:8px;color:var(--gufa-accent);
|
|
@@ -2261,6 +2273,7 @@ const ICON_PATHS = {
|
|
|
2261
2273
|
['path', { d: 'M8 3h7l4 4v10a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1z' }],
|
|
2262
2274
|
['path', { d: 'M15 3v4h4M3 8v12a1 1 0 0 0 1 1h9' }, { opacity: 0.55 }],
|
|
2263
2275
|
],
|
|
2276
|
+
cloud: [['path', { d: 'M7 18h10a4 4 0 0 0 .4-8A6 6 0 0 0 6 11.2 3.6 3.6 0 0 0 7 18z' }]],
|
|
2264
2277
|
git: [
|
|
2265
2278
|
['circle', { cx: 6, cy: 6, r: 2.2 }],
|
|
2266
2279
|
['circle', { cx: 6, cy: 18, r: 2.2 }],
|
|
@@ -3119,7 +3132,7 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3119
3132
|
*/
|
|
3120
3133
|
/* JS/TS 的 F12 交回 Monaco 原生 TS DefinitionProvider(之前被我们关掉过);
|
|
3121
3134
|
Cmd+点击在 click handler 里直接走 Host LanguageService 以拿到最准结果。 */
|
|
3122
|
-
const GUFA_DEFINITION_LANGUAGES = ['python']
|
|
3135
|
+
const GUFA_DEFINITION_LANGUAGES = ['python', 'php']
|
|
3123
3136
|
function gufaRegisterDefinitionInfrastructure(monaco) {
|
|
3124
3137
|
try {
|
|
3125
3138
|
if (monaco === null || monaco === undefined) return
|
|
@@ -3179,7 +3192,7 @@ function gufaRegisterDefinitionInfrastructure(monaco) {
|
|
|
3179
3192
|
language: 'python',
|
|
3180
3193
|
content: model.getValue(),
|
|
3181
3194
|
})
|
|
3182
|
-
} else {
|
|
3195
|
+
} else if (language === 'javascript' || language === 'typescript') {
|
|
3183
3196
|
/* LanguageService 解析定义(TS 编译器),比正则项目搜索准确;
|
|
3184
3197
|
JS/TS 不再回退到 code.definition,避免“宁可跳错也不空着”。 */
|
|
3185
3198
|
result = await G.api('code.tsDefinition', {
|
|
@@ -3189,6 +3202,16 @@ function gufaRegisterDefinitionInfrastructure(monaco) {
|
|
|
3189
3202
|
column: position.column,
|
|
3190
3203
|
content: model.getValue(),
|
|
3191
3204
|
})
|
|
3205
|
+
} else {
|
|
3206
|
+
/* PHP 等无内置语言服务的语言:项目级定义搜索(Host code.definition) */
|
|
3207
|
+
result = await G.api('code.definition', {
|
|
3208
|
+
root: info.root,
|
|
3209
|
+
path: info.path,
|
|
3210
|
+
line: position.lineNumber,
|
|
3211
|
+
column: position.column,
|
|
3212
|
+
word,
|
|
3213
|
+
content: model.getValue(),
|
|
3214
|
+
})
|
|
3192
3215
|
}
|
|
3193
3216
|
if (token !== null && token !== undefined && token.isCancellationRequested === true) return []
|
|
3194
3217
|
return locationsOf(info.root, result !== null && result !== undefined ? result.matches : null, word, monaco)
|
|
@@ -3476,6 +3499,23 @@ const GUFA_LINT_ENABLED = true
|
|
|
3476
3499
|
const activePathRef = useRef(activePath)
|
|
3477
3500
|
const statusRef = useRef('loading')
|
|
3478
3501
|
const pendingRevealRef = useRef(null)
|
|
3502
|
+
/* 打开未加载的文件时,editor 可能还没挂载/模型还没切换;先记住目标位置,
|
|
3503
|
+
等编辑器就绪或切到目标文件后再落光标,避免只跳文件、位置不准。 */
|
|
3504
|
+
const applyPendingReveal = useCallback((editor) => {
|
|
3505
|
+
const pending = pendingRevealRef.current
|
|
3506
|
+
if (pending === null || pending === undefined) return false
|
|
3507
|
+
if (editor === null || editor === undefined) return false
|
|
3508
|
+
if (modelPathRef.current !== pending.path) return false
|
|
3509
|
+
pendingRevealRef.current = null
|
|
3510
|
+
try {
|
|
3511
|
+
editor.setPosition({ lineNumber: pending.line, column: pending.column })
|
|
3512
|
+
editor.revealLineInCenter(pending.line)
|
|
3513
|
+
editor.focus()
|
|
3514
|
+
} catch {
|
|
3515
|
+
/* ignore */
|
|
3516
|
+
}
|
|
3517
|
+
return true
|
|
3518
|
+
}, [])
|
|
3479
3519
|
|
|
3480
3520
|
/** idle → loading → ready / error */
|
|
3481
3521
|
const [status, setStatus] = useState('loading')
|
|
@@ -4038,6 +4078,33 @@ const GUFA_LINT_ENABLED = true
|
|
|
4038
4078
|
clearHoverDecoration()
|
|
4039
4079
|
return
|
|
4040
4080
|
}
|
|
4081
|
+
/* 其它语言(PHP / Go / Java …):走项目级定义搜索。
|
|
4082
|
+
queryDefinitions + decideDefinition 已实现,此前没接到点击入口。 */
|
|
4083
|
+
try {
|
|
4084
|
+
const resolved = await queryDefinitions(position, word, model, path, root)
|
|
4085
|
+
const decision = decideDefinition(resolved)
|
|
4086
|
+
if (decision.kind === 'open') {
|
|
4087
|
+
G.bus.emit('editor:open-at', {
|
|
4088
|
+
path: decision.match.path,
|
|
4089
|
+
line: decision.match.line,
|
|
4090
|
+
column: decision.match.column,
|
|
4091
|
+
})
|
|
4092
|
+
clearHoverDecoration()
|
|
4093
|
+
return
|
|
4094
|
+
}
|
|
4095
|
+
if (decision.kind === 'pick') {
|
|
4096
|
+
G.bus.emit('definition:pick', {
|
|
4097
|
+
word,
|
|
4098
|
+
matches: decision.matches,
|
|
4099
|
+
x: Number.isFinite(Number(event.clientX)) ? Number(event.clientX) : 240,
|
|
4100
|
+
y: Number.isFinite(Number(event.clientY)) ? Number(event.clientY) : 240,
|
|
4101
|
+
})
|
|
4102
|
+
clearHoverDecoration()
|
|
4103
|
+
return
|
|
4104
|
+
}
|
|
4105
|
+
} catch {
|
|
4106
|
+
/* 解析失败继续走原生兜底,不跳错 */
|
|
4107
|
+
}
|
|
4041
4108
|
/* 其它语言:保留 Monaco 原生 action 兜底 */
|
|
4042
4109
|
try {
|
|
4043
4110
|
instance.focus()
|
|
@@ -4479,17 +4546,7 @@ const GUFA_LINT_ENABLED = true
|
|
|
4479
4546
|
}
|
|
4480
4547
|
}
|
|
4481
4548
|
reportCursor()
|
|
4482
|
-
|
|
4483
|
-
if (pending !== null && pending !== undefined && pending.path === targetTab.path) {
|
|
4484
|
-
pendingRevealRef.current = null
|
|
4485
|
-
try {
|
|
4486
|
-
editor.setPosition({ lineNumber: pending.line, column: pending.column })
|
|
4487
|
-
editor.revealLineInCenter(pending.line)
|
|
4488
|
-
editor.focus()
|
|
4489
|
-
} catch {
|
|
4490
|
-
/* ignore */
|
|
4491
|
-
}
|
|
4492
|
-
}
|
|
4549
|
+
applyPendingReveal(editor)
|
|
4493
4550
|
/* 打开 Python 文件时预热 pyright,避免第一次 Cmd+点击等语言服务启动 */
|
|
4494
4551
|
if (targetTab.language === 'python' && !GUFA_LSP_WARMED.has(root)) {
|
|
4495
4552
|
GUFA_LSP_WARMED.add(root)
|
|
@@ -4512,19 +4569,28 @@ const GUFA_LINT_ENABLED = true
|
|
|
4512
4569
|
} else if (targetTab !== null) {
|
|
4513
4570
|
modelPathRef.current = targetTab.path
|
|
4514
4571
|
}
|
|
4515
|
-
}, [status, tabs, activePath, root, reportCursor, disposeAllModels, disposeModelAt])
|
|
4572
|
+
}, [status, tabs, activePath, root, reportCursor, applyPendingReveal, disposeAllModels, disposeModelAt])
|
|
4573
|
+
|
|
4574
|
+
/* 编辑器挂载完成/模型已就绪时,把还没落地的定义跳转位置补上 */
|
|
4575
|
+
useEffect(() => {
|
|
4576
|
+
applyPendingReveal(editorRef.current)
|
|
4577
|
+
}, [status, tabs, activePath, applyPendingReveal])
|
|
4516
4578
|
|
|
4517
4579
|
/* 搜索面板点击结果 → 打开文件并跳到对应行列(由 App 通过 bus 发来) */
|
|
4518
4580
|
useEffect(() => {
|
|
4519
4581
|
if (G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function') return undefined
|
|
4520
4582
|
return G.bus.on('editor:reveal', (detail) => {
|
|
4521
4583
|
const editor = editorRef.current
|
|
4522
|
-
if (editor === null || editor === undefined) return
|
|
4523
4584
|
const rawLine = Number(detail?.line)
|
|
4524
4585
|
const rawColumn = Number(detail?.column)
|
|
4525
4586
|
const line = Number.isFinite(rawLine) ? Math.max(1, Math.trunc(rawLine)) : 1
|
|
4526
4587
|
const column = Number.isFinite(rawColumn) ? Math.max(1, Math.trunc(rawColumn)) : 1
|
|
4527
4588
|
const path = typeof detail?.path === 'string' && detail.path !== '' ? detail.path : null
|
|
4589
|
+
if (editor === null || editor === undefined) {
|
|
4590
|
+
/* 编辑器还没挂载(首次打开文件):先记下位置,挂载/切模型后的 effect 会补上 */
|
|
4591
|
+
if (path !== null) pendingRevealRef.current = { path, line, column }
|
|
4592
|
+
return
|
|
4593
|
+
}
|
|
4528
4594
|
if (path !== null && modelPathRef.current !== path) {
|
|
4529
4595
|
pendingRevealRef.current = { path, line, column }
|
|
4530
4596
|
return
|
|
@@ -8035,6 +8101,8 @@ G.GitGraphView = function GitGraphView(props) {
|
|
|
8035
8101
|
* 纯展示 + 直接调用 Host API,状态自持;容器在 90-app.js。
|
|
8036
8102
|
*/
|
|
8037
8103
|
|
|
8104
|
+
const GUFA_EXPLORER_MOVE_TYPE = 'application/x-gufa-explorer-move'
|
|
8105
|
+
|
|
8038
8106
|
/* ── 资源管理器 ────────────────────────────────────────────────────────── */
|
|
8039
8107
|
G.Explorer = function Explorer(props) {
|
|
8040
8108
|
const t = G.useT()
|
|
@@ -8044,6 +8112,8 @@ G.Explorer = function Explorer(props) {
|
|
|
8044
8112
|
const [selected, setSelected] = useState(() => (props.activePath ? { path: props.activePath, kind: 'file' } : null))
|
|
8045
8113
|
const [multi, setMulti] = useState([])
|
|
8046
8114
|
const [clipboard, setClipboard] = useState(null)
|
|
8115
|
+
const [dragTarget, setDragTarget] = useState(null)
|
|
8116
|
+
const internalDragRef = useRef(null)
|
|
8047
8117
|
const [menu, setMenu] = useState(null)
|
|
8048
8118
|
const [menuError, setMenuError] = useState('')
|
|
8049
8119
|
const [notice, setNotice] = useState('')
|
|
@@ -8167,8 +8237,12 @@ G.Explorer = function Explorer(props) {
|
|
|
8167
8237
|
|
|
8168
8238
|
const copySelection = (paths) => {
|
|
8169
8239
|
if (!Array.isArray(paths) || paths.length === 0) return
|
|
8170
|
-
|
|
8240
|
+
const entries = paths.filter((path) => typeof path === 'string' && path !== '')
|
|
8241
|
+
if (entries.length === 0) return
|
|
8242
|
+
setClipboard({ entries })
|
|
8171
8243
|
setMenuError('')
|
|
8244
|
+
/* 同时写入系统剪贴板(file URL / alias 列表):另一个古法编程实例或 Finder 可以直接粘贴 */
|
|
8245
|
+
void G.api('fs.copyToSystemClipboard', { root, from: entries }).catch(() => {})
|
|
8172
8246
|
}
|
|
8173
8247
|
|
|
8174
8248
|
/* 内置剪贴板(IDE 内复制/剪切)优先;没有时读系统剪贴板里的文件/文件夹路径(Finder/资源管理器复制)。 */
|
|
@@ -8212,6 +8286,59 @@ G.Explorer = function Explorer(props) {
|
|
|
8212
8286
|
return () => window.removeEventListener('blur', clear)
|
|
8213
8287
|
}, [])
|
|
8214
8288
|
|
|
8289
|
+
const selectRoot = () => {
|
|
8290
|
+
containerRef.current?.focus?.()
|
|
8291
|
+
setMulti([])
|
|
8292
|
+
setSelected({ path: '', kind: 'dir' })
|
|
8293
|
+
}
|
|
8294
|
+
|
|
8295
|
+
/** 内部拖拽目标目录:拖到文件行 = 其父目录;拖到文件夹/空白 = 文件夹/根目录。 */
|
|
8296
|
+
const internalDropTargetDir = (target) => {
|
|
8297
|
+
const row = target instanceof Element ? target.closest('[data-edrv-path]') : null
|
|
8298
|
+
if (row === null) return ''
|
|
8299
|
+
const path = row.getAttribute('data-edrv-path') ?? ''
|
|
8300
|
+
const kind = row.getAttribute('data-kind')
|
|
8301
|
+
return kind === 'dir' ? path : projectDirOf(path)
|
|
8302
|
+
}
|
|
8303
|
+
|
|
8304
|
+
/** 把资源管理器里拖拽的条目移动到目标目录(根目录传 '')。 */
|
|
8305
|
+
const moveEntries = async (paths, targetDir) => {
|
|
8306
|
+
const list = (Array.isArray(paths) ? paths : []).filter((path) => typeof path === 'string' && path !== '')
|
|
8307
|
+
const movable = list.filter((path) => {
|
|
8308
|
+
if (path === targetDir) return false
|
|
8309
|
+
if (targetDir !== '' && targetDir.startsWith(`${path}/`)) return false
|
|
8310
|
+
return true
|
|
8311
|
+
})
|
|
8312
|
+
if (movable.length === 0) return
|
|
8313
|
+
showNotice(`正在移动 ${movable.length} 项…`)
|
|
8314
|
+
const failed = []
|
|
8315
|
+
let moved = 0
|
|
8316
|
+
let last = null
|
|
8317
|
+
for (const path of movable) {
|
|
8318
|
+
const base = path.split('/').filter(Boolean).pop() ?? path
|
|
8319
|
+
const nextPath = targetDir === '' ? base : `${targetDir}/${base}`
|
|
8320
|
+
if (nextPath === path) continue
|
|
8321
|
+
try {
|
|
8322
|
+
await G.api('fs.rename', { root, path, nextPath })
|
|
8323
|
+
moved += 1
|
|
8324
|
+
last = { path: nextPath, kind: kindByPathRef.current.get(path) ?? 'file' }
|
|
8325
|
+
} catch (error) {
|
|
8326
|
+
failed.push(`${path}:${G.errorText(error)}`)
|
|
8327
|
+
}
|
|
8328
|
+
}
|
|
8329
|
+
const dirsToRefresh = new Set(['', targetDir])
|
|
8330
|
+
for (const path of movable) dirsToRefresh.add(projectDirOf(path))
|
|
8331
|
+
for (const dir of dirsToRefresh) void loadDir(dir)
|
|
8332
|
+
props.onChanged?.()
|
|
8333
|
+
if (last !== null) {
|
|
8334
|
+
setMulti([])
|
|
8335
|
+
setSelected(last)
|
|
8336
|
+
if (last.kind === 'dir') setExpanded((current) => ({ ...current, [last.path]: true }))
|
|
8337
|
+
}
|
|
8338
|
+
if (moved > 0) showNotice(`已移动 ${moved} 项${failed.length > 0 ? `,${failed.length} 项失败` : ''}`)
|
|
8339
|
+
else if (failed.length > 0) showNotice(`移动失败:${failed[0]}`)
|
|
8340
|
+
}
|
|
8341
|
+
|
|
8215
8342
|
const noticeRef = useRef(0)
|
|
8216
8343
|
const showNotice = (text) => {
|
|
8217
8344
|
setNotice(text)
|
|
@@ -8364,6 +8491,8 @@ G.Explorer = function Explorer(props) {
|
|
|
8364
8491
|
'data-git-status': status !== undefined ? status : undefined,
|
|
8365
8492
|
/* 给 dsh-drag-ref 用:把资源管理器行变成可拖拽的 @ 引用来源 */
|
|
8366
8493
|
'data-edrv-path': entry.path,
|
|
8494
|
+
'data-drop': isDir && dragTarget === entry.path ? '' : undefined,
|
|
8495
|
+
draggable: true,
|
|
8367
8496
|
style: { paddingLeft: 8 + depth * 14 },
|
|
8368
8497
|
title: entry.path,
|
|
8369
8498
|
onClick: (event) => {
|
|
@@ -8387,6 +8516,22 @@ G.Explorer = function Explorer(props) {
|
|
|
8387
8516
|
onDoubleClick: () => {
|
|
8388
8517
|
if (!isDir) props.onOpenFile?.(entry.path, { preview: false })
|
|
8389
8518
|
},
|
|
8519
|
+
onDragStart: (event) => {
|
|
8520
|
+
const dragPaths = multi.length > 0 && multi.includes(entry.path) ? multi.slice() : [entry.path]
|
|
8521
|
+
internalDragRef.current = dragPaths
|
|
8522
|
+
try {
|
|
8523
|
+
if (event.dataTransfer !== null && event.dataTransfer !== undefined) {
|
|
8524
|
+
event.dataTransfer.effectAllowed = 'copyMove'
|
|
8525
|
+
event.dataTransfer.setData(GUFA_EXPLORER_MOVE_TYPE, JSON.stringify({ paths: dragPaths }))
|
|
8526
|
+
}
|
|
8527
|
+
} catch {
|
|
8528
|
+
/* ignore */
|
|
8529
|
+
}
|
|
8530
|
+
},
|
|
8531
|
+
onDragEnd: () => {
|
|
8532
|
+
internalDragRef.current = null
|
|
8533
|
+
setDragTarget(null)
|
|
8534
|
+
},
|
|
8390
8535
|
onContextMenu: (event) => openContextMenu(event, entry),
|
|
8391
8536
|
},
|
|
8392
8537
|
h(
|
|
@@ -8438,28 +8583,59 @@ G.Explorer = function Explorer(props) {
|
|
|
8438
8583
|
},
|
|
8439
8584
|
onDragOver: (event) => {
|
|
8440
8585
|
const types = event.dataTransfer?.types
|
|
8441
|
-
if (types === undefined || types === null
|
|
8586
|
+
if (types === undefined || types === null) return
|
|
8587
|
+
const list = Array.from(types)
|
|
8588
|
+
if (list.includes(GUFA_EXPLORER_MOVE_TYPE)) {
|
|
8589
|
+
event.preventDefault()
|
|
8590
|
+
event.stopPropagation()
|
|
8591
|
+
if (event.dataTransfer !== null && event.dataTransfer !== undefined) event.dataTransfer.dropEffect = 'move'
|
|
8592
|
+
setDragTarget(internalDropTargetDir(event.target))
|
|
8593
|
+
return
|
|
8594
|
+
}
|
|
8595
|
+
if (!list.includes('Files')) return
|
|
8442
8596
|
event.preventDefault()
|
|
8443
8597
|
event.stopPropagation()
|
|
8444
8598
|
event.dataTransfer.dropEffect = 'copy'
|
|
8445
8599
|
},
|
|
8600
|
+
onDragLeave: (event) => {
|
|
8601
|
+
if (event.currentTarget instanceof Node && event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget)) return
|
|
8602
|
+
setDragTarget(null)
|
|
8603
|
+
},
|
|
8446
8604
|
onDrop: (event) => {
|
|
8605
|
+
const types = event.dataTransfer?.types
|
|
8606
|
+
if (types !== undefined && types !== null && Array.from(types).includes(GUFA_EXPLORER_MOVE_TYPE)) {
|
|
8607
|
+
event.preventDefault()
|
|
8608
|
+
event.stopPropagation()
|
|
8609
|
+
const paths = internalDragRef.current
|
|
8610
|
+
internalDragRef.current = null
|
|
8611
|
+
const targetDir = internalDropTargetDir(event.target)
|
|
8612
|
+
setDragTarget(null)
|
|
8613
|
+
void moveEntries(paths, targetDir)
|
|
8614
|
+
return
|
|
8615
|
+
}
|
|
8447
8616
|
const files = event.dataTransfer?.files
|
|
8448
8617
|
if (files === undefined || files === null || files.length === 0) return
|
|
8449
8618
|
event.preventDefault()
|
|
8450
8619
|
event.stopPropagation()
|
|
8451
8620
|
void uploadFiles(files, dropTargetDir(event.target))
|
|
8452
8621
|
},
|
|
8622
|
+
onClick: (event) => {
|
|
8623
|
+
/* 点击资源管理器空白处:选中根目录,而不是保留上一次选中的文件/文件夹 */
|
|
8624
|
+
if (!(event.target instanceof Element)) return
|
|
8625
|
+
if (event.target.closest('[data-edrv-path]') !== null) return
|
|
8626
|
+
if (event.target.closest('.gufa-panel-head, button, input, textarea, [role="menu"]') !== null) return
|
|
8627
|
+
selectRoot()
|
|
8628
|
+
},
|
|
8453
8629
|
onKeyDown: (event) => {
|
|
8454
8630
|
if (event.key === 'Enter') {
|
|
8455
|
-
if (selected === null) return
|
|
8631
|
+
if (selected === null || selected.path === '') return
|
|
8456
8632
|
event.preventDefault()
|
|
8457
8633
|
props.onRename?.(selected.path)
|
|
8458
8634
|
return
|
|
8459
8635
|
}
|
|
8460
8636
|
const mod = event.metaKey || event.ctrlKey
|
|
8461
8637
|
if (!mod || event.altKey) {
|
|
8462
|
-
if (event.key === 'Delete' && selected !== null) {
|
|
8638
|
+
if (event.key === 'Delete' && selected !== null && selected.path !== '') {
|
|
8463
8639
|
event.preventDefault()
|
|
8464
8640
|
props.onDelete?.(selected.path)
|
|
8465
8641
|
}
|
|
@@ -8474,7 +8650,7 @@ G.Explorer = function Explorer(props) {
|
|
|
8474
8650
|
void pasteInto(selectedDir())
|
|
8475
8651
|
} else if (key === 'backspace' || event.key === 'Delete') {
|
|
8476
8652
|
event.preventDefault()
|
|
8477
|
-
if (selected !== null) props.onDelete?.(selected.path)
|
|
8653
|
+
if (selected !== null && selected.path !== '') props.onDelete?.(selected.path)
|
|
8478
8654
|
}
|
|
8479
8655
|
},
|
|
8480
8656
|
},
|
|
@@ -8494,6 +8670,7 @@ G.Explorer = function Explorer(props) {
|
|
|
8494
8670
|
'div',
|
|
8495
8671
|
{
|
|
8496
8672
|
className: 'gufa-panel-body gufa-scroll',
|
|
8673
|
+
'data-drop-root': dragTarget === '' ? '' : undefined,
|
|
8497
8674
|
onContextMenu: (event) => {
|
|
8498
8675
|
try {
|
|
8499
8676
|
if (event.target !== null && event.target !== undefined && typeof event.target.closest === 'function' && event.target.closest('.gufa-tree-row') !== null) return
|
|
@@ -10857,6 +11034,9 @@ function install(ctx) {
|
|
|
10857
11034
|
};
|
|
10858
11035
|
const onDrop = (event) => {
|
|
10859
11036
|
if (!isOurs(event.dataTransfer)) return;
|
|
11037
|
+
/* 资源管理器内部拖拽移动文件:交给 Explorer 自己的 drop 处理,不当作 @ 引用插入 */
|
|
11038
|
+
if (event.dataTransfer !== null && Array.prototype.indexOf.call(event.dataTransfer.types, "application/x-gufa-explorer-move") !== -1
|
|
11039
|
+
&& event.target instanceof Element && event.target.closest(".gufa-sidepanel") !== null) return;
|
|
10860
11040
|
if (dropZoneOf(event.target) === null) {
|
|
10861
11041
|
toast("松手位置不在输入框内,未插入", "err");
|
|
10862
11042
|
return;
|
|
@@ -12692,6 +12872,14 @@ G.installShortcutIntegration = function installShortcutIntegration(service) {
|
|
|
12692
12872
|
const mac = G.isMacPlatform()
|
|
12693
12873
|
const primary = mac ? gesture?.meta === true && gesture?.control !== true : gesture?.control === true
|
|
12694
12874
|
if (primary && gesture?.code === 'KeyK' && gesture?.shift !== true && gesture?.alt !== true) {
|
|
12875
|
+
try {
|
|
12876
|
+
if ((window.__gufaDispatchRemapLogs ?? 0) < 20) {
|
|
12877
|
+
window.__gufaDispatchRemapLogs = (window.__gufaDispatchRemapLogs ?? 0) + 1
|
|
12878
|
+
void G.api('dev.log', { message: 'command-remap-dispatch KeyK -> clearTerminal' }).catch(() => {})
|
|
12879
|
+
}
|
|
12880
|
+
} catch {
|
|
12881
|
+
/* ignore */
|
|
12882
|
+
}
|
|
12695
12883
|
if (typeof consume === 'function') consume()
|
|
12696
12884
|
if (gesture?.repeat !== true) {
|
|
12697
12885
|
try { window.__gufaIdeShortcutDispatch('clearTerminal') } catch { /* ignore */ }
|
|
@@ -12759,6 +12947,65 @@ G.installShortcutIntegration = function installShortcutIntegration(service) {
|
|
|
12759
12947
|
/* 重试安装失败不影响主流程 */
|
|
12760
12948
|
}
|
|
12761
12949
|
|
|
12950
|
+
/* ── 自愈:DSH 重连/切换会话/热重载可能重建命令表或丢掉 dispatch 补丁,
|
|
12951
|
+
表现为「一开始 Cmd+K 好用,操作一阵后失效、重启客户端才恢复」。
|
|
12952
|
+
每 1.5s 检查一次,发现补丁丢失就在 IDE 模式下自动重装。 ── */
|
|
12953
|
+
try {
|
|
12954
|
+
if (typeof window !== 'undefined' && window !== null) {
|
|
12955
|
+
if (service.__gufaHealthTimer === undefined || service.__gufaHealthTimer === null) {
|
|
12956
|
+
service.__gufaHealthTimer = window.setInterval(() => {
|
|
12957
|
+
try {
|
|
12958
|
+
if (G.mode.get() !== true) return
|
|
12959
|
+
const registryNow = service.registry
|
|
12960
|
+
if (registryNow === null || registryNow === undefined) return
|
|
12961
|
+
const dispatchOk = registryNow.__gufaDispatchPatched === true
|
|
12962
|
+
let wrapMissing = false
|
|
12963
|
+
const commandsNow = registryNow.commands
|
|
12964
|
+
if (commandsNow !== null && commandsNow !== undefined && typeof commandsNow.get === 'function') {
|
|
12965
|
+
for (const id of Object.keys(service.__gufaCommandActions ?? {})) {
|
|
12966
|
+
const command = commandsNow.get(id)
|
|
12967
|
+
if (command !== null && command !== undefined && command.__gufaWrapped !== true) {
|
|
12968
|
+
wrapMissing = true
|
|
12969
|
+
break
|
|
12970
|
+
}
|
|
12971
|
+
}
|
|
12972
|
+
}
|
|
12973
|
+
if (dispatchOk && !wrapMissing) return
|
|
12974
|
+
if ((service.__gufaHealthLogs ?? 0) < 20) {
|
|
12975
|
+
service.__gufaHealthLogs = (service.__gufaHealthLogs ?? 0) + 1
|
|
12976
|
+
void G.api('dev.log', {
|
|
12977
|
+
message: `shortcut-health-heal dispatch=${dispatchOk} wrapMissing=${wrapMissing} mode=${G.mode.get() === true}`,
|
|
12978
|
+
}).catch(() => {})
|
|
12979
|
+
}
|
|
12980
|
+
try {
|
|
12981
|
+
G.installShortcutIntegration(service)
|
|
12982
|
+
} catch {
|
|
12983
|
+
/* ignore */
|
|
12984
|
+
}
|
|
12985
|
+
} catch {
|
|
12986
|
+
/* ignore */
|
|
12987
|
+
}
|
|
12988
|
+
}, 1500)
|
|
12989
|
+
}
|
|
12990
|
+
if (service.__gufaCatalogSubscribed !== true && service.catalog !== null && service.catalog !== undefined && typeof service.catalog.subscribe === 'function') {
|
|
12991
|
+
service.__gufaCatalogSubscribed = true
|
|
12992
|
+
try {
|
|
12993
|
+
service.catalog.subscribe(() => {
|
|
12994
|
+
try {
|
|
12995
|
+
if (G.mode.get() === true) G.installShortcutIntegration(service)
|
|
12996
|
+
} catch {
|
|
12997
|
+
/* ignore */
|
|
12998
|
+
}
|
|
12999
|
+
})
|
|
13000
|
+
} catch {
|
|
13001
|
+
/* ignore */
|
|
13002
|
+
}
|
|
13003
|
+
}
|
|
13004
|
+
}
|
|
13005
|
+
} catch {
|
|
13006
|
+
/* ignore */
|
|
13007
|
+
}
|
|
13008
|
+
|
|
12762
13009
|
// ── 一次性自检:确认改派在 IDE 模式下真的会执行(不会影响经典模式)──
|
|
12763
13010
|
try {
|
|
12764
13011
|
if (typeof window !== 'undefined' && window !== null && window.sessionStorage !== undefined) {
|
|
@@ -13328,6 +13575,9 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13328
13575
|
const [banner, setBanner] = useState('')
|
|
13329
13576
|
const [tabs, setTabs] = useState([])
|
|
13330
13577
|
const [activePath, setActivePath] = useState(null)
|
|
13578
|
+
const activePathRef = useRef(activePath)
|
|
13579
|
+
activePathRef.current = activePath
|
|
13580
|
+
const pendingOpenAtRef = useRef(null)
|
|
13331
13581
|
/* 选区(给右侧 AI 用)单独更新;光标位置/行数走 G.cursorStore,避免每次按键重渲染整个 IDE。 */
|
|
13332
13582
|
const [selection, setSelection] = useState(null)
|
|
13333
13583
|
/* 编辑器内容缓冲:Monaco 每次按键只写这里,300ms 停顿后才同步进 tabs(保存/自动保存直接读缓冲)。 */
|
|
@@ -13670,15 +13920,31 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13670
13920
|
await openFile(path)
|
|
13671
13921
|
const targetLine = Number.isFinite(Number(line)) ? Math.max(1, Math.trunc(Number(line))) : 1
|
|
13672
13922
|
const targetColumn = Number.isFinite(Number(column)) ? Math.max(1, Math.trunc(Number(column))) : 1
|
|
13673
|
-
|
|
13674
|
-
|
|
13675
|
-
|
|
13676
|
-
|
|
13677
|
-
|
|
13678
|
-
|
|
13679
|
-
|
|
13923
|
+
const target = { path, line: targetLine, column: targetColumn }
|
|
13924
|
+
const currentActive = activePathRef.current === null ? null : gufaNormalizeProjectPath(activePathRef.current)
|
|
13925
|
+
if (currentActive === path) {
|
|
13926
|
+
/* 文件本来就打开着:编辑器/model 已就绪,延迟一帧即可 */
|
|
13927
|
+
window.setTimeout(() => {
|
|
13928
|
+
try { G.bus.emit('editor:reveal', target) } catch { /* ignore */ }
|
|
13929
|
+
}, 80)
|
|
13930
|
+
return
|
|
13931
|
+
}
|
|
13932
|
+
/* 文件未打开:交给 activePath effect,在 tab 真正切过去之后再 reveal(避免固定 120ms 的竞态) */
|
|
13933
|
+
pendingOpenAtRef.current = target
|
|
13680
13934
|
}, [openFile])
|
|
13681
13935
|
|
|
13936
|
+
/* 未打开文件跳转:activePath 切到目标文件后(子组件编辑器 effect 已先行)再发 reveal */
|
|
13937
|
+
useEffect(() => {
|
|
13938
|
+
const pending = pendingOpenAtRef.current
|
|
13939
|
+
if (pending === null || pending === undefined) return undefined
|
|
13940
|
+
if (activePath === null || gufaNormalizeProjectPath(activePath) !== gufaNormalizeProjectPath(pending.path)) return undefined
|
|
13941
|
+
pendingOpenAtRef.current = null
|
|
13942
|
+
const timer = window.setTimeout(() => {
|
|
13943
|
+
try { G.bus.emit('editor:reveal', pending) } catch { /* ignore */ }
|
|
13944
|
+
}, 40)
|
|
13945
|
+
return () => window.clearTimeout(timer)
|
|
13946
|
+
}, [activePath])
|
|
13947
|
+
|
|
13682
13948
|
/* Cmd/Ctrl+点击定义:编辑器 → App 跳转 / 多结果选择(兜底搜索在 host/code.js) */
|
|
13683
13949
|
useEffect(() => {
|
|
13684
13950
|
if (G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function') return undefined
|
|
@@ -14075,13 +14341,25 @@ G.GufaApp = function GufaApp(props) {
|
|
|
14075
14341
|
}
|
|
14076
14342
|
setBranchInput('')
|
|
14077
14343
|
setBranchMenu({ ...placement, repo: repoPath, loading: true, branches: [], error: '' })
|
|
14078
|
-
|
|
14344
|
+
const loadBranches = () => G.api('git.branches', { root: project.root, repo: repoPath })
|
|
14079
14345
|
.then((value) => {
|
|
14080
|
-
setBranchMenu((current) => (current === null
|
|
14346
|
+
setBranchMenu((current) => (current === null
|
|
14347
|
+
? current
|
|
14348
|
+
: {
|
|
14349
|
+
...current,
|
|
14350
|
+
loading: false,
|
|
14351
|
+
branches: Array.isArray(value?.branches) ? value.branches : [],
|
|
14352
|
+
remotes: Array.isArray(value?.remotes) ? value.remotes : [],
|
|
14353
|
+
}))
|
|
14081
14354
|
})
|
|
14082
14355
|
.catch((error) => {
|
|
14083
14356
|
setBranchMenu((current) => (current === null ? current : { ...current, loading: false, error: G.errorText(error) }))
|
|
14084
14357
|
})
|
|
14358
|
+
void loadBranches()
|
|
14359
|
+
/* 远端分支可能只在远端、本地还没 fetch:打开弹窗时后台 fetch 一次再刷新列表 */
|
|
14360
|
+
void G.api('git.fetch', { root: project.root, repo: repoPath })
|
|
14361
|
+
.catch(() => {})
|
|
14362
|
+
.then(() => loadBranches())
|
|
14085
14363
|
}, [project])
|
|
14086
14364
|
|
|
14087
14365
|
const closeBranchMenu = useCallback(() => {
|
|
@@ -14107,10 +14385,10 @@ G.GufaApp = function GufaApp(props) {
|
|
|
14107
14385
|
}
|
|
14108
14386
|
}, [branchMenu, closeBranchMenu])
|
|
14109
14387
|
|
|
14110
|
-
const checkoutBranch = useCallback(async (name) => {
|
|
14388
|
+
const checkoutBranch = useCallback(async (name, remote) => {
|
|
14111
14389
|
if (project === null || typeof name !== 'string' || name === '') return
|
|
14112
14390
|
try {
|
|
14113
|
-
await G.api('git.checkout', { root: project.root, repo: branchMenu?.repo, branch: name })
|
|
14391
|
+
await G.api('git.checkout', { root: project.root, repo: branchMenu?.repo, branch: name, remote: remote === true })
|
|
14114
14392
|
closeBranchMenu()
|
|
14115
14393
|
setGitRefreshToken((token) => token + 1)
|
|
14116
14394
|
setRefreshToken((token) => token + 1)
|
|
@@ -16167,21 +16445,45 @@ G.GufaApp = function GufaApp(props) {
|
|
|
16167
16445
|
{ className: 'gufa-branch-dialog-list gufa-scroll' },
|
|
16168
16446
|
...(branchMenu.loading === true
|
|
16169
16447
|
? []
|
|
16170
|
-
:
|
|
16171
|
-
|
|
16172
|
-
'
|
|
16173
|
-
|
|
16174
|
-
|
|
16175
|
-
|
|
16176
|
-
|
|
16177
|
-
|
|
16178
|
-
|
|
16179
|
-
|
|
16180
|
-
|
|
16181
|
-
|
|
16182
|
-
|
|
16448
|
+
: [
|
|
16449
|
+
branchMenu.branches.length > 0
|
|
16450
|
+
? h('div', { className: 'gufa-branch-group' }, t('git.branchesLocal'))
|
|
16451
|
+
: null,
|
|
16452
|
+
...branchMenu.branches.map((branch) =>
|
|
16453
|
+
h(
|
|
16454
|
+
'button',
|
|
16455
|
+
{
|
|
16456
|
+
key: `l:${branch.name}`,
|
|
16457
|
+
type: 'button',
|
|
16458
|
+
className: 'gufa-branch-row',
|
|
16459
|
+
'data-current': branch.current === true ? '' : undefined,
|
|
16460
|
+
onClick: () => void checkoutBranch(branch.name),
|
|
16461
|
+
},
|
|
16462
|
+
h(G.Icon, { name: branch.current === true ? 'check' : 'branch', size: 13 }),
|
|
16463
|
+
h('span', { className: 'gufa-branch-name' }, branch.name),
|
|
16464
|
+
branch.current === true ? h('span', { className: 'gufa-branch-tag' }, t('git.branchCurrent')) : null,
|
|
16465
|
+
),
|
|
16466
|
+
),
|
|
16467
|
+
Array.isArray(branchMenu.remotes) && branchMenu.remotes.length > 0
|
|
16468
|
+
? h('div', { className: 'gufa-branch-group' }, t('git.branchesRemote'))
|
|
16469
|
+
: null,
|
|
16470
|
+
...(Array.isArray(branchMenu.remotes) ? branchMenu.remotes : []).map((branch) =>
|
|
16471
|
+
h(
|
|
16472
|
+
'button',
|
|
16473
|
+
{
|
|
16474
|
+
key: `r:${branch.name}`,
|
|
16475
|
+
type: 'button',
|
|
16476
|
+
className: 'gufa-branch-row',
|
|
16477
|
+
'data-remote': '',
|
|
16478
|
+
title: `${branch.name} → ${branch.short}(创建本地跟踪分支)`,
|
|
16479
|
+
onClick: () => void checkoutBranch(branch.name, true),
|
|
16480
|
+
},
|
|
16481
|
+
h(G.Icon, { name: 'cloud', size: 13 }),
|
|
16482
|
+
h('span', { className: 'gufa-branch-name' }, branch.name),
|
|
16483
|
+
h('span', { className: 'gufa-branch-tag', 'data-kind': 'remote' }, t('git.branchRemoteTag')),
|
|
16484
|
+
),
|
|
16183
16485
|
),
|
|
16184
|
-
)
|
|
16486
|
+
]),
|
|
16185
16487
|
),
|
|
16186
16488
|
h(
|
|
16187
16489
|
'div',
|
|
Binary file
|
|
Binary file
|
|
Binary file
|