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/src/client/50-panels.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* 纯展示 + 直接调用 Host API,状态自持;容器在 90-app.js。
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
const GUFA_EXPLORER_MOVE_TYPE = 'application/x-gufa-explorer-move'
|
|
7
|
+
|
|
6
8
|
/* ── 资源管理器 ────────────────────────────────────────────────────────── */
|
|
7
9
|
G.Explorer = function Explorer(props) {
|
|
8
10
|
const t = G.useT()
|
|
@@ -12,6 +14,8 @@ G.Explorer = function Explorer(props) {
|
|
|
12
14
|
const [selected, setSelected] = useState(() => (props.activePath ? { path: props.activePath, kind: 'file' } : null))
|
|
13
15
|
const [multi, setMulti] = useState([])
|
|
14
16
|
const [clipboard, setClipboard] = useState(null)
|
|
17
|
+
const [dragTarget, setDragTarget] = useState(null)
|
|
18
|
+
const internalDragRef = useRef(null)
|
|
15
19
|
const [menu, setMenu] = useState(null)
|
|
16
20
|
const [menuError, setMenuError] = useState('')
|
|
17
21
|
const [notice, setNotice] = useState('')
|
|
@@ -135,8 +139,12 @@ G.Explorer = function Explorer(props) {
|
|
|
135
139
|
|
|
136
140
|
const copySelection = (paths) => {
|
|
137
141
|
if (!Array.isArray(paths) || paths.length === 0) return
|
|
138
|
-
|
|
142
|
+
const entries = paths.filter((path) => typeof path === 'string' && path !== '')
|
|
143
|
+
if (entries.length === 0) return
|
|
144
|
+
setClipboard({ entries })
|
|
139
145
|
setMenuError('')
|
|
146
|
+
/* 同时写入系统剪贴板(file URL / alias 列表):另一个古法编程实例或 Finder 可以直接粘贴 */
|
|
147
|
+
void G.api('fs.copyToSystemClipboard', { root, from: entries }).catch(() => {})
|
|
140
148
|
}
|
|
141
149
|
|
|
142
150
|
/* 内置剪贴板(IDE 内复制/剪切)优先;没有时读系统剪贴板里的文件/文件夹路径(Finder/资源管理器复制)。 */
|
|
@@ -180,6 +188,59 @@ G.Explorer = function Explorer(props) {
|
|
|
180
188
|
return () => window.removeEventListener('blur', clear)
|
|
181
189
|
}, [])
|
|
182
190
|
|
|
191
|
+
const selectRoot = () => {
|
|
192
|
+
containerRef.current?.focus?.()
|
|
193
|
+
setMulti([])
|
|
194
|
+
setSelected({ path: '', kind: 'dir' })
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** 内部拖拽目标目录:拖到文件行 = 其父目录;拖到文件夹/空白 = 文件夹/根目录。 */
|
|
198
|
+
const internalDropTargetDir = (target) => {
|
|
199
|
+
const row = target instanceof Element ? target.closest('[data-edrv-path]') : null
|
|
200
|
+
if (row === null) return ''
|
|
201
|
+
const path = row.getAttribute('data-edrv-path') ?? ''
|
|
202
|
+
const kind = row.getAttribute('data-kind')
|
|
203
|
+
return kind === 'dir' ? path : projectDirOf(path)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** 把资源管理器里拖拽的条目移动到目标目录(根目录传 '')。 */
|
|
207
|
+
const moveEntries = async (paths, targetDir) => {
|
|
208
|
+
const list = (Array.isArray(paths) ? paths : []).filter((path) => typeof path === 'string' && path !== '')
|
|
209
|
+
const movable = list.filter((path) => {
|
|
210
|
+
if (path === targetDir) return false
|
|
211
|
+
if (targetDir !== '' && targetDir.startsWith(`${path}/`)) return false
|
|
212
|
+
return true
|
|
213
|
+
})
|
|
214
|
+
if (movable.length === 0) return
|
|
215
|
+
showNotice(`正在移动 ${movable.length} 项…`)
|
|
216
|
+
const failed = []
|
|
217
|
+
let moved = 0
|
|
218
|
+
let last = null
|
|
219
|
+
for (const path of movable) {
|
|
220
|
+
const base = path.split('/').filter(Boolean).pop() ?? path
|
|
221
|
+
const nextPath = targetDir === '' ? base : `${targetDir}/${base}`
|
|
222
|
+
if (nextPath === path) continue
|
|
223
|
+
try {
|
|
224
|
+
await G.api('fs.rename', { root, path, nextPath })
|
|
225
|
+
moved += 1
|
|
226
|
+
last = { path: nextPath, kind: kindByPathRef.current.get(path) ?? 'file' }
|
|
227
|
+
} catch (error) {
|
|
228
|
+
failed.push(`${path}:${G.errorText(error)}`)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const dirsToRefresh = new Set(['', targetDir])
|
|
232
|
+
for (const path of movable) dirsToRefresh.add(projectDirOf(path))
|
|
233
|
+
for (const dir of dirsToRefresh) void loadDir(dir)
|
|
234
|
+
props.onChanged?.()
|
|
235
|
+
if (last !== null) {
|
|
236
|
+
setMulti([])
|
|
237
|
+
setSelected(last)
|
|
238
|
+
if (last.kind === 'dir') setExpanded((current) => ({ ...current, [last.path]: true }))
|
|
239
|
+
}
|
|
240
|
+
if (moved > 0) showNotice(`已移动 ${moved} 项${failed.length > 0 ? `,${failed.length} 项失败` : ''}`)
|
|
241
|
+
else if (failed.length > 0) showNotice(`移动失败:${failed[0]}`)
|
|
242
|
+
}
|
|
243
|
+
|
|
183
244
|
const noticeRef = useRef(0)
|
|
184
245
|
const showNotice = (text) => {
|
|
185
246
|
setNotice(text)
|
|
@@ -332,6 +393,8 @@ G.Explorer = function Explorer(props) {
|
|
|
332
393
|
'data-git-status': status !== undefined ? status : undefined,
|
|
333
394
|
/* 给 dsh-drag-ref 用:把资源管理器行变成可拖拽的 @ 引用来源 */
|
|
334
395
|
'data-edrv-path': entry.path,
|
|
396
|
+
'data-drop': isDir && dragTarget === entry.path ? '' : undefined,
|
|
397
|
+
draggable: true,
|
|
335
398
|
style: { paddingLeft: 8 + depth * 14 },
|
|
336
399
|
title: entry.path,
|
|
337
400
|
onClick: (event) => {
|
|
@@ -355,6 +418,22 @@ G.Explorer = function Explorer(props) {
|
|
|
355
418
|
onDoubleClick: () => {
|
|
356
419
|
if (!isDir) props.onOpenFile?.(entry.path, { preview: false })
|
|
357
420
|
},
|
|
421
|
+
onDragStart: (event) => {
|
|
422
|
+
const dragPaths = multi.length > 0 && multi.includes(entry.path) ? multi.slice() : [entry.path]
|
|
423
|
+
internalDragRef.current = dragPaths
|
|
424
|
+
try {
|
|
425
|
+
if (event.dataTransfer !== null && event.dataTransfer !== undefined) {
|
|
426
|
+
event.dataTransfer.effectAllowed = 'copyMove'
|
|
427
|
+
event.dataTransfer.setData(GUFA_EXPLORER_MOVE_TYPE, JSON.stringify({ paths: dragPaths }))
|
|
428
|
+
}
|
|
429
|
+
} catch {
|
|
430
|
+
/* ignore */
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
onDragEnd: () => {
|
|
434
|
+
internalDragRef.current = null
|
|
435
|
+
setDragTarget(null)
|
|
436
|
+
},
|
|
358
437
|
onContextMenu: (event) => openContextMenu(event, entry),
|
|
359
438
|
},
|
|
360
439
|
h(
|
|
@@ -406,28 +485,59 @@ G.Explorer = function Explorer(props) {
|
|
|
406
485
|
},
|
|
407
486
|
onDragOver: (event) => {
|
|
408
487
|
const types = event.dataTransfer?.types
|
|
409
|
-
if (types === undefined || types === null
|
|
488
|
+
if (types === undefined || types === null) return
|
|
489
|
+
const list = Array.from(types)
|
|
490
|
+
if (list.includes(GUFA_EXPLORER_MOVE_TYPE)) {
|
|
491
|
+
event.preventDefault()
|
|
492
|
+
event.stopPropagation()
|
|
493
|
+
if (event.dataTransfer !== null && event.dataTransfer !== undefined) event.dataTransfer.dropEffect = 'move'
|
|
494
|
+
setDragTarget(internalDropTargetDir(event.target))
|
|
495
|
+
return
|
|
496
|
+
}
|
|
497
|
+
if (!list.includes('Files')) return
|
|
410
498
|
event.preventDefault()
|
|
411
499
|
event.stopPropagation()
|
|
412
500
|
event.dataTransfer.dropEffect = 'copy'
|
|
413
501
|
},
|
|
502
|
+
onDragLeave: (event) => {
|
|
503
|
+
if (event.currentTarget instanceof Node && event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget)) return
|
|
504
|
+
setDragTarget(null)
|
|
505
|
+
},
|
|
414
506
|
onDrop: (event) => {
|
|
507
|
+
const types = event.dataTransfer?.types
|
|
508
|
+
if (types !== undefined && types !== null && Array.from(types).includes(GUFA_EXPLORER_MOVE_TYPE)) {
|
|
509
|
+
event.preventDefault()
|
|
510
|
+
event.stopPropagation()
|
|
511
|
+
const paths = internalDragRef.current
|
|
512
|
+
internalDragRef.current = null
|
|
513
|
+
const targetDir = internalDropTargetDir(event.target)
|
|
514
|
+
setDragTarget(null)
|
|
515
|
+
void moveEntries(paths, targetDir)
|
|
516
|
+
return
|
|
517
|
+
}
|
|
415
518
|
const files = event.dataTransfer?.files
|
|
416
519
|
if (files === undefined || files === null || files.length === 0) return
|
|
417
520
|
event.preventDefault()
|
|
418
521
|
event.stopPropagation()
|
|
419
522
|
void uploadFiles(files, dropTargetDir(event.target))
|
|
420
523
|
},
|
|
524
|
+
onClick: (event) => {
|
|
525
|
+
/* 点击资源管理器空白处:选中根目录,而不是保留上一次选中的文件/文件夹 */
|
|
526
|
+
if (!(event.target instanceof Element)) return
|
|
527
|
+
if (event.target.closest('[data-edrv-path]') !== null) return
|
|
528
|
+
if (event.target.closest('.gufa-panel-head, button, input, textarea, [role="menu"]') !== null) return
|
|
529
|
+
selectRoot()
|
|
530
|
+
},
|
|
421
531
|
onKeyDown: (event) => {
|
|
422
532
|
if (event.key === 'Enter') {
|
|
423
|
-
if (selected === null) return
|
|
533
|
+
if (selected === null || selected.path === '') return
|
|
424
534
|
event.preventDefault()
|
|
425
535
|
props.onRename?.(selected.path)
|
|
426
536
|
return
|
|
427
537
|
}
|
|
428
538
|
const mod = event.metaKey || event.ctrlKey
|
|
429
539
|
if (!mod || event.altKey) {
|
|
430
|
-
if (event.key === 'Delete' && selected !== null) {
|
|
540
|
+
if (event.key === 'Delete' && selected !== null && selected.path !== '') {
|
|
431
541
|
event.preventDefault()
|
|
432
542
|
props.onDelete?.(selected.path)
|
|
433
543
|
}
|
|
@@ -442,7 +552,7 @@ G.Explorer = function Explorer(props) {
|
|
|
442
552
|
void pasteInto(selectedDir())
|
|
443
553
|
} else if (key === 'backspace' || event.key === 'Delete') {
|
|
444
554
|
event.preventDefault()
|
|
445
|
-
if (selected !== null) props.onDelete?.(selected.path)
|
|
555
|
+
if (selected !== null && selected.path !== '') props.onDelete?.(selected.path)
|
|
446
556
|
}
|
|
447
557
|
},
|
|
448
558
|
},
|
|
@@ -462,6 +572,7 @@ G.Explorer = function Explorer(props) {
|
|
|
462
572
|
'div',
|
|
463
573
|
{
|
|
464
574
|
className: 'gufa-panel-body gufa-scroll',
|
|
575
|
+
'data-drop-root': dragTarget === '' ? '' : undefined,
|
|
465
576
|
onContextMenu: (event) => {
|
|
466
577
|
try {
|
|
467
578
|
if (event.target !== null && event.target !== undefined && typeof event.target.closest === 'function' && event.target.closest('.gufa-tree-row') !== null) return
|
|
@@ -261,6 +261,9 @@ function install(ctx) {
|
|
|
261
261
|
};
|
|
262
262
|
const onDrop = (event) => {
|
|
263
263
|
if (!isOurs(event.dataTransfer)) return;
|
|
264
|
+
/* 资源管理器内部拖拽移动文件:交给 Explorer 自己的 drop 处理,不当作 @ 引用插入 */
|
|
265
|
+
if (event.dataTransfer !== null && Array.prototype.indexOf.call(event.dataTransfer.types, "application/x-gufa-explorer-move") !== -1
|
|
266
|
+
&& event.target instanceof Element && event.target.closest(".gufa-sidepanel") !== null) return;
|
|
264
267
|
if (dropZoneOf(event.target) === null) {
|
|
265
268
|
toast("松手位置不在输入框内,未插入", "err");
|
|
266
269
|
return;
|
|
@@ -432,6 +432,14 @@ G.installShortcutIntegration = function installShortcutIntegration(service) {
|
|
|
432
432
|
const mac = G.isMacPlatform()
|
|
433
433
|
const primary = mac ? gesture?.meta === true && gesture?.control !== true : gesture?.control === true
|
|
434
434
|
if (primary && gesture?.code === 'KeyK' && gesture?.shift !== true && gesture?.alt !== true) {
|
|
435
|
+
try {
|
|
436
|
+
if ((window.__gufaDispatchRemapLogs ?? 0) < 20) {
|
|
437
|
+
window.__gufaDispatchRemapLogs = (window.__gufaDispatchRemapLogs ?? 0) + 1
|
|
438
|
+
void G.api('dev.log', { message: 'command-remap-dispatch KeyK -> clearTerminal' }).catch(() => {})
|
|
439
|
+
}
|
|
440
|
+
} catch {
|
|
441
|
+
/* ignore */
|
|
442
|
+
}
|
|
435
443
|
if (typeof consume === 'function') consume()
|
|
436
444
|
if (gesture?.repeat !== true) {
|
|
437
445
|
try { window.__gufaIdeShortcutDispatch('clearTerminal') } catch { /* ignore */ }
|
|
@@ -499,6 +507,65 @@ G.installShortcutIntegration = function installShortcutIntegration(service) {
|
|
|
499
507
|
/* 重试安装失败不影响主流程 */
|
|
500
508
|
}
|
|
501
509
|
|
|
510
|
+
/* ── 自愈:DSH 重连/切换会话/热重载可能重建命令表或丢掉 dispatch 补丁,
|
|
511
|
+
表现为「一开始 Cmd+K 好用,操作一阵后失效、重启客户端才恢复」。
|
|
512
|
+
每 1.5s 检查一次,发现补丁丢失就在 IDE 模式下自动重装。 ── */
|
|
513
|
+
try {
|
|
514
|
+
if (typeof window !== 'undefined' && window !== null) {
|
|
515
|
+
if (service.__gufaHealthTimer === undefined || service.__gufaHealthTimer === null) {
|
|
516
|
+
service.__gufaHealthTimer = window.setInterval(() => {
|
|
517
|
+
try {
|
|
518
|
+
if (G.mode.get() !== true) return
|
|
519
|
+
const registryNow = service.registry
|
|
520
|
+
if (registryNow === null || registryNow === undefined) return
|
|
521
|
+
const dispatchOk = registryNow.__gufaDispatchPatched === true
|
|
522
|
+
let wrapMissing = false
|
|
523
|
+
const commandsNow = registryNow.commands
|
|
524
|
+
if (commandsNow !== null && commandsNow !== undefined && typeof commandsNow.get === 'function') {
|
|
525
|
+
for (const id of Object.keys(service.__gufaCommandActions ?? {})) {
|
|
526
|
+
const command = commandsNow.get(id)
|
|
527
|
+
if (command !== null && command !== undefined && command.__gufaWrapped !== true) {
|
|
528
|
+
wrapMissing = true
|
|
529
|
+
break
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
if (dispatchOk && !wrapMissing) return
|
|
534
|
+
if ((service.__gufaHealthLogs ?? 0) < 20) {
|
|
535
|
+
service.__gufaHealthLogs = (service.__gufaHealthLogs ?? 0) + 1
|
|
536
|
+
void G.api('dev.log', {
|
|
537
|
+
message: `shortcut-health-heal dispatch=${dispatchOk} wrapMissing=${wrapMissing} mode=${G.mode.get() === true}`,
|
|
538
|
+
}).catch(() => {})
|
|
539
|
+
}
|
|
540
|
+
try {
|
|
541
|
+
G.installShortcutIntegration(service)
|
|
542
|
+
} catch {
|
|
543
|
+
/* ignore */
|
|
544
|
+
}
|
|
545
|
+
} catch {
|
|
546
|
+
/* ignore */
|
|
547
|
+
}
|
|
548
|
+
}, 1500)
|
|
549
|
+
}
|
|
550
|
+
if (service.__gufaCatalogSubscribed !== true && service.catalog !== null && service.catalog !== undefined && typeof service.catalog.subscribe === 'function') {
|
|
551
|
+
service.__gufaCatalogSubscribed = true
|
|
552
|
+
try {
|
|
553
|
+
service.catalog.subscribe(() => {
|
|
554
|
+
try {
|
|
555
|
+
if (G.mode.get() === true) G.installShortcutIntegration(service)
|
|
556
|
+
} catch {
|
|
557
|
+
/* ignore */
|
|
558
|
+
}
|
|
559
|
+
})
|
|
560
|
+
} catch {
|
|
561
|
+
/* ignore */
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
} catch {
|
|
566
|
+
/* ignore */
|
|
567
|
+
}
|
|
568
|
+
|
|
502
569
|
// ── 一次性自检:确认改派在 IDE 模式下真的会执行(不会影响经典模式)──
|
|
503
570
|
try {
|
|
504
571
|
if (typeof window !== 'undefined' && window !== null && window.sessionStorage !== undefined) {
|
package/src/client/90-app.js
CHANGED
|
@@ -351,6 +351,9 @@ G.GufaApp = function GufaApp(props) {
|
|
|
351
351
|
const [banner, setBanner] = useState('')
|
|
352
352
|
const [tabs, setTabs] = useState([])
|
|
353
353
|
const [activePath, setActivePath] = useState(null)
|
|
354
|
+
const activePathRef = useRef(activePath)
|
|
355
|
+
activePathRef.current = activePath
|
|
356
|
+
const pendingOpenAtRef = useRef(null)
|
|
354
357
|
/* 选区(给右侧 AI 用)单独更新;光标位置/行数走 G.cursorStore,避免每次按键重渲染整个 IDE。 */
|
|
355
358
|
const [selection, setSelection] = useState(null)
|
|
356
359
|
/* 编辑器内容缓冲:Monaco 每次按键只写这里,300ms 停顿后才同步进 tabs(保存/自动保存直接读缓冲)。 */
|
|
@@ -693,15 +696,31 @@ G.GufaApp = function GufaApp(props) {
|
|
|
693
696
|
await openFile(path)
|
|
694
697
|
const targetLine = Number.isFinite(Number(line)) ? Math.max(1, Math.trunc(Number(line))) : 1
|
|
695
698
|
const targetColumn = Number.isFinite(Number(column)) ? Math.max(1, Math.trunc(Number(column))) : 1
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
699
|
+
const target = { path, line: targetLine, column: targetColumn }
|
|
700
|
+
const currentActive = activePathRef.current === null ? null : gufaNormalizeProjectPath(activePathRef.current)
|
|
701
|
+
if (currentActive === path) {
|
|
702
|
+
/* 文件本来就打开着:编辑器/model 已就绪,延迟一帧即可 */
|
|
703
|
+
window.setTimeout(() => {
|
|
704
|
+
try { G.bus.emit('editor:reveal', target) } catch { /* ignore */ }
|
|
705
|
+
}, 80)
|
|
706
|
+
return
|
|
707
|
+
}
|
|
708
|
+
/* 文件未打开:交给 activePath effect,在 tab 真正切过去之后再 reveal(避免固定 120ms 的竞态) */
|
|
709
|
+
pendingOpenAtRef.current = target
|
|
703
710
|
}, [openFile])
|
|
704
711
|
|
|
712
|
+
/* 未打开文件跳转:activePath 切到目标文件后(子组件编辑器 effect 已先行)再发 reveal */
|
|
713
|
+
useEffect(() => {
|
|
714
|
+
const pending = pendingOpenAtRef.current
|
|
715
|
+
if (pending === null || pending === undefined) return undefined
|
|
716
|
+
if (activePath === null || gufaNormalizeProjectPath(activePath) !== gufaNormalizeProjectPath(pending.path)) return undefined
|
|
717
|
+
pendingOpenAtRef.current = null
|
|
718
|
+
const timer = window.setTimeout(() => {
|
|
719
|
+
try { G.bus.emit('editor:reveal', pending) } catch { /* ignore */ }
|
|
720
|
+
}, 40)
|
|
721
|
+
return () => window.clearTimeout(timer)
|
|
722
|
+
}, [activePath])
|
|
723
|
+
|
|
705
724
|
/* Cmd/Ctrl+点击定义:编辑器 → App 跳转 / 多结果选择(兜底搜索在 host/code.js) */
|
|
706
725
|
useEffect(() => {
|
|
707
726
|
if (G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function') return undefined
|
|
@@ -1098,13 +1117,25 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1098
1117
|
}
|
|
1099
1118
|
setBranchInput('')
|
|
1100
1119
|
setBranchMenu({ ...placement, repo: repoPath, loading: true, branches: [], error: '' })
|
|
1101
|
-
|
|
1120
|
+
const loadBranches = () => G.api('git.branches', { root: project.root, repo: repoPath })
|
|
1102
1121
|
.then((value) => {
|
|
1103
|
-
setBranchMenu((current) => (current === null
|
|
1122
|
+
setBranchMenu((current) => (current === null
|
|
1123
|
+
? current
|
|
1124
|
+
: {
|
|
1125
|
+
...current,
|
|
1126
|
+
loading: false,
|
|
1127
|
+
branches: Array.isArray(value?.branches) ? value.branches : [],
|
|
1128
|
+
remotes: Array.isArray(value?.remotes) ? value.remotes : [],
|
|
1129
|
+
}))
|
|
1104
1130
|
})
|
|
1105
1131
|
.catch((error) => {
|
|
1106
1132
|
setBranchMenu((current) => (current === null ? current : { ...current, loading: false, error: G.errorText(error) }))
|
|
1107
1133
|
})
|
|
1134
|
+
void loadBranches()
|
|
1135
|
+
/* 远端分支可能只在远端、本地还没 fetch:打开弹窗时后台 fetch 一次再刷新列表 */
|
|
1136
|
+
void G.api('git.fetch', { root: project.root, repo: repoPath })
|
|
1137
|
+
.catch(() => {})
|
|
1138
|
+
.then(() => loadBranches())
|
|
1108
1139
|
}, [project])
|
|
1109
1140
|
|
|
1110
1141
|
const closeBranchMenu = useCallback(() => {
|
|
@@ -1130,10 +1161,10 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1130
1161
|
}
|
|
1131
1162
|
}, [branchMenu, closeBranchMenu])
|
|
1132
1163
|
|
|
1133
|
-
const checkoutBranch = useCallback(async (name) => {
|
|
1164
|
+
const checkoutBranch = useCallback(async (name, remote) => {
|
|
1134
1165
|
if (project === null || typeof name !== 'string' || name === '') return
|
|
1135
1166
|
try {
|
|
1136
|
-
await G.api('git.checkout', { root: project.root, repo: branchMenu?.repo, branch: name })
|
|
1167
|
+
await G.api('git.checkout', { root: project.root, repo: branchMenu?.repo, branch: name, remote: remote === true })
|
|
1137
1168
|
closeBranchMenu()
|
|
1138
1169
|
setGitRefreshToken((token) => token + 1)
|
|
1139
1170
|
setRefreshToken((token) => token + 1)
|
|
@@ -3190,21 +3221,45 @@ G.GufaApp = function GufaApp(props) {
|
|
|
3190
3221
|
{ className: 'gufa-branch-dialog-list gufa-scroll' },
|
|
3191
3222
|
...(branchMenu.loading === true
|
|
3192
3223
|
? []
|
|
3193
|
-
:
|
|
3194
|
-
|
|
3195
|
-
'
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3224
|
+
: [
|
|
3225
|
+
branchMenu.branches.length > 0
|
|
3226
|
+
? h('div', { className: 'gufa-branch-group' }, t('git.branchesLocal'))
|
|
3227
|
+
: null,
|
|
3228
|
+
...branchMenu.branches.map((branch) =>
|
|
3229
|
+
h(
|
|
3230
|
+
'button',
|
|
3231
|
+
{
|
|
3232
|
+
key: `l:${branch.name}`,
|
|
3233
|
+
type: 'button',
|
|
3234
|
+
className: 'gufa-branch-row',
|
|
3235
|
+
'data-current': branch.current === true ? '' : undefined,
|
|
3236
|
+
onClick: () => void checkoutBranch(branch.name),
|
|
3237
|
+
},
|
|
3238
|
+
h(G.Icon, { name: branch.current === true ? 'check' : 'branch', size: 13 }),
|
|
3239
|
+
h('span', { className: 'gufa-branch-name' }, branch.name),
|
|
3240
|
+
branch.current === true ? h('span', { className: 'gufa-branch-tag' }, t('git.branchCurrent')) : null,
|
|
3241
|
+
),
|
|
3242
|
+
),
|
|
3243
|
+
Array.isArray(branchMenu.remotes) && branchMenu.remotes.length > 0
|
|
3244
|
+
? h('div', { className: 'gufa-branch-group' }, t('git.branchesRemote'))
|
|
3245
|
+
: null,
|
|
3246
|
+
...(Array.isArray(branchMenu.remotes) ? branchMenu.remotes : []).map((branch) =>
|
|
3247
|
+
h(
|
|
3248
|
+
'button',
|
|
3249
|
+
{
|
|
3250
|
+
key: `r:${branch.name}`,
|
|
3251
|
+
type: 'button',
|
|
3252
|
+
className: 'gufa-branch-row',
|
|
3253
|
+
'data-remote': '',
|
|
3254
|
+
title: `${branch.name} → ${branch.short}(创建本地跟踪分支)`,
|
|
3255
|
+
onClick: () => void checkoutBranch(branch.name, true),
|
|
3256
|
+
},
|
|
3257
|
+
h(G.Icon, { name: 'cloud', size: 13 }),
|
|
3258
|
+
h('span', { className: 'gufa-branch-name' }, branch.name),
|
|
3259
|
+
h('span', { className: 'gufa-branch-tag', 'data-kind': 'remote' }, t('git.branchRemoteTag')),
|
|
3260
|
+
),
|
|
3206
3261
|
),
|
|
3207
|
-
)
|
|
3262
|
+
]),
|
|
3208
3263
|
),
|
|
3209
3264
|
h(
|
|
3210
3265
|
'div',
|