dsh-gufa-code 1.3.117 → 1.3.133
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 +2 -2
- package/client.js +563 -101
- package/desktop/float/bin/gufa-float-macos-arm64 +0 -0
- package/desktop/float/bin/gufa-float-macos-universal +0 -0
- package/desktop/float/bin/gufa-float-macos-x64 +0 -0
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/Info.plist +2 -2
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/MacOS/gufa-float +0 -0
- package/docs/KNOWN-PITFALLS.md +56 -0
- package/docs/RELEASE.md +14 -5
- package/host/fs.js +24 -0
- package/host/lint.js +8 -1
- package/host/ts-definition.js +212 -0
- package/package.json +1 -1
- package/scripts/selftest-host.mjs +44 -0
- package/src/client/00-core.js +2 -0
- package/src/client/20-editor.js +328 -86
- package/src/client/30-terminal.js +10 -1
- package/src/client/60-dock.js +55 -0
- package/src/client/90-app.js +167 -13
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.133'
|
|
20
20
|
G.PANEL_ID = 'gufa-code'
|
|
21
21
|
/** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
|
|
22
22
|
G.pendingEntryWorkspace = null
|
|
@@ -1692,6 +1692,8 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
|
|
|
1692
1692
|
.gufa-breadcrumb b{font-weight:500;color:var(--gufa-text)}
|
|
1693
1693
|
.gufa-editor-host{flex:1 1 auto;position:relative;min-height:0;min-width:0;overflow:hidden}
|
|
1694
1694
|
.gufa-def-link{text-decoration:underline;text-decoration-color:var(--gufa-accent);text-decoration-thickness:1px;text-underline-offset:2px;cursor:pointer}
|
|
1695
|
+
/* Cmd 悬停:只变正经链接蓝,不下划线、不弹框 */
|
|
1696
|
+
.gufa-def-link-color{color:#4aa8ff!important;text-decoration:none!important;cursor:pointer}
|
|
1695
1697
|
.monaco-editor.gufa-def-hover .view-lines{cursor:pointer}
|
|
1696
1698
|
.gufa-editor-fallback{position:absolute;inset:0;overflow:auto;margin:0;padding:14px 18px;font:12.5px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre;tab-size:2}
|
|
1697
1699
|
.gufa-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;height:100%;padding:28px;
|
|
@@ -3029,6 +3031,146 @@ G.registerTemplateLanguages = function registerTemplateLanguages(monaco) {
|
|
|
3029
3031
|
const GUFA_LSP_WARMED = new Set()
|
|
3030
3032
|
const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'def', 'func', 'fn', 'type', 'export', 'lsp'])
|
|
3031
3033
|
|
|
3034
|
+
/* ── 原生 DefinitionProvider + editor opener ─────────────────────────
|
|
3035
|
+
* Cmd+点击 / F12 都交给 Monaco 自己的 `editor.action.revealDefinition`;
|
|
3036
|
+
* 定义解析走 Host API(JS/TS 用 code.definition,Python 用 pyright 的 lsp.definition),
|
|
3037
|
+
* 打开文件由 registerEditorOpener 转成 App 的 editor:open-at,多个结果交给 Monaco 原生 peek。
|
|
3038
|
+
*/
|
|
3039
|
+
/* JS/TS 的 F12 交回 Monaco 原生 TS DefinitionProvider(之前被我们关掉过);
|
|
3040
|
+
Cmd+点击在 click handler 里直接走 Host LanguageService 以拿到最准结果。 */
|
|
3041
|
+
const GUFA_DEFINITION_LANGUAGES = ['python']
|
|
3042
|
+
function gufaRegisterDefinitionInfrastructure(monaco) {
|
|
3043
|
+
try {
|
|
3044
|
+
if (monaco === null || monaco === undefined) return
|
|
3045
|
+
if (G.__gufaDefinitionInfra === true) return
|
|
3046
|
+
if (monaco.languages === null || monaco.languages === undefined || typeof monaco.languages.registerDefinitionProvider !== 'function') return
|
|
3047
|
+
G.__gufaDefinitionInfra = true
|
|
3048
|
+
const rootAt = () => (typeof G.projectRoot === 'string' ? G.projectRoot.replace(/\\/g, '/').replace(/\/+$/, '') : '')
|
|
3049
|
+
const pathOfModel = (model) => {
|
|
3050
|
+
const root = rootAt()
|
|
3051
|
+
if (root === '' || model === null || model === undefined) return null
|
|
3052
|
+
let absolute = ''
|
|
3053
|
+
try {
|
|
3054
|
+
absolute = model.uri?.fsPath ?? (typeof model.uri?.path === 'string' ? decodeURIComponent(model.uri.path) : '')
|
|
3055
|
+
} catch {
|
|
3056
|
+
return null
|
|
3057
|
+
}
|
|
3058
|
+
absolute = String(absolute).replace(/\\/g, '/')
|
|
3059
|
+
if (!absolute.startsWith(`${root}/`)) return null
|
|
3060
|
+
return { root, path: absolute.slice(root.length + 1) }
|
|
3061
|
+
}
|
|
3062
|
+
const locationsOf = (root, matches, word, monacoNs) => {
|
|
3063
|
+
const list = Array.isArray(matches) ? matches : []
|
|
3064
|
+
const result = []
|
|
3065
|
+
const seen = new Set()
|
|
3066
|
+
for (const match of list.slice(0, 10)) {
|
|
3067
|
+
if (match === null || typeof match !== 'object' || typeof match.path !== 'string') continue
|
|
3068
|
+
/* TS lib 定义(parseInt/Promise 等)走 readTsLib 只读标签,不交给 Monaco 原生动作 */
|
|
3069
|
+
if (match.external === true || typeof match.absolutePath === 'string') continue
|
|
3070
|
+
const line = Math.max(1, Math.trunc(Number(match.line) || 1))
|
|
3071
|
+
const column = Math.max(1, Math.trunc(Number(match.column) || 1))
|
|
3072
|
+
const key = `${match.path}:${line}:${column}`
|
|
3073
|
+
if (seen.has(key)) continue
|
|
3074
|
+
seen.add(key)
|
|
3075
|
+
const uri = gufaModelUri(monacoNs, root, match.path)
|
|
3076
|
+
const range = new monacoNs.Range(line, column, line, column + Math.max(1, word.length))
|
|
3077
|
+
result.push({ uri, range })
|
|
3078
|
+
}
|
|
3079
|
+
return result
|
|
3080
|
+
}
|
|
3081
|
+
for (const language of GUFA_DEFINITION_LANGUAGES) {
|
|
3082
|
+
try {
|
|
3083
|
+
monaco.languages.registerDefinitionProvider(language, {
|
|
3084
|
+
async provideDefinition(model, position, token) {
|
|
3085
|
+
if (token !== null && token !== undefined && token.isCancellationRequested === true) return []
|
|
3086
|
+
const info = pathOfModel(model)
|
|
3087
|
+
if (info === null) return []
|
|
3088
|
+
const wordInfo = typeof model.getWordAtPosition === 'function' ? model.getWordAtPosition(position) : null
|
|
3089
|
+
const word = wordInfo !== null && wordInfo !== undefined && typeof wordInfo.word === 'string' ? wordInfo.word : ''
|
|
3090
|
+
try {
|
|
3091
|
+
let result = null
|
|
3092
|
+
if (language === 'python') {
|
|
3093
|
+
result = await G.api('lsp.definition', {
|
|
3094
|
+
root: info.root,
|
|
3095
|
+
path: info.path,
|
|
3096
|
+
line: position.lineNumber,
|
|
3097
|
+
column: position.column,
|
|
3098
|
+
language: 'python',
|
|
3099
|
+
content: model.getValue(),
|
|
3100
|
+
})
|
|
3101
|
+
} else {
|
|
3102
|
+
/* LanguageService 解析定义(TS 编译器),比正则项目搜索准确;
|
|
3103
|
+
JS/TS 不再回退到 code.definition,避免“宁可跳错也不空着”。 */
|
|
3104
|
+
result = await G.api('code.tsDefinition', {
|
|
3105
|
+
root: info.root,
|
|
3106
|
+
path: info.path,
|
|
3107
|
+
line: position.lineNumber,
|
|
3108
|
+
column: position.column,
|
|
3109
|
+
content: model.getValue(),
|
|
3110
|
+
})
|
|
3111
|
+
}
|
|
3112
|
+
if (token !== null && token !== undefined && token.isCancellationRequested === true) return []
|
|
3113
|
+
return locationsOf(info.root, result !== null && result !== undefined ? result.matches : null, word, monaco)
|
|
3114
|
+
} catch {
|
|
3115
|
+
return []
|
|
3116
|
+
}
|
|
3117
|
+
},
|
|
3118
|
+
})
|
|
3119
|
+
} catch {
|
|
3120
|
+
/* 单个语言注册失败不影响其它语言 */
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
try {
|
|
3124
|
+
if (typeof monaco.editor.registerEditorOpener === 'function') {
|
|
3125
|
+
monaco.editor.registerEditorOpener({
|
|
3126
|
+
openCodeEditor(source, resource, selectionOrPosition) {
|
|
3127
|
+
const root = rootAt()
|
|
3128
|
+
if (root === '') return false
|
|
3129
|
+
let absolute = ''
|
|
3130
|
+
try {
|
|
3131
|
+
absolute = resource?.fsPath ?? (typeof resource?.path === 'string' ? decodeURIComponent(resource.path) : '')
|
|
3132
|
+
} catch {
|
|
3133
|
+
return false
|
|
3134
|
+
}
|
|
3135
|
+
absolute = String(absolute).replace(/\\/g, '/')
|
|
3136
|
+
const selection = selectionOrPosition !== null && selectionOrPosition !== undefined && selectionOrPosition.selection !== undefined
|
|
3137
|
+
? selectionOrPosition.selection
|
|
3138
|
+
: selectionOrPosition
|
|
3139
|
+
const line = Math.max(1, Math.trunc(Number(selection?.startLineNumber ?? selection?.lineNumber ?? 1) || 1))
|
|
3140
|
+
const column = Math.max(1, Math.trunc(Number(selection?.startColumn ?? selection?.column ?? 1) || 1))
|
|
3141
|
+
if (absolute.startsWith(`${root}/`)) {
|
|
3142
|
+
try {
|
|
3143
|
+
G.bus.emit('editor:open-at', { path: absolute.slice(root.length + 1), line, column })
|
|
3144
|
+
} catch {
|
|
3145
|
+
return false
|
|
3146
|
+
}
|
|
3147
|
+
return true
|
|
3148
|
+
}
|
|
3149
|
+
/* 系统内置 API 的定义在 TS worker 的 lib 里(parseInt 等):按 basename 交给只读标签打开 */
|
|
3150
|
+
const baseName = absolute.slice(absolute.lastIndexOf('/') + 1)
|
|
3151
|
+
if (/^lib\.[A-Za-z0-9._-]+\.d\.ts$/.test(baseName)) {
|
|
3152
|
+
try {
|
|
3153
|
+
G.bus.emit('editor:open-external', { absolutePath: '', libName: baseName, path: baseName, line, column })
|
|
3154
|
+
} catch {
|
|
3155
|
+
return false
|
|
3156
|
+
}
|
|
3157
|
+
return true
|
|
3158
|
+
}
|
|
3159
|
+
return false
|
|
3160
|
+
},
|
|
3161
|
+
})
|
|
3162
|
+
}
|
|
3163
|
+
} catch {
|
|
3164
|
+
/* ignore */
|
|
3165
|
+
}
|
|
3166
|
+
} catch {
|
|
3167
|
+
/* ignore */
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3171
|
+
/* 诊断波浪线已关闭(用户要求);Host lint 也不再在每次输入后跑 tsc,省 CPU */
|
|
3172
|
+
const GUFA_LINT_ENABLED = false
|
|
3173
|
+
|
|
3032
3174
|
/* ── model / URI ────────────────────────────────────────────────────── */
|
|
3033
3175
|
|
|
3034
3176
|
/**
|
|
@@ -3363,13 +3505,32 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3363
3505
|
} catch (error) {
|
|
3364
3506
|
/* 模板语言注册失败不影响编辑器 */
|
|
3365
3507
|
}
|
|
3366
|
-
|
|
3367
|
-
|
|
3508
|
+
try {
|
|
3509
|
+
gufaRegisterDefinitionInfrastructure(monaco)
|
|
3510
|
+
} catch {
|
|
3511
|
+
/* ignore */
|
|
3512
|
+
}
|
|
3513
|
+
/* 错误诊断恢复 Monaco 原生 TS worker:语法/语义/类型错误都正常画线。
|
|
3514
|
+
Monaco 的 javascriptDefaults 默认关掉了 JS 语义诊断(noSemanticValidation=true),
|
|
3515
|
+
这里显式打开并开 checkJs,否则 .js 里只有语法错误、没有未定义变量等诊断。 */
|
|
3368
3516
|
try {
|
|
3369
3517
|
const typescriptLanguages = monaco.languages.typescript
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3518
|
+
if (typescriptLanguages !== null && typescriptLanguages !== undefined) {
|
|
3519
|
+
const diagnosticsOn = { noSemanticValidation: false, noSyntaxValidation: false }
|
|
3520
|
+
typescriptLanguages.typescriptDefaults?.setDiagnosticsOptions(diagnosticsOn)
|
|
3521
|
+
typescriptLanguages.javascriptDefaults?.setDiagnosticsOptions(diagnosticsOn)
|
|
3522
|
+
typescriptLanguages.javascriptDefaults?.setCompilerOptions({
|
|
3523
|
+
allowNonTsExtensions: true,
|
|
3524
|
+
allowJs: true,
|
|
3525
|
+
checkJs: true,
|
|
3526
|
+
target: 99,
|
|
3527
|
+
moduleResolution: 2,
|
|
3528
|
+
module: 99,
|
|
3529
|
+
jsx: 1,
|
|
3530
|
+
esModuleInterop: true,
|
|
3531
|
+
allowSyntheticDefaultImports: true,
|
|
3532
|
+
})
|
|
3533
|
+
}
|
|
3373
3534
|
} catch (error) {
|
|
3374
3535
|
/* ignore */
|
|
3375
3536
|
}
|
|
@@ -3535,8 +3696,9 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3535
3696
|
/* ignore */
|
|
3536
3697
|
}
|
|
3537
3698
|
}
|
|
3699
|
+
/* Cmd 悬停只给单词换颜色(蓝色),不加下划线、不弹原生 link 提示框。 */
|
|
3538
3700
|
const showHoverDecoration = (position, wordInfo) => {
|
|
3539
|
-
if (wordInfo === null || wordInfo === undefined) return clearHoverDecoration()
|
|
3701
|
+
if (wordInfo === null || wordInfo === undefined || position === null || position === undefined) return clearHoverDecoration()
|
|
3540
3702
|
let range = null
|
|
3541
3703
|
try {
|
|
3542
3704
|
range = new monaco.Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn)
|
|
@@ -3545,68 +3707,28 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3545
3707
|
}
|
|
3546
3708
|
try {
|
|
3547
3709
|
hover.decorationIds = instance.deltaDecorations(hover.decorationIds, [
|
|
3548
|
-
{ range, options: { inlineClassName: 'gufa-def-link', stickiness: 1 } },
|
|
3710
|
+
{ range, options: { inlineClassName: 'gufa-def-link-color', stickiness: 1 } },
|
|
3549
3711
|
])
|
|
3550
3712
|
} catch {
|
|
3551
3713
|
/* ignore */
|
|
3552
3714
|
}
|
|
3553
|
-
try {
|
|
3554
|
-
editorDom.classList.add('gufa-def-hover')
|
|
3555
|
-
} catch {
|
|
3556
|
-
/* ignore */
|
|
3557
|
-
}
|
|
3558
3715
|
}
|
|
3559
3716
|
const evaluateHoverPosition = (position, wordInfo) => {
|
|
3560
3717
|
if (!hover.meta) {
|
|
3561
3718
|
clearHoverDecoration()
|
|
3562
3719
|
return
|
|
3563
3720
|
}
|
|
3564
|
-
const model = instance.getModel()
|
|
3565
3721
|
const word = wordInfo !== null && wordInfo !== undefined && typeof wordInfo.word === 'string' ? wordInfo.word : ''
|
|
3566
|
-
|
|
3567
|
-
const root = modelsRootRef.current
|
|
3568
|
-
if (position === null || position === undefined || model === null || model === undefined
|
|
3569
|
-
|| word.length < 2 || path === null || path === undefined || root === null || root === undefined || root === '') {
|
|
3722
|
+
if (position === null || position === undefined || word.length < 2) {
|
|
3570
3723
|
clearHoverDecoration()
|
|
3571
3724
|
return
|
|
3572
3725
|
}
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
const key = `${
|
|
3726
|
+
/* 不再为了下划线去跑项目级定义搜索:按住 Cmd 立刻标出当前单词,
|
|
3727
|
+
真正解析只发生在点击时。之前 hover 的 host 扫描是「难用/卡」的主要来源。 */
|
|
3728
|
+
const key = `${position.lineNumber}:${wordInfo.startColumn}:${wordInfo.endColumn}`
|
|
3729
|
+
if (hover.lastKey === key && hover.decorationIds.length > 0) return
|
|
3576
3730
|
hover.lastKey = key
|
|
3577
|
-
|
|
3578
|
-
if (cached === 'none') {
|
|
3579
|
-
clearHoverDecoration()
|
|
3580
|
-
return
|
|
3581
|
-
}
|
|
3582
|
-
if (cached === 'yes') {
|
|
3583
|
-
showHoverDecoration(position, wordInfo)
|
|
3584
|
-
return
|
|
3585
|
-
}
|
|
3586
|
-
if (hover.timer !== 0) {
|
|
3587
|
-
window.clearTimeout(hover.timer)
|
|
3588
|
-
hover.timer = 0
|
|
3589
|
-
}
|
|
3590
|
-
const seq = ++hover.seq
|
|
3591
|
-
hover.timer = window.setTimeout(() => {
|
|
3592
|
-
hover.timer = 0
|
|
3593
|
-
if (!hover.meta || seq !== hover.seq) return
|
|
3594
|
-
void queryDefinitions(position, word, model, path, root).then((result) => {
|
|
3595
|
-
if (!hover.meta || seq !== hover.seq || hover.lastKey !== key) return
|
|
3596
|
-
const decision = decideDefinition(result)
|
|
3597
|
-
if (decision.kind === 'none') {
|
|
3598
|
-
if (hover.cache.size > 100) hover.cache.clear()
|
|
3599
|
-
hover.cache.set(key, 'none')
|
|
3600
|
-
clearHoverDecoration()
|
|
3601
|
-
return
|
|
3602
|
-
}
|
|
3603
|
-
if (hover.cache.size > 100) hover.cache.clear()
|
|
3604
|
-
hover.cache.set(key, 'yes')
|
|
3605
|
-
showHoverDecoration(position, wordInfo)
|
|
3606
|
-
}).catch(() => {
|
|
3607
|
-
/* ignore */
|
|
3608
|
-
})
|
|
3609
|
-
}, 130)
|
|
3731
|
+
showHoverDecoration(position, wordInfo)
|
|
3610
3732
|
}
|
|
3611
3733
|
/* 用 Monaco 自己的 onMouseMove(带修饰键状态 + 精确 position),
|
|
3612
3734
|
不依赖 DOM mousedown/getTargetAtClientPoint 的坐标系与包含关系。 */
|
|
@@ -3717,13 +3839,66 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3717
3839
|
} catch {
|
|
3718
3840
|
/* ignore */
|
|
3719
3841
|
}
|
|
3842
|
+
/* Cmd+点击直接用 Host 的准确解析,避免依赖 Monaco 原生 action/worker:
|
|
3843
|
+
- JS/TS:TypeScript LanguageService(含 parseInt 等系统 lib);
|
|
3844
|
+
- Python:pyright lsp.definition。 */
|
|
3845
|
+
const clickLanguage = typeof model.getLanguageId === 'function' ? model.getLanguageId() : ''
|
|
3846
|
+
if (clickLanguage === 'javascript' || clickLanguage === 'typescript') {
|
|
3847
|
+
try {
|
|
3848
|
+
const resolved = await G.api('code.tsDefinition', {
|
|
3849
|
+
root,
|
|
3850
|
+
path,
|
|
3851
|
+
line: position.lineNumber,
|
|
3852
|
+
column: position.column,
|
|
3853
|
+
content: model.getValue(),
|
|
3854
|
+
})
|
|
3855
|
+
const matches = resolved !== null && resolved !== undefined && Array.isArray(resolved.matches) ? resolved.matches : []
|
|
3856
|
+
const internal = matches.find((item) => item !== null && item !== undefined && item.external !== true && typeof item.path === 'string' && item.path !== '')
|
|
3857
|
+
if (internal !== undefined) {
|
|
3858
|
+
G.bus.emit('editor:open-at', { path: internal.path, line: internal.line, column: internal.column })
|
|
3859
|
+
} else {
|
|
3860
|
+
const external = matches.find((item) => item !== null && item !== undefined && item.external === true && typeof item.absolutePath === 'string')
|
|
3861
|
+
if (external !== undefined) {
|
|
3862
|
+
G.bus.emit('editor:open-external', {
|
|
3863
|
+
absolutePath: external.absolutePath,
|
|
3864
|
+
path: typeof external.path === 'string' ? external.path : '',
|
|
3865
|
+
line: external.line,
|
|
3866
|
+
column: external.column,
|
|
3867
|
+
})
|
|
3868
|
+
}
|
|
3869
|
+
}
|
|
3870
|
+
} catch {
|
|
3871
|
+
/* 解析失败不跳错 */
|
|
3872
|
+
}
|
|
3873
|
+
clearHoverDecoration()
|
|
3874
|
+
return
|
|
3875
|
+
}
|
|
3876
|
+
if (clickLanguage === 'python') {
|
|
3877
|
+
try {
|
|
3878
|
+
const resolved = await G.api('lsp.definition', {
|
|
3879
|
+
root,
|
|
3880
|
+
path,
|
|
3881
|
+
line: position.lineNumber,
|
|
3882
|
+
column: position.column,
|
|
3883
|
+
language: 'python',
|
|
3884
|
+
content: model.getValue(),
|
|
3885
|
+
})
|
|
3886
|
+
const matches = resolved !== null && resolved !== undefined && Array.isArray(resolved.matches) ? resolved.matches : []
|
|
3887
|
+
const first = matches.find((item) => item !== null && item !== undefined && typeof item.path === 'string' && item.path !== '')
|
|
3888
|
+
if (first !== undefined) G.bus.emit('editor:open-at', { path: first.path, line: first.line, column: first.column })
|
|
3889
|
+
} catch {
|
|
3890
|
+
/* ignore */
|
|
3891
|
+
}
|
|
3892
|
+
clearHoverDecoration()
|
|
3893
|
+
return
|
|
3894
|
+
}
|
|
3895
|
+
/* 其它语言:保留 Monaco 原生 action 兜底 */
|
|
3720
3896
|
try {
|
|
3721
|
-
|
|
3897
|
+
instance.focus()
|
|
3898
|
+
instance.setPosition(position)
|
|
3722
3899
|
} catch {
|
|
3723
3900
|
/* ignore */
|
|
3724
3901
|
}
|
|
3725
|
-
const beforePath = modelPathRef.current
|
|
3726
|
-
const beforePosition = instance.getPosition()
|
|
3727
3902
|
try {
|
|
3728
3903
|
const action = typeof instance.getAction === 'function' ? instance.getAction('editor.action.revealDefinition') : null
|
|
3729
3904
|
if (action !== null && action !== undefined) {
|
|
@@ -3733,37 +3908,8 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3733
3908
|
} catch {
|
|
3734
3909
|
/* ignore */
|
|
3735
3910
|
}
|
|
3736
|
-
await new Promise((resolve) => { window.setTimeout(resolve,
|
|
3737
|
-
let monacoHandled = false
|
|
3738
|
-
try {
|
|
3739
|
-
const afterPosition = instance.getPosition()
|
|
3740
|
-
monacoHandled = modelPathRef.current !== beforePath
|
|
3741
|
-
|| (beforePosition !== null && beforePosition !== undefined && afterPosition !== null && afterPosition !== undefined
|
|
3742
|
-
&& (afterPosition.lineNumber !== beforePosition.lineNumber || afterPosition.column !== beforePosition.column))
|
|
3743
|
-
|| document.querySelector('.monaco-editor .peekview-widget, .monaco-editor .reference-zone-widget') !== null
|
|
3744
|
-
} catch {
|
|
3745
|
-
monacoHandled = false
|
|
3746
|
-
}
|
|
3911
|
+
await new Promise((resolve) => { window.setTimeout(resolve, 200) })
|
|
3747
3912
|
clearHoverDecoration()
|
|
3748
|
-
if (monacoHandled) return
|
|
3749
|
-
try {
|
|
3750
|
-
const result = await queryDefinitions(position, word, model, path, root)
|
|
3751
|
-
const decision = decideDefinition(result)
|
|
3752
|
-
if (decision.kind === 'open') {
|
|
3753
|
-
G.bus.emit('editor:open-at', { path: decision.match.path, line: decision.match.line, column: decision.match.column })
|
|
3754
|
-
return
|
|
3755
|
-
}
|
|
3756
|
-
if (decision.kind === 'pick') {
|
|
3757
|
-
G.bus.emit('definition:pick', {
|
|
3758
|
-
word: result !== null && result !== undefined && typeof result.word === 'string' ? result.word : word,
|
|
3759
|
-
matches: decision.matches,
|
|
3760
|
-
x: event.clientX,
|
|
3761
|
-
y: event.clientY,
|
|
3762
|
-
})
|
|
3763
|
-
}
|
|
3764
|
-
} catch {
|
|
3765
|
-
/* ignore */
|
|
3766
|
-
}
|
|
3767
3913
|
}
|
|
3768
3914
|
document.addEventListener('mousedown', onDefinitionClick, true)
|
|
3769
3915
|
document.addEventListener('keydown', onMetaDown, true)
|
|
@@ -3789,6 +3935,88 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3789
3935
|
} catch {
|
|
3790
3936
|
/* ignore */
|
|
3791
3937
|
}
|
|
3938
|
+
/* 外部/AI 修改磁盘后由 App 轮询发现,通过 bus 通知编辑器热替换 model 内容。
|
|
3939
|
+
(1.3.117 删 AI Tab 时误删过这一段,1.3.125 恢复) */
|
|
3940
|
+
try {
|
|
3941
|
+
if (G.bus !== null && G.bus !== undefined && typeof G.bus.on === 'function') {
|
|
3942
|
+
const offExternalReload = G.bus.on('editor:external-reload', (detail) => {
|
|
3943
|
+
if (detail === null || detail === undefined || typeof detail.path !== 'string' || typeof detail.content !== 'string') return
|
|
3944
|
+
const target = modelsRef.current.get(detail.path)
|
|
3945
|
+
if (target === null || target === undefined) return
|
|
3946
|
+
let content = ''
|
|
3947
|
+
try {
|
|
3948
|
+
content = target.getValue()
|
|
3949
|
+
} catch {
|
|
3950
|
+
return
|
|
3951
|
+
}
|
|
3952
|
+
if (content === detail.content) return
|
|
3953
|
+
const active = modelPathRef.current === detail.path
|
|
3954
|
+
let position = null
|
|
3955
|
+
let scrollTop = 0
|
|
3956
|
+
if (active) {
|
|
3957
|
+
try {
|
|
3958
|
+
position = instance.getPosition()
|
|
3959
|
+
scrollTop = instance.getScrollTop()
|
|
3960
|
+
} catch {
|
|
3961
|
+
position = null
|
|
3962
|
+
}
|
|
3963
|
+
}
|
|
3964
|
+
suppressChangeRef.current = true
|
|
3965
|
+
try {
|
|
3966
|
+
target.setValue(detail.content)
|
|
3967
|
+
} finally {
|
|
3968
|
+
suppressChangeRef.current = false
|
|
3969
|
+
}
|
|
3970
|
+
lastPropContentRef.current.set(detail.path, detail.content)
|
|
3971
|
+
if (active && position !== null && position !== undefined) {
|
|
3972
|
+
try {
|
|
3973
|
+
instance.setPosition(position)
|
|
3974
|
+
instance.setScrollTop(scrollTop)
|
|
3975
|
+
} catch {
|
|
3976
|
+
/* ignore */
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
3979
|
+
})
|
|
3980
|
+
if (typeof offExternalReload === 'function') subscriptions.push({ dispose: offExternalReload })
|
|
3981
|
+
}
|
|
3982
|
+
} catch {
|
|
3983
|
+
/* ignore */
|
|
3984
|
+
}
|
|
3985
|
+
|
|
3986
|
+
/* 拖拽分割条期间暂停 Monaco automaticLayout:
|
|
3987
|
+
宽度每帧变化时 Monaco layout() 会跟着重排整块编辑器,是「不跟手」的大头;
|
|
3988
|
+
拖拽先只动容器/别的面板,松手后再 layout 一次。 */
|
|
3989
|
+
try {
|
|
3990
|
+
if (G.bus !== null && G.bus !== undefined && typeof G.bus.on === 'function') {
|
|
3991
|
+
const offResizeStart = G.bus.on('layout:resize-start', () => {
|
|
3992
|
+
try {
|
|
3993
|
+
instance.updateOptions({ automaticLayout: false })
|
|
3994
|
+
} catch {
|
|
3995
|
+
/* ignore */
|
|
3996
|
+
}
|
|
3997
|
+
})
|
|
3998
|
+
const offResizeEnd = G.bus.on('layout:resize-end', () => {
|
|
3999
|
+
const relayout = () => {
|
|
4000
|
+
try {
|
|
4001
|
+
instance.updateOptions({ automaticLayout: true })
|
|
4002
|
+
instance.layout()
|
|
4003
|
+
} catch {
|
|
4004
|
+
/* ignore */
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
if (typeof requestAnimationFrame === 'function') {
|
|
4008
|
+
requestAnimationFrame(() => requestAnimationFrame(relayout))
|
|
4009
|
+
} else {
|
|
4010
|
+
window.setTimeout(relayout, 32)
|
|
4011
|
+
}
|
|
4012
|
+
})
|
|
4013
|
+
if (typeof offResizeStart === 'function') subscriptions.push({ dispose: offResizeStart })
|
|
4014
|
+
if (typeof offResizeEnd === 'function') subscriptions.push({ dispose: offResizeEnd })
|
|
4015
|
+
}
|
|
4016
|
+
} catch {
|
|
4017
|
+
/* ignore */
|
|
4018
|
+
}
|
|
4019
|
+
|
|
3792
4020
|
G.__gufaEditorDebug = {
|
|
3793
4021
|
focus: () => {
|
|
3794
4022
|
try {
|
|
@@ -3852,6 +4080,7 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3852
4080
|
lintTimers.clear()
|
|
3853
4081
|
}
|
|
3854
4082
|
const runLint = async (model, path) => {
|
|
4083
|
+
if (GUFA_LINT_ENABLED !== true) return
|
|
3855
4084
|
if (model === null || model === undefined || typeof path !== 'string' || path === '') return
|
|
3856
4085
|
const language = typeof model.getLanguageId === 'function' ? model.getLanguageId() : ''
|
|
3857
4086
|
if (language !== 'javascript' && language !== 'typescript') return
|
|
@@ -3889,6 +4118,7 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3889
4118
|
}
|
|
3890
4119
|
}
|
|
3891
4120
|
const scheduleLint = (model, path) => {
|
|
4121
|
+
if (GUFA_LINT_ENABLED !== true) return
|
|
3892
4122
|
if (model === null || model === undefined || typeof path !== 'string' || path === '') return
|
|
3893
4123
|
const previous = lintTimers.get(path)
|
|
3894
4124
|
if (previous !== undefined) window.clearTimeout(previous)
|
|
@@ -3979,6 +4209,20 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3979
4209
|
}
|
|
3980
4210
|
}, [attempt, reportCursor, disposeAllModels])
|
|
3981
4211
|
|
|
4212
|
+
/* TS 内置 lib(parseInt 等)标签是只读预览 */
|
|
4213
|
+
const activeExternal = activeTab !== null && activeTab.external === true
|
|
4214
|
+
useEffect(() => {
|
|
4215
|
+
if (status !== 'ready') return undefined
|
|
4216
|
+
const instance = editorRef.current
|
|
4217
|
+
if (instance === null || instance === undefined) return undefined
|
|
4218
|
+
try {
|
|
4219
|
+
instance.updateOptions({ readOnly: activeExternal })
|
|
4220
|
+
} catch {
|
|
4221
|
+
/* ignore */
|
|
4222
|
+
}
|
|
4223
|
+
return undefined
|
|
4224
|
+
}, [activeExternal, status])
|
|
4225
|
+
|
|
3982
4226
|
/* ── 同步 tabs ↔ models,并切换当前 model ──────────────────────── */
|
|
3983
4227
|
useEffect(() => {
|
|
3984
4228
|
if (status !== 'ready') return
|
|
@@ -5156,6 +5400,8 @@ function GufaTerminalView(props) {
|
|
|
5156
5400
|
|
|
5157
5401
|
const fitNow = () => {
|
|
5158
5402
|
if (fit === null || term === null || disposed) return
|
|
5403
|
+
/* 拖分割条时尺寸每帧都在变,xterm.fit() 很重;等 layout:resize-end 一次算到位 */
|
|
5404
|
+
if (G.__gufaSplitterDragging === true) return
|
|
5159
5405
|
const host = hostRef.current
|
|
5160
5406
|
if (host === null || host.clientWidth <= 0 || host.clientHeight <= 0) return
|
|
5161
5407
|
try {
|
|
@@ -5557,12 +5803,19 @@ function GufaTerminalView(props) {
|
|
|
5557
5803
|
openFrame = window.requestAnimationFrame(tryOpen)
|
|
5558
5804
|
}
|
|
5559
5805
|
props.register(terminalId, channel)
|
|
5806
|
+
const offLayoutEnd = G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function'
|
|
5807
|
+
? () => {}
|
|
5808
|
+
: G.bus.on('layout:resize-end', () => {
|
|
5809
|
+
fitNow()
|
|
5810
|
+
sendCurrentSize()
|
|
5811
|
+
})
|
|
5560
5812
|
|
|
5561
5813
|
startStream()
|
|
5562
5814
|
if (mode === 'xterm') tryOpen()
|
|
5563
5815
|
|
|
5564
5816
|
return () => {
|
|
5565
5817
|
disposed = true
|
|
5818
|
+
try { offLayoutEnd() } catch { /* ignore */ }
|
|
5566
5819
|
if (retryTimer !== null) clearTimeout(retryTimer)
|
|
5567
5820
|
if (replayTimer !== null) clearTimeout(replayTimer)
|
|
5568
5821
|
if (openFrame !== 0) window.cancelAnimationFrame(openFrame)
|
|
@@ -6087,7 +6340,7 @@ G.TerminalPane = function TerminalPane(props) {
|
|
|
6087
6340
|
{
|
|
6088
6341
|
className: 'gufa-termpane',
|
|
6089
6342
|
style: {
|
|
6090
|
-
height,
|
|
6343
|
+
height: `var(--gufa-h-terminal, ${height}px)`,
|
|
6091
6344
|
flex: '0 0 auto',
|
|
6092
6345
|
display: 'flex',
|
|
6093
6346
|
flexDirection: 'column',
|
|
@@ -10968,6 +11221,31 @@ G.ChatDock = function ChatDock(props) {
|
|
|
10968
11221
|
}
|
|
10969
11222
|
}, [active, undock, props.backdrop])
|
|
10970
11223
|
|
|
11224
|
+
/* 拖拽分割条时的轻量重定位:只改宿主几何,不 getComputedStyle、不读自身 rect、不 setState。
|
|
11225
|
+
完整 tick 每次都会 getComputedStyle + 最多两次 getBoundingClientRect,按帧跑会把拖拽拖卡。 */
|
|
11226
|
+
const lightTickRef = useRef(null)
|
|
11227
|
+
const lightTick = useCallback(() => {
|
|
11228
|
+
const host = hostRef.current
|
|
11229
|
+
if (host === null) return
|
|
11230
|
+
const root = dockRef.current.root
|
|
11231
|
+
if (root === null) return
|
|
11232
|
+
try {
|
|
11233
|
+
const rect = host.getBoundingClientRect()
|
|
11234
|
+
if (!(rect.width >= 80 && rect.height >= 80)) return
|
|
11235
|
+
root.style.position = 'fixed'
|
|
11236
|
+
root.style.left = `${Math.round(rect.left)}px`
|
|
11237
|
+
root.style.top = `${Math.round(rect.top)}px`
|
|
11238
|
+
root.style.width = `${Math.round(rect.width)}px`
|
|
11239
|
+
root.style.height = `${Math.round(rect.height)}px`
|
|
11240
|
+
root.style.setProperty('--dsh-conversation-column-width', `${Math.round(rect.width)}px`)
|
|
11241
|
+
} catch {
|
|
11242
|
+
/* ignore */
|
|
11243
|
+
}
|
|
11244
|
+
}, [])
|
|
11245
|
+
useEffect(() => {
|
|
11246
|
+
lightTickRef.current = lightTick
|
|
11247
|
+
}, [lightTick])
|
|
11248
|
+
|
|
10971
11249
|
useEffect(() => {
|
|
10972
11250
|
tickRef.current = tick
|
|
10973
11251
|
}, [tick])
|
|
@@ -11012,6 +11290,36 @@ G.ChatDock = function ChatDock(props) {
|
|
|
11012
11290
|
tickRef.current?.()
|
|
11013
11291
|
}, [props.width, props.backdrop])
|
|
11014
11292
|
|
|
11293
|
+
// 拖拽过程中宽高每帧变化(App 不重渲染),DSH 浮层需要跟着宿主矩形逐帧重定位
|
|
11294
|
+
useEffect(() => {
|
|
11295
|
+
if (G.bus === undefined || G.bus === null || typeof G.bus.on !== 'function') return undefined
|
|
11296
|
+
let frame = 0
|
|
11297
|
+
let lastTickAt = 0
|
|
11298
|
+
const off = G.bus.on('layout:resize', (detail) => {
|
|
11299
|
+
/* 只有横向聊天栏/宽度变化才需要动 DSH 浮层;终端高度拖拽不用每帧重定位 */
|
|
11300
|
+
const varName = detail !== null && detail !== undefined && typeof detail.varName === 'string' ? detail.varName : ''
|
|
11301
|
+
if (varName !== '' && varName !== '--gufa-w-chat') return
|
|
11302
|
+
/* 拖拽中 20fps 足够跟上视觉;每帧 getBoundingClientRect 会强制布局,反而拖慢分割条 */
|
|
11303
|
+
const now = Date.now()
|
|
11304
|
+
if (now - lastTickAt < 45) return
|
|
11305
|
+
lastTickAt = now
|
|
11306
|
+
if (frame !== 0) return
|
|
11307
|
+
frame = typeof requestAnimationFrame === 'function' ? requestAnimationFrame(() => {
|
|
11308
|
+
frame = 0
|
|
11309
|
+
lightTickRef.current?.()
|
|
11310
|
+
}) : window.setTimeout(() => { frame = 0; lightTickRef.current?.() }, 16)
|
|
11311
|
+
})
|
|
11312
|
+
return () => {
|
|
11313
|
+
try { off?.() } catch { /* ignore */ }
|
|
11314
|
+
if (frame !== 0) {
|
|
11315
|
+
try {
|
|
11316
|
+
if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)
|
|
11317
|
+
else window.clearTimeout(frame)
|
|
11318
|
+
} catch { /* ignore */ }
|
|
11319
|
+
}
|
|
11320
|
+
}
|
|
11321
|
+
}, [])
|
|
11322
|
+
|
|
11015
11323
|
const newSession = useCallback(() => {
|
|
11016
11324
|
const ui = G.ctx === null || G.ctx === undefined ? undefined : G.ctx.get('uiWorkspace')
|
|
11017
11325
|
if (ui === undefined || ui === null || typeof ui.startSession !== 'function') {
|
|
@@ -11959,30 +12267,106 @@ function selectSessionCwd(state) {
|
|
|
11959
12267
|
return picked?.projectionValues?.workingDirectory ?? picked?.cwd ?? null
|
|
11960
12268
|
}
|
|
11961
12269
|
|
|
11962
|
-
/** 可拖拽尺寸 hook:返回 [size, onMouseDown, setSize]。
|
|
12270
|
+
/** 可拖拽尺寸 hook:返回 [size, onMouseDown, setSize]。
|
|
12271
|
+
* 拖拽过程只改根节点 CSS 变量(rAF 合帧),不触发 GufaApp 整棵树重渲染;
|
|
12272
|
+
* 松手时才 setSize 一次,避免拖边框卡顿。 */
|
|
11963
12273
|
G.useSplitter = function useSplitter(options) {
|
|
11964
|
-
const { initial, min, max, axis = 'x', invert = false, storageKey } = options
|
|
12274
|
+
const { initial, min, max, axis = 'x', invert = false, storageKey, cssVar, targetSelector } = options
|
|
11965
12275
|
const [size, setSize] = useState(() => {
|
|
11966
12276
|
const stored = storageKey === undefined ? null : Number(localStorage.getItem(storageKey))
|
|
11967
12277
|
return Number.isFinite(stored) && stored > 0 ? Math.min(max, Math.max(min, stored)) : initial
|
|
11968
12278
|
})
|
|
12279
|
+
const findTarget = () => {
|
|
12280
|
+
if (typeof targetSelector !== 'string' || targetSelector === '') return null
|
|
12281
|
+
try {
|
|
12282
|
+
return typeof document !== 'undefined' ? document.querySelector(targetSelector) : null
|
|
12283
|
+
} catch {
|
|
12284
|
+
return null
|
|
12285
|
+
}
|
|
12286
|
+
}
|
|
12287
|
+
const applyToTarget = (target, value) => {
|
|
12288
|
+
if (target === null || target === undefined) return false
|
|
12289
|
+
try {
|
|
12290
|
+
if (axis === 'x') target.style.width = `${value}px`
|
|
12291
|
+
else target.style.height = `${value}px`
|
|
12292
|
+
return true
|
|
12293
|
+
} catch {
|
|
12294
|
+
return false
|
|
12295
|
+
}
|
|
12296
|
+
}
|
|
12297
|
+
/* 初始/恢复持久化尺寸:直接写目标元素,不往 documentElement 挂 CSS 变量
|
|
12298
|
+
(根节点自定义属性变化会让整棵文档(含 Monaco/DSH)样式重算,拖拽时非常伤) */
|
|
12299
|
+
React.useLayoutEffect(() => {
|
|
12300
|
+
const target = findTarget()
|
|
12301
|
+
if (!applyToTarget(target, size)) {
|
|
12302
|
+
if (typeof cssVar !== 'string' || cssVar === '') return
|
|
12303
|
+
try {
|
|
12304
|
+
document.documentElement.style.setProperty(cssVar, `${size}px`)
|
|
12305
|
+
} catch {
|
|
12306
|
+
/* ignore */
|
|
12307
|
+
}
|
|
12308
|
+
}
|
|
12309
|
+
return undefined
|
|
12310
|
+
}, [cssVar, size])
|
|
11969
12311
|
const onMouseDown = useCallback((event) => {
|
|
11970
12312
|
if (event.button !== 0) return
|
|
11971
12313
|
event.preventDefault()
|
|
12314
|
+
const splitter = event.currentTarget
|
|
12315
|
+
const target = findTarget()
|
|
11972
12316
|
const startPosition = axis === 'x' ? event.clientX : event.clientY
|
|
11973
12317
|
const startSize = size
|
|
11974
12318
|
let latest = size
|
|
11975
|
-
|
|
11976
|
-
|
|
11977
|
-
|
|
12319
|
+
let frame = 0
|
|
12320
|
+
let pendingPosition = null
|
|
12321
|
+
const applySize = () => {
|
|
12322
|
+
frame = 0
|
|
12323
|
+
if (pendingPosition === null) return
|
|
12324
|
+
const delta = (pendingPosition - startPosition) * (invert ? -1 : 1)
|
|
11978
12325
|
latest = Math.min(max, Math.max(min, startSize + delta))
|
|
11979
|
-
|
|
12326
|
+
pendingPosition = null
|
|
12327
|
+
/* 只改目标元素自身的 width/height:不发散到整个 root 的 CSS 变量 */
|
|
12328
|
+
if (!applyToTarget(target, latest)) {
|
|
12329
|
+
try {
|
|
12330
|
+
if (typeof cssVar === 'string' && cssVar !== '') document.documentElement.style.setProperty(cssVar, `${latest}px`)
|
|
12331
|
+
} catch {
|
|
12332
|
+
/* ignore */
|
|
12333
|
+
}
|
|
12334
|
+
}
|
|
12335
|
+
/* 聊天栏是 DSH 原生浮层,需要跟着宿主矩形重新定位;终端/Monaco 各自有 ResizeObserver */
|
|
12336
|
+
try {
|
|
12337
|
+
G.bus.emit('layout:resize', { varName: cssVar ?? '', size: latest })
|
|
12338
|
+
} catch {
|
|
12339
|
+
/* ignore */
|
|
12340
|
+
}
|
|
12341
|
+
}
|
|
12342
|
+
const onMove = (moveEvent) => {
|
|
12343
|
+
pendingPosition = axis === 'x' ? moveEvent.clientX : moveEvent.clientY
|
|
12344
|
+
if (frame === 0) {
|
|
12345
|
+
frame = typeof requestAnimationFrame === 'function' ? requestAnimationFrame(applySize) : window.setTimeout(applySize, 16)
|
|
12346
|
+
}
|
|
11980
12347
|
}
|
|
11981
12348
|
const onUp = () => {
|
|
11982
12349
|
window.removeEventListener('mousemove', onMove)
|
|
11983
12350
|
window.removeEventListener('mouseup', onUp)
|
|
12351
|
+
window.removeEventListener('blur', onUp)
|
|
12352
|
+
if (frame !== 0) {
|
|
12353
|
+
try {
|
|
12354
|
+
if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)
|
|
12355
|
+
else window.clearTimeout(frame)
|
|
12356
|
+
} catch {
|
|
12357
|
+
/* ignore */
|
|
12358
|
+
}
|
|
12359
|
+
frame = 0
|
|
12360
|
+
}
|
|
12361
|
+
if (pendingPosition !== null) applySize()
|
|
12362
|
+
setSize(latest)
|
|
11984
12363
|
document.body.style.cursor = ''
|
|
11985
12364
|
document.body.style.userSelect = ''
|
|
12365
|
+
try {
|
|
12366
|
+
if (splitter !== null && splitter !== undefined && typeof splitter.removeAttribute === 'function') splitter.removeAttribute('data-dragging')
|
|
12367
|
+
} catch {
|
|
12368
|
+
/* ignore */
|
|
12369
|
+
}
|
|
11986
12370
|
if (storageKey !== undefined) {
|
|
11987
12371
|
try {
|
|
11988
12372
|
localStorage.setItem(storageKey, String(latest))
|
|
@@ -11990,12 +12374,30 @@ G.useSplitter = function useSplitter(options) {
|
|
|
11990
12374
|
/* ignore */
|
|
11991
12375
|
}
|
|
11992
12376
|
}
|
|
12377
|
+
G.__gufaSplitterDragging = false
|
|
12378
|
+
try {
|
|
12379
|
+
G.bus.emit('layout:resize-end', { varName: cssVar ?? '', size: latest })
|
|
12380
|
+
} catch {
|
|
12381
|
+
/* ignore */
|
|
12382
|
+
}
|
|
12383
|
+
}
|
|
12384
|
+
try {
|
|
12385
|
+
if (splitter !== null && splitter !== undefined && typeof splitter.setAttribute === 'function') splitter.setAttribute('data-dragging', '')
|
|
12386
|
+
} catch {
|
|
12387
|
+
/* ignore */
|
|
11993
12388
|
}
|
|
11994
12389
|
document.body.style.cursor = axis === 'x' ? 'col-resize' : 'row-resize'
|
|
11995
12390
|
document.body.style.userSelect = 'none'
|
|
12391
|
+
G.__gufaSplitterDragging = true
|
|
12392
|
+
try {
|
|
12393
|
+
G.bus.emit('layout:resize-start', { varName: cssVar ?? '' })
|
|
12394
|
+
} catch {
|
|
12395
|
+
/* ignore */
|
|
12396
|
+
}
|
|
11996
12397
|
window.addEventListener('mousemove', onMove)
|
|
11997
12398
|
window.addEventListener('mouseup', onUp)
|
|
11998
|
-
|
|
12399
|
+
window.addEventListener('blur', onUp)
|
|
12400
|
+
}, [axis, cssVar, invert, max, min, size, storageKey])
|
|
11999
12401
|
return [size, onMouseDown, setSize]
|
|
12000
12402
|
}
|
|
12001
12403
|
|
|
@@ -12159,9 +12561,9 @@ G.GufaApp = function GufaApp(props) {
|
|
|
12159
12561
|
const [modalPending, setModalPending] = useState(false)
|
|
12160
12562
|
const [modalError, setModalError] = useState('')
|
|
12161
12563
|
const bootedRef = useRef(false)
|
|
12162
|
-
const [explorerWidth, explorerDrag] = G.useSplitter({ initial: 260, min: 190, max: 520, storageKey: 'gufa-code:w:explorer' })
|
|
12163
|
-
const [chatWidth, chatDrag] = G.useSplitter({ initial: 430, min: 320, max: 780, axis: 'x', invert: true, storageKey: 'gufa-code:w:chat' })
|
|
12164
|
-
const [terminalHeight, terminalDrag] = G.useSplitter({ initial: 230, min: 120, max: 560, axis: 'y', invert: true, storageKey: 'gufa-code:h:terminal' })
|
|
12564
|
+
const [explorerWidth, explorerDrag] = G.useSplitter({ initial: 260, min: 190, max: 520, storageKey: 'gufa-code:w:explorer', cssVar: '--gufa-w-explorer', targetSelector: '.gufa-sidepanel' })
|
|
12565
|
+
const [chatWidth, chatDrag] = G.useSplitter({ initial: 430, min: 320, max: 780, axis: 'x', invert: true, storageKey: 'gufa-code:w:chat', cssVar: '--gufa-w-chat', targetSelector: '.gufa-chatpane' })
|
|
12566
|
+
const [terminalHeight, terminalDrag] = G.useSplitter({ initial: 230, min: 120, max: 560, axis: 'y', invert: true, storageKey: 'gufa-code:h:terminal', cssVar: '--gufa-h-terminal', targetSelector: '.gufa-termpane' })
|
|
12165
12567
|
useEffect(() => {
|
|
12166
12568
|
tabsRef.current = tabs
|
|
12167
12569
|
}, [tabs])
|
|
@@ -12588,6 +12990,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
12588
12990
|
if (project === null) return
|
|
12589
12991
|
const tab = tabsRef.current.find((item) => item !== null && item.path === path)
|
|
12590
12992
|
if (tab === undefined) return
|
|
12993
|
+
if (tab.external === true) return
|
|
12591
12994
|
/* 缓冲里可能有比 tabs 更新的内容(按键后 300ms 内保存/自动保存) */
|
|
12592
12995
|
const content = editorBuffersRef.current.has(path) ? editorBuffersRef.current.get(path) : tab.content
|
|
12593
12996
|
if (content === tab.savedContent) {
|
|
@@ -13039,6 +13442,65 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13039
13442
|
}
|
|
13040
13443
|
}, [project, tabs, patchTab, refreshGit, t])
|
|
13041
13444
|
|
|
13445
|
+
/* TS 内置 lib 定义(parseInt/Promise 等):以只读标签打开 */
|
|
13446
|
+
const openExternalTab = useCallback(async (detail) => {
|
|
13447
|
+
if (detail === null || detail === undefined) return
|
|
13448
|
+
const absolutePath = typeof detail.absolutePath === 'string' ? detail.absolutePath : ''
|
|
13449
|
+
const libName = typeof detail.libName === 'string' ? detail.libName : ''
|
|
13450
|
+
if (absolutePath === '' && libName === '') return
|
|
13451
|
+
const relative = libName !== ''
|
|
13452
|
+
? libName
|
|
13453
|
+
: (typeof detail.path === 'string' && detail.path !== '' ? detail.path.replace(/^\/+/, '') : 'lib.d.ts')
|
|
13454
|
+
const pseudoPath = `~typescript/${relative}`
|
|
13455
|
+
flushBuffersRef.current?.()
|
|
13456
|
+
const existing = (tabsRef.current ?? []).find((tab) => tab !== null && tab !== undefined && tab.path === pseudoPath)
|
|
13457
|
+
if (existing !== undefined) {
|
|
13458
|
+
setActivePath(pseudoPath)
|
|
13459
|
+
window.setTimeout(() => {
|
|
13460
|
+
try {
|
|
13461
|
+
G.bus.emit('editor:reveal', { path: pseudoPath, line: Number(detail.line) || 1, column: Number(detail.column) || 1 })
|
|
13462
|
+
} catch {
|
|
13463
|
+
/* ignore */
|
|
13464
|
+
}
|
|
13465
|
+
}, 120)
|
|
13466
|
+
return
|
|
13467
|
+
}
|
|
13468
|
+
const doc = await G.api('code.readTsLib', libName !== '' ? { libName } : { absolutePath })
|
|
13469
|
+
const content = doc !== null && doc !== undefined && typeof doc.content === 'string' ? doc.content : ''
|
|
13470
|
+
const tab = {
|
|
13471
|
+
path: pseudoPath,
|
|
13472
|
+
content,
|
|
13473
|
+
savedContent: content,
|
|
13474
|
+
revision: 'external',
|
|
13475
|
+
savedRevision: 'external',
|
|
13476
|
+
dirty: false,
|
|
13477
|
+
size: content.length,
|
|
13478
|
+
language: doc !== null && doc !== undefined && typeof doc.language === 'string' ? doc.language : 'typescript',
|
|
13479
|
+
external: true,
|
|
13480
|
+
absolutePath: detail.absolutePath,
|
|
13481
|
+
name: doc !== null && doc !== undefined && typeof doc.name === 'string' ? doc.name : pseudoPath,
|
|
13482
|
+
}
|
|
13483
|
+
setTabs((current) => (current.some((item) => item !== null && item !== undefined && item.path === pseudoPath) ? current : [...current, tab]))
|
|
13484
|
+
setActivePath(pseudoPath)
|
|
13485
|
+
window.setTimeout(() => {
|
|
13486
|
+
try {
|
|
13487
|
+
G.bus.emit('editor:reveal', { path: pseudoPath, line: Number(detail.line) || 1, column: Number(detail.column) || 1 })
|
|
13488
|
+
} catch {
|
|
13489
|
+
/* ignore */
|
|
13490
|
+
}
|
|
13491
|
+
}, 120)
|
|
13492
|
+
}, [])
|
|
13493
|
+
|
|
13494
|
+
useEffect(() => {
|
|
13495
|
+
if (G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function') return undefined
|
|
13496
|
+
const offExternal = G.bus.on('editor:open-external', (detail) => {
|
|
13497
|
+
void openExternalTab(detail).catch((error) => setBanner(G.errorText(error)))
|
|
13498
|
+
})
|
|
13499
|
+
return () => {
|
|
13500
|
+
offExternal?.()
|
|
13501
|
+
}
|
|
13502
|
+
}, [openExternalTab])
|
|
13503
|
+
|
|
13042
13504
|
/* 自动保存:dirty 后 700ms 静默保存(普通文件 / 工作树 diff / 两文件对比) */
|
|
13043
13505
|
const saveFileRef = useRef(null)
|
|
13044
13506
|
const saveCompareRef = useRef(null)
|
|
@@ -14338,7 +14800,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
14338
14800
|
{
|
|
14339
14801
|
className: 'gufa-root',
|
|
14340
14802
|
'data-backdrop': backdropActive ? 'on' : undefined,
|
|
14341
|
-
style: { '--gufa-dock-width': ui.chatOpen ?
|
|
14803
|
+
style: { '--gufa-dock-width': ui.chatOpen ? `var(--gufa-w-chat, ${Math.round(chatWidth)}px)` : '0px' },
|
|
14342
14804
|
},
|
|
14343
14805
|
backdropActive ? h(G.SkinBackdrop, { meta: skinBackdrop, enabled: true, strength: backdropStrength }) : null,
|
|
14344
14806
|
h(
|
|
@@ -14473,7 +14935,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
14473
14935
|
? null
|
|
14474
14936
|
: h(
|
|
14475
14937
|
'div',
|
|
14476
|
-
{ className: 'gufa-sidepanel', style: { width: explorerWidth } },
|
|
14938
|
+
{ className: 'gufa-sidepanel', style: { width: `var(--gufa-w-explorer, ${explorerWidth}px)` } },
|
|
14477
14939
|
h('div', { style: { flex: '1 1 auto', minHeight: 0, display: 'flex', flexDirection: 'column' } }, leftPanel),
|
|
14478
14940
|
),
|
|
14479
14941
|
ui.sidebarOpen === false ? null : h('div', { className: 'gufa-splitter', onMouseDown: explorerDrag, title: '' }),
|
|
@@ -14555,7 +15017,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
14555
15017
|
h('div', { className: 'gufa-splitter', onMouseDown: chatDrag }),
|
|
14556
15018
|
h(
|
|
14557
15019
|
'div',
|
|
14558
|
-
{ className: 'gufa-chatpane', style: { width: chatWidth } },
|
|
15020
|
+
{ className: 'gufa-chatpane', style: { width: `var(--gufa-w-chat, ${chatWidth}px)` } },
|
|
14559
15021
|
h(G.ChatDock, {
|
|
14560
15022
|
project,
|
|
14561
15023
|
activeFile: activeFileForChat,
|