dsh-gufa-code 1.3.118 → 1.3.173
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 +826 -108
- 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 +76 -0
- package/docs/RELEASE.md +14 -5
- package/host/code.js +41 -0
- package/host/fs.js +35 -0
- package/host/lint.js +152 -2
- package/host/ts-definition.js +212 -0
- package/package.json +2 -1
- package/scripts/selftest-host.mjs +54 -2
- package/scripts/test-editor.mjs +3 -3
- package/src/client/00-core.js +13 -0
- package/src/client/20-editor.js +383 -86
- package/src/client/30-terminal.js +10 -1
- package/src/client/55-backdrop.js +51 -0
- package/src/client/60-dock.js +199 -6
- package/src/client/90-app.js +169 -14
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.173'
|
|
20
20
|
G.PANEL_ID = 'gufa-code'
|
|
21
21
|
/** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
|
|
22
22
|
G.pendingEntryWorkspace = null
|
|
@@ -1161,6 +1161,7 @@ G.errorText = (error) => {
|
|
|
1161
1161
|
G.CSS = `
|
|
1162
1162
|
.gufa-overlay-root{position:fixed;inset:0;z-index:1;display:flex;box-sizing:border-box;background:var(--gufa-solid-bg, var(--dsw-alias-bg-base));pointer-events:auto;overflow:hidden}
|
|
1163
1163
|
.gufa-backdrop{position:absolute;inset:0;z-index:0;overflow:hidden;pointer-events:none}
|
|
1164
|
+
|
|
1164
1165
|
/* 桌面悬浮层(摸鱼)模式:整窗半透明,透明度由 --gufa-float-alpha 控制(标题栏滑块) */
|
|
1165
1166
|
html[data-gufa-float]{--gufa-float-alpha:0.55}
|
|
1166
1167
|
html[data-gufa-float] body{background:transparent!important;color-scheme:dark;
|
|
@@ -1301,7 +1302,17 @@ html[data-gufa-float] #root [data-gufa-dock],
|
|
|
1301
1302
|
html[data-gufa-float] #root .gufa-overlay-root *,
|
|
1302
1303
|
html[data-gufa-float] #root [data-gufa-dock] *{visibility:visible!important}
|
|
1303
1304
|
/* 桌宠提到覆盖层之上:同时兼容 @linxin666/dsh-pet(data-dsh-pet-root)与官方 dsh-pet(.dsh-pet-root) */
|
|
1305
|
+
/* 古法覆盖层打开时,DSH 右侧栏被覆盖却仍参与 layout/paint;
|
|
1306
|
+
myrta 这类会话会给右侧栏渲染 7000+ 节点,导致编辑器滚动每帧 style/layout 50ms。 */
|
|
1307
|
+
html[data-gufa-ide] [class*="rightbarCol"],
|
|
1308
|
+
html[data-gufa-float] [class*="rightbarCol"]{display:none!important}
|
|
1309
|
+
|
|
1304
1310
|
html[data-gufa-ide] .dsh-pet-root{z-index:2147483050!important}
|
|
1311
|
+
/* 聊天栏收起时,把覆盖层下面的官方会话(可能几千个 DOM 节点)真正隐藏,
|
|
1312
|
+
避免编辑器滚动时整页 layout/paint 把它一起算进去。 */
|
|
1313
|
+
/* 古法/摸鱼模式下皮肤自身的粒子 canvas 不参与绘制(防止 WebGL/rAF 在覆盖层下面持续跑) */
|
|
1314
|
+
html[data-gufa-ide] .liang-ambient,
|
|
1315
|
+
html[data-gufa-float] .liang-ambient{display:none!important}
|
|
1305
1316
|
/* 外部弹窗(DSH 设置等)打开时:停靠会话、古法 portal、桌宠全部降到官方弹窗之下 */
|
|
1306
1317
|
html[data-gufa-external-modal] [data-gufa-dock]{z-index:2!important}
|
|
1307
1318
|
html[data-gufa-external-modal] #gufa-portal-root{z-index:1!important}
|
|
@@ -1692,6 +1703,8 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
|
|
|
1692
1703
|
.gufa-breadcrumb b{font-weight:500;color:var(--gufa-text)}
|
|
1693
1704
|
.gufa-editor-host{flex:1 1 auto;position:relative;min-height:0;min-width:0;overflow:hidden}
|
|
1694
1705
|
.gufa-def-link{text-decoration:underline;text-decoration-color:var(--gufa-accent);text-decoration-thickness:1px;text-underline-offset:2px;cursor:pointer}
|
|
1706
|
+
/* Cmd 悬停:只变正经链接蓝,不下划线、不弹框 */
|
|
1707
|
+
.gufa-def-link-color{color:#4aa8ff!important;text-decoration:none!important;cursor:pointer}
|
|
1695
1708
|
.monaco-editor.gufa-def-hover .view-lines{cursor:pointer}
|
|
1696
1709
|
.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
1710
|
.gufa-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;height:100%;padding:28px;
|
|
@@ -2756,6 +2769,9 @@ G.registerTemplateLanguages = function registerTemplateLanguages(monaco) {
|
|
|
2756
2769
|
'editorLink.activeForeground': gufaHex(accent),
|
|
2757
2770
|
'editorInfo.foreground': gufaHex(accent),
|
|
2758
2771
|
'editorOverviewRuler.border': '#00000000',
|
|
2772
|
+
'editorOverviewRuler.findMatchForeground': dark ? '#d7ba7d' : '#b58900',
|
|
2773
|
+
'editorOverviewRuler.errorForeground': '#f14c4c',
|
|
2774
|
+
'editorOverviewRuler.warningForeground': '#cca700',
|
|
2759
2775
|
'scrollbarSlider.background': gufaHexAlpha(fg, 0.16),
|
|
2760
2776
|
'scrollbarSlider.hoverBackground': gufaHexAlpha(fg, 0.26),
|
|
2761
2777
|
'scrollbarSlider.activeBackground': gufaHexAlpha(fg, 0.34),
|
|
@@ -3029,6 +3045,146 @@ G.registerTemplateLanguages = function registerTemplateLanguages(monaco) {
|
|
|
3029
3045
|
const GUFA_LSP_WARMED = new Set()
|
|
3030
3046
|
const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'def', 'func', 'fn', 'type', 'export', 'lsp'])
|
|
3031
3047
|
|
|
3048
|
+
/* ── 原生 DefinitionProvider + editor opener ─────────────────────────
|
|
3049
|
+
* Cmd+点击 / F12 都交给 Monaco 自己的 `editor.action.revealDefinition`;
|
|
3050
|
+
* 定义解析走 Host API(JS/TS 用 code.definition,Python 用 pyright 的 lsp.definition),
|
|
3051
|
+
* 打开文件由 registerEditorOpener 转成 App 的 editor:open-at,多个结果交给 Monaco 原生 peek。
|
|
3052
|
+
*/
|
|
3053
|
+
/* JS/TS 的 F12 交回 Monaco 原生 TS DefinitionProvider(之前被我们关掉过);
|
|
3054
|
+
Cmd+点击在 click handler 里直接走 Host LanguageService 以拿到最准结果。 */
|
|
3055
|
+
const GUFA_DEFINITION_LANGUAGES = ['python']
|
|
3056
|
+
function gufaRegisterDefinitionInfrastructure(monaco) {
|
|
3057
|
+
try {
|
|
3058
|
+
if (monaco === null || monaco === undefined) return
|
|
3059
|
+
if (G.__gufaDefinitionInfra === true) return
|
|
3060
|
+
if (monaco.languages === null || monaco.languages === undefined || typeof monaco.languages.registerDefinitionProvider !== 'function') return
|
|
3061
|
+
G.__gufaDefinitionInfra = true
|
|
3062
|
+
const rootAt = () => (typeof G.projectRoot === 'string' ? G.projectRoot.replace(/\\/g, '/').replace(/\/+$/, '') : '')
|
|
3063
|
+
const pathOfModel = (model) => {
|
|
3064
|
+
const root = rootAt()
|
|
3065
|
+
if (root === '' || model === null || model === undefined) return null
|
|
3066
|
+
let absolute = ''
|
|
3067
|
+
try {
|
|
3068
|
+
absolute = model.uri?.fsPath ?? (typeof model.uri?.path === 'string' ? decodeURIComponent(model.uri.path) : '')
|
|
3069
|
+
} catch {
|
|
3070
|
+
return null
|
|
3071
|
+
}
|
|
3072
|
+
absolute = String(absolute).replace(/\\/g, '/')
|
|
3073
|
+
if (!absolute.startsWith(`${root}/`)) return null
|
|
3074
|
+
return { root, path: absolute.slice(root.length + 1) }
|
|
3075
|
+
}
|
|
3076
|
+
const locationsOf = (root, matches, word, monacoNs) => {
|
|
3077
|
+
const list = Array.isArray(matches) ? matches : []
|
|
3078
|
+
const result = []
|
|
3079
|
+
const seen = new Set()
|
|
3080
|
+
for (const match of list.slice(0, 10)) {
|
|
3081
|
+
if (match === null || typeof match !== 'object' || typeof match.path !== 'string') continue
|
|
3082
|
+
/* TS lib 定义(parseInt/Promise 等)走 readTsLib 只读标签,不交给 Monaco 原生动作 */
|
|
3083
|
+
if (match.external === true || typeof match.absolutePath === 'string') continue
|
|
3084
|
+
const line = Math.max(1, Math.trunc(Number(match.line) || 1))
|
|
3085
|
+
const column = Math.max(1, Math.trunc(Number(match.column) || 1))
|
|
3086
|
+
const key = `${match.path}:${line}:${column}`
|
|
3087
|
+
if (seen.has(key)) continue
|
|
3088
|
+
seen.add(key)
|
|
3089
|
+
const uri = gufaModelUri(monacoNs, root, match.path)
|
|
3090
|
+
const range = new monacoNs.Range(line, column, line, column + Math.max(1, word.length))
|
|
3091
|
+
result.push({ uri, range })
|
|
3092
|
+
}
|
|
3093
|
+
return result
|
|
3094
|
+
}
|
|
3095
|
+
for (const language of GUFA_DEFINITION_LANGUAGES) {
|
|
3096
|
+
try {
|
|
3097
|
+
monaco.languages.registerDefinitionProvider(language, {
|
|
3098
|
+
async provideDefinition(model, position, token) {
|
|
3099
|
+
if (token !== null && token !== undefined && token.isCancellationRequested === true) return []
|
|
3100
|
+
const info = pathOfModel(model)
|
|
3101
|
+
if (info === null) return []
|
|
3102
|
+
const wordInfo = typeof model.getWordAtPosition === 'function' ? model.getWordAtPosition(position) : null
|
|
3103
|
+
const word = wordInfo !== null && wordInfo !== undefined && typeof wordInfo.word === 'string' ? wordInfo.word : ''
|
|
3104
|
+
try {
|
|
3105
|
+
let result = null
|
|
3106
|
+
if (language === 'python') {
|
|
3107
|
+
result = await G.api('lsp.definition', {
|
|
3108
|
+
root: info.root,
|
|
3109
|
+
path: info.path,
|
|
3110
|
+
line: position.lineNumber,
|
|
3111
|
+
column: position.column,
|
|
3112
|
+
language: 'python',
|
|
3113
|
+
content: model.getValue(),
|
|
3114
|
+
})
|
|
3115
|
+
} else {
|
|
3116
|
+
/* LanguageService 解析定义(TS 编译器),比正则项目搜索准确;
|
|
3117
|
+
JS/TS 不再回退到 code.definition,避免“宁可跳错也不空着”。 */
|
|
3118
|
+
result = await G.api('code.tsDefinition', {
|
|
3119
|
+
root: info.root,
|
|
3120
|
+
path: info.path,
|
|
3121
|
+
line: position.lineNumber,
|
|
3122
|
+
column: position.column,
|
|
3123
|
+
content: model.getValue(),
|
|
3124
|
+
})
|
|
3125
|
+
}
|
|
3126
|
+
if (token !== null && token !== undefined && token.isCancellationRequested === true) return []
|
|
3127
|
+
return locationsOf(info.root, result !== null && result !== undefined ? result.matches : null, word, monaco)
|
|
3128
|
+
} catch {
|
|
3129
|
+
return []
|
|
3130
|
+
}
|
|
3131
|
+
},
|
|
3132
|
+
})
|
|
3133
|
+
} catch {
|
|
3134
|
+
/* 单个语言注册失败不影响其它语言 */
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
try {
|
|
3138
|
+
if (typeof monaco.editor.registerEditorOpener === 'function') {
|
|
3139
|
+
monaco.editor.registerEditorOpener({
|
|
3140
|
+
openCodeEditor(source, resource, selectionOrPosition) {
|
|
3141
|
+
const root = rootAt()
|
|
3142
|
+
if (root === '') return false
|
|
3143
|
+
let absolute = ''
|
|
3144
|
+
try {
|
|
3145
|
+
absolute = resource?.fsPath ?? (typeof resource?.path === 'string' ? decodeURIComponent(resource.path) : '')
|
|
3146
|
+
} catch {
|
|
3147
|
+
return false
|
|
3148
|
+
}
|
|
3149
|
+
absolute = String(absolute).replace(/\\/g, '/')
|
|
3150
|
+
const selection = selectionOrPosition !== null && selectionOrPosition !== undefined && selectionOrPosition.selection !== undefined
|
|
3151
|
+
? selectionOrPosition.selection
|
|
3152
|
+
: selectionOrPosition
|
|
3153
|
+
const line = Math.max(1, Math.trunc(Number(selection?.startLineNumber ?? selection?.lineNumber ?? 1) || 1))
|
|
3154
|
+
const column = Math.max(1, Math.trunc(Number(selection?.startColumn ?? selection?.column ?? 1) || 1))
|
|
3155
|
+
if (absolute.startsWith(`${root}/`)) {
|
|
3156
|
+
try {
|
|
3157
|
+
G.bus.emit('editor:open-at', { path: absolute.slice(root.length + 1), line, column })
|
|
3158
|
+
} catch {
|
|
3159
|
+
return false
|
|
3160
|
+
}
|
|
3161
|
+
return true
|
|
3162
|
+
}
|
|
3163
|
+
/* 系统内置 API 的定义在 TS worker 的 lib 里(parseInt 等):按 basename 交给只读标签打开 */
|
|
3164
|
+
const baseName = absolute.slice(absolute.lastIndexOf('/') + 1)
|
|
3165
|
+
if (/^lib\.[A-Za-z0-9._-]+\.d\.ts$/.test(baseName)) {
|
|
3166
|
+
try {
|
|
3167
|
+
G.bus.emit('editor:open-external', { absolutePath: '', libName: baseName, path: baseName, line, column })
|
|
3168
|
+
} catch {
|
|
3169
|
+
return false
|
|
3170
|
+
}
|
|
3171
|
+
return true
|
|
3172
|
+
}
|
|
3173
|
+
return false
|
|
3174
|
+
},
|
|
3175
|
+
})
|
|
3176
|
+
}
|
|
3177
|
+
} catch {
|
|
3178
|
+
/* ignore */
|
|
3179
|
+
}
|
|
3180
|
+
} catch {
|
|
3181
|
+
/* ignore */
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
|
|
3185
|
+
/* 诊断波浪线已关闭(用户要求);Host lint 也不再在每次输入后跑 tsc,省 CPU */
|
|
3186
|
+
const GUFA_LINT_ENABLED = true
|
|
3187
|
+
|
|
3032
3188
|
/* ── model / URI ────────────────────────────────────────────────────── */
|
|
3033
3189
|
|
|
3034
3190
|
/**
|
|
@@ -3080,19 +3236,82 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3080
3236
|
return model
|
|
3081
3237
|
}
|
|
3082
3238
|
|
|
3239
|
+
/**
|
|
3240
|
+
* 查找框可见时才打开 overview ruler(查找匹配标记),关闭时收起。
|
|
3241
|
+
* 常开 ruler 会在每次滚动时额外渲染诊断/查找标记,体感卡。
|
|
3242
|
+
*/
|
|
3243
|
+
function gufaInstallFindRuler(instance) {
|
|
3244
|
+
try {
|
|
3245
|
+
const dom = typeof instance.getDomNode === 'function' ? instance.getDomNode() : null
|
|
3246
|
+
if (dom === null || dom === undefined) return null
|
|
3247
|
+
let frame = 0
|
|
3248
|
+
const apply = () => {
|
|
3249
|
+
frame = 0
|
|
3250
|
+
let visible = false
|
|
3251
|
+
try {
|
|
3252
|
+
const widget = dom.querySelector('.find-widget')
|
|
3253
|
+
visible = widget !== null && widget !== undefined && widget.classList.contains('visible')
|
|
3254
|
+
} catch {
|
|
3255
|
+
visible = false
|
|
3256
|
+
}
|
|
3257
|
+
try {
|
|
3258
|
+
instance.updateOptions({ renderOverviewRuler: visible, overviewRulerLanes: visible ? 1 : 0 })
|
|
3259
|
+
} catch {
|
|
3260
|
+
/* ignore */
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
const schedule = () => {
|
|
3264
|
+
if (frame !== 0) return
|
|
3265
|
+
frame = typeof requestAnimationFrame === 'function' ? requestAnimationFrame(apply) : window.setTimeout(apply, 16)
|
|
3266
|
+
}
|
|
3267
|
+
const observer = typeof MutationObserver === 'function' ? new MutationObserver((records) => {
|
|
3268
|
+
for (const record of records) {
|
|
3269
|
+
if (record.type === 'attributes' && record.target instanceof Element && record.target.classList.contains('find-widget')) {
|
|
3270
|
+
schedule()
|
|
3271
|
+
return
|
|
3272
|
+
}
|
|
3273
|
+
if (record.type === 'childList') {
|
|
3274
|
+
for (const node of record.addedNodes) {
|
|
3275
|
+
if (node instanceof Element && (node.classList.contains('find-widget') || node.querySelector('.find-widget') !== null)) {
|
|
3276
|
+
schedule()
|
|
3277
|
+
return
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
}) : null
|
|
3283
|
+
observer?.observe(dom, { subtree: true, attributes: true, attributeFilter: ['class'], childList: true })
|
|
3284
|
+
return () => {
|
|
3285
|
+
try { observer?.disconnect() } catch { /* ignore */ }
|
|
3286
|
+
if (frame !== 0) {
|
|
3287
|
+
try {
|
|
3288
|
+
if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)
|
|
3289
|
+
else window.clearTimeout(frame)
|
|
3290
|
+
} catch { /* ignore */ }
|
|
3291
|
+
frame = 0
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
} catch {
|
|
3295
|
+
return null
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3083
3299
|
/** Monaco 编辑器选项:关闭 minimap / overview ruler,automaticLayout 跟随容器尺寸。 */
|
|
3084
3300
|
function gufaEditorOptions(theme) {
|
|
3085
3301
|
return {
|
|
3086
3302
|
theme: gufaMonacoTheme(theme),
|
|
3087
3303
|
automaticLayout: true,
|
|
3088
3304
|
minimap: { enabled: false },
|
|
3089
|
-
|
|
3090
|
-
|
|
3305
|
+
/* 右侧 ruler 常开:查找匹配/诊断标记显示在滚动条旁 */
|
|
3306
|
+
renderOverviewRuler: true,
|
|
3307
|
+
overviewRulerLanes: 1,
|
|
3091
3308
|
overviewRulerBorder: false,
|
|
3092
3309
|
hideCursorInOverviewRuler: true,
|
|
3093
3310
|
scrollBeyondLastLine: false,
|
|
3094
3311
|
smoothScrolling: true,
|
|
3095
3312
|
cursorBlinking: 'smooth',
|
|
3313
|
+
/* 滚动相关的额外渲染关掉:sticky scroll / 常驻 overview ruler 已单独处理 */
|
|
3314
|
+
stickyScroll: { enabled: false },
|
|
3096
3315
|
fontSize: 13,
|
|
3097
3316
|
lineHeight: 20,
|
|
3098
3317
|
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',
|
|
@@ -3363,8 +3582,13 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3363
3582
|
} catch (error) {
|
|
3364
3583
|
/* 模板语言注册失败不影响编辑器 */
|
|
3365
3584
|
}
|
|
3366
|
-
|
|
3367
|
-
|
|
3585
|
+
try {
|
|
3586
|
+
gufaRegisterDefinitionInfrastructure(monaco)
|
|
3587
|
+
} catch {
|
|
3588
|
+
/* ignore */
|
|
3589
|
+
}
|
|
3590
|
+
/* 诊断统一由 Host 提供:JS 用项目 ESLint(尊重 .eslintrc/globals/rules),
|
|
3591
|
+
TS 回落 Host tsc;关掉 Monaco worker 诊断,避免同一个错误画两条线/问题计数翻倍。 */
|
|
3368
3592
|
try {
|
|
3369
3593
|
const typescriptLanguages = monaco.languages.typescript
|
|
3370
3594
|
const diagnosticsOff = { noSemanticValidation: true, noSyntaxValidation: true }
|
|
@@ -3535,8 +3759,9 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3535
3759
|
/* ignore */
|
|
3536
3760
|
}
|
|
3537
3761
|
}
|
|
3762
|
+
/* Cmd 悬停只给单词换颜色(蓝色),不加下划线、不弹原生 link 提示框。 */
|
|
3538
3763
|
const showHoverDecoration = (position, wordInfo) => {
|
|
3539
|
-
if (wordInfo === null || wordInfo === undefined) return clearHoverDecoration()
|
|
3764
|
+
if (wordInfo === null || wordInfo === undefined || position === null || position === undefined) return clearHoverDecoration()
|
|
3540
3765
|
let range = null
|
|
3541
3766
|
try {
|
|
3542
3767
|
range = new monaco.Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn)
|
|
@@ -3545,68 +3770,28 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3545
3770
|
}
|
|
3546
3771
|
try {
|
|
3547
3772
|
hover.decorationIds = instance.deltaDecorations(hover.decorationIds, [
|
|
3548
|
-
{ range, options: { inlineClassName: 'gufa-def-link', stickiness: 1 } },
|
|
3773
|
+
{ range, options: { inlineClassName: 'gufa-def-link-color', stickiness: 1 } },
|
|
3549
3774
|
])
|
|
3550
3775
|
} catch {
|
|
3551
3776
|
/* ignore */
|
|
3552
3777
|
}
|
|
3553
|
-
try {
|
|
3554
|
-
editorDom.classList.add('gufa-def-hover')
|
|
3555
|
-
} catch {
|
|
3556
|
-
/* ignore */
|
|
3557
|
-
}
|
|
3558
3778
|
}
|
|
3559
3779
|
const evaluateHoverPosition = (position, wordInfo) => {
|
|
3560
3780
|
if (!hover.meta) {
|
|
3561
3781
|
clearHoverDecoration()
|
|
3562
3782
|
return
|
|
3563
3783
|
}
|
|
3564
|
-
const model = instance.getModel()
|
|
3565
3784
|
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 === '') {
|
|
3785
|
+
if (position === null || position === undefined || word.length < 2) {
|
|
3570
3786
|
clearHoverDecoration()
|
|
3571
3787
|
return
|
|
3572
3788
|
}
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
const key = `${
|
|
3789
|
+
/* 不再为了下划线去跑项目级定义搜索:按住 Cmd 立刻标出当前单词,
|
|
3790
|
+
真正解析只发生在点击时。之前 hover 的 host 扫描是「难用/卡」的主要来源。 */
|
|
3791
|
+
const key = `${position.lineNumber}:${wordInfo.startColumn}:${wordInfo.endColumn}`
|
|
3792
|
+
if (hover.lastKey === key && hover.decorationIds.length > 0) return
|
|
3576
3793
|
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)
|
|
3794
|
+
showHoverDecoration(position, wordInfo)
|
|
3610
3795
|
}
|
|
3611
3796
|
/* 用 Monaco 自己的 onMouseMove(带修饰键状态 + 精确 position),
|
|
3612
3797
|
不依赖 DOM mousedown/getTargetAtClientPoint 的坐标系与包含关系。 */
|
|
@@ -3717,13 +3902,66 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3717
3902
|
} catch {
|
|
3718
3903
|
/* ignore */
|
|
3719
3904
|
}
|
|
3905
|
+
/* Cmd+点击直接用 Host 的准确解析,避免依赖 Monaco 原生 action/worker:
|
|
3906
|
+
- JS/TS:TypeScript LanguageService(含 parseInt 等系统 lib);
|
|
3907
|
+
- Python:pyright lsp.definition。 */
|
|
3908
|
+
const clickLanguage = typeof model.getLanguageId === 'function' ? model.getLanguageId() : ''
|
|
3909
|
+
if (clickLanguage === 'javascript' || clickLanguage === 'typescript') {
|
|
3910
|
+
try {
|
|
3911
|
+
const resolved = await G.api('code.tsDefinition', {
|
|
3912
|
+
root,
|
|
3913
|
+
path,
|
|
3914
|
+
line: position.lineNumber,
|
|
3915
|
+
column: position.column,
|
|
3916
|
+
content: model.getValue(),
|
|
3917
|
+
})
|
|
3918
|
+
const matches = resolved !== null && resolved !== undefined && Array.isArray(resolved.matches) ? resolved.matches : []
|
|
3919
|
+
const internal = matches.find((item) => item !== null && item !== undefined && item.external !== true && typeof item.path === 'string' && item.path !== '')
|
|
3920
|
+
if (internal !== undefined) {
|
|
3921
|
+
G.bus.emit('editor:open-at', { path: internal.path, line: internal.line, column: internal.column })
|
|
3922
|
+
} else {
|
|
3923
|
+
const external = matches.find((item) => item !== null && item !== undefined && item.external === true && typeof item.absolutePath === 'string')
|
|
3924
|
+
if (external !== undefined) {
|
|
3925
|
+
G.bus.emit('editor:open-external', {
|
|
3926
|
+
absolutePath: external.absolutePath,
|
|
3927
|
+
path: typeof external.path === 'string' ? external.path : '',
|
|
3928
|
+
line: external.line,
|
|
3929
|
+
column: external.column,
|
|
3930
|
+
})
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
} catch {
|
|
3934
|
+
/* 解析失败不跳错 */
|
|
3935
|
+
}
|
|
3936
|
+
clearHoverDecoration()
|
|
3937
|
+
return
|
|
3938
|
+
}
|
|
3939
|
+
if (clickLanguage === 'python') {
|
|
3940
|
+
try {
|
|
3941
|
+
const resolved = await G.api('lsp.definition', {
|
|
3942
|
+
root,
|
|
3943
|
+
path,
|
|
3944
|
+
line: position.lineNumber,
|
|
3945
|
+
column: position.column,
|
|
3946
|
+
language: 'python',
|
|
3947
|
+
content: model.getValue(),
|
|
3948
|
+
})
|
|
3949
|
+
const matches = resolved !== null && resolved !== undefined && Array.isArray(resolved.matches) ? resolved.matches : []
|
|
3950
|
+
const first = matches.find((item) => item !== null && item !== undefined && typeof item.path === 'string' && item.path !== '')
|
|
3951
|
+
if (first !== undefined) G.bus.emit('editor:open-at', { path: first.path, line: first.line, column: first.column })
|
|
3952
|
+
} catch {
|
|
3953
|
+
/* ignore */
|
|
3954
|
+
}
|
|
3955
|
+
clearHoverDecoration()
|
|
3956
|
+
return
|
|
3957
|
+
}
|
|
3958
|
+
/* 其它语言:保留 Monaco 原生 action 兜底 */
|
|
3720
3959
|
try {
|
|
3721
|
-
|
|
3960
|
+
instance.focus()
|
|
3961
|
+
instance.setPosition(position)
|
|
3722
3962
|
} catch {
|
|
3723
3963
|
/* ignore */
|
|
3724
3964
|
}
|
|
3725
|
-
const beforePath = modelPathRef.current
|
|
3726
|
-
const beforePosition = instance.getPosition()
|
|
3727
3965
|
try {
|
|
3728
3966
|
const action = typeof instance.getAction === 'function' ? instance.getAction('editor.action.revealDefinition') : null
|
|
3729
3967
|
if (action !== null && action !== undefined) {
|
|
@@ -3733,37 +3971,8 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3733
3971
|
} catch {
|
|
3734
3972
|
/* ignore */
|
|
3735
3973
|
}
|
|
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
|
-
}
|
|
3974
|
+
await new Promise((resolve) => { window.setTimeout(resolve, 200) })
|
|
3747
3975
|
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
3976
|
}
|
|
3768
3977
|
document.addEventListener('mousedown', onDefinitionClick, true)
|
|
3769
3978
|
document.addEventListener('keydown', onMetaDown, true)
|
|
@@ -3789,6 +3998,88 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3789
3998
|
} catch {
|
|
3790
3999
|
/* ignore */
|
|
3791
4000
|
}
|
|
4001
|
+
/* 外部/AI 修改磁盘后由 App 轮询发现,通过 bus 通知编辑器热替换 model 内容。
|
|
4002
|
+
(1.3.117 删 AI Tab 时误删过这一段,1.3.125 恢复) */
|
|
4003
|
+
try {
|
|
4004
|
+
if (G.bus !== null && G.bus !== undefined && typeof G.bus.on === 'function') {
|
|
4005
|
+
const offExternalReload = G.bus.on('editor:external-reload', (detail) => {
|
|
4006
|
+
if (detail === null || detail === undefined || typeof detail.path !== 'string' || typeof detail.content !== 'string') return
|
|
4007
|
+
const target = modelsRef.current.get(detail.path)
|
|
4008
|
+
if (target === null || target === undefined) return
|
|
4009
|
+
let content = ''
|
|
4010
|
+
try {
|
|
4011
|
+
content = target.getValue()
|
|
4012
|
+
} catch {
|
|
4013
|
+
return
|
|
4014
|
+
}
|
|
4015
|
+
if (content === detail.content) return
|
|
4016
|
+
const active = modelPathRef.current === detail.path
|
|
4017
|
+
let position = null
|
|
4018
|
+
let scrollTop = 0
|
|
4019
|
+
if (active) {
|
|
4020
|
+
try {
|
|
4021
|
+
position = instance.getPosition()
|
|
4022
|
+
scrollTop = instance.getScrollTop()
|
|
4023
|
+
} catch {
|
|
4024
|
+
position = null
|
|
4025
|
+
}
|
|
4026
|
+
}
|
|
4027
|
+
suppressChangeRef.current = true
|
|
4028
|
+
try {
|
|
4029
|
+
target.setValue(detail.content)
|
|
4030
|
+
} finally {
|
|
4031
|
+
suppressChangeRef.current = false
|
|
4032
|
+
}
|
|
4033
|
+
lastPropContentRef.current.set(detail.path, detail.content)
|
|
4034
|
+
if (active && position !== null && position !== undefined) {
|
|
4035
|
+
try {
|
|
4036
|
+
instance.setPosition(position)
|
|
4037
|
+
instance.setScrollTop(scrollTop)
|
|
4038
|
+
} catch {
|
|
4039
|
+
/* ignore */
|
|
4040
|
+
}
|
|
4041
|
+
}
|
|
4042
|
+
})
|
|
4043
|
+
if (typeof offExternalReload === 'function') subscriptions.push({ dispose: offExternalReload })
|
|
4044
|
+
}
|
|
4045
|
+
} catch {
|
|
4046
|
+
/* ignore */
|
|
4047
|
+
}
|
|
4048
|
+
|
|
4049
|
+
/* 拖拽分割条期间暂停 Monaco automaticLayout:
|
|
4050
|
+
宽度每帧变化时 Monaco layout() 会跟着重排整块编辑器,是「不跟手」的大头;
|
|
4051
|
+
拖拽先只动容器/别的面板,松手后再 layout 一次。 */
|
|
4052
|
+
try {
|
|
4053
|
+
if (G.bus !== null && G.bus !== undefined && typeof G.bus.on === 'function') {
|
|
4054
|
+
const offResizeStart = G.bus.on('layout:resize-start', () => {
|
|
4055
|
+
try {
|
|
4056
|
+
instance.updateOptions({ automaticLayout: false })
|
|
4057
|
+
} catch {
|
|
4058
|
+
/* ignore */
|
|
4059
|
+
}
|
|
4060
|
+
})
|
|
4061
|
+
const offResizeEnd = G.bus.on('layout:resize-end', () => {
|
|
4062
|
+
const relayout = () => {
|
|
4063
|
+
try {
|
|
4064
|
+
instance.updateOptions({ automaticLayout: true })
|
|
4065
|
+
instance.layout()
|
|
4066
|
+
} catch {
|
|
4067
|
+
/* ignore */
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4070
|
+
if (typeof requestAnimationFrame === 'function') {
|
|
4071
|
+
requestAnimationFrame(() => requestAnimationFrame(relayout))
|
|
4072
|
+
} else {
|
|
4073
|
+
window.setTimeout(relayout, 32)
|
|
4074
|
+
}
|
|
4075
|
+
})
|
|
4076
|
+
if (typeof offResizeStart === 'function') subscriptions.push({ dispose: offResizeStart })
|
|
4077
|
+
if (typeof offResizeEnd === 'function') subscriptions.push({ dispose: offResizeEnd })
|
|
4078
|
+
}
|
|
4079
|
+
} catch {
|
|
4080
|
+
/* ignore */
|
|
4081
|
+
}
|
|
4082
|
+
|
|
3792
4083
|
G.__gufaEditorDebug = {
|
|
3793
4084
|
focus: () => {
|
|
3794
4085
|
try {
|
|
@@ -3852,6 +4143,7 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3852
4143
|
lintTimers.clear()
|
|
3853
4144
|
}
|
|
3854
4145
|
const runLint = async (model, path) => {
|
|
4146
|
+
if (GUFA_LINT_ENABLED !== true) return
|
|
3855
4147
|
if (model === null || model === undefined || typeof path !== 'string' || path === '') return
|
|
3856
4148
|
const language = typeof model.getLanguageId === 'function' ? model.getLanguageId() : ''
|
|
3857
4149
|
if (language !== 'javascript' && language !== 'typescript') return
|
|
@@ -3889,6 +4181,7 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3889
4181
|
}
|
|
3890
4182
|
}
|
|
3891
4183
|
const scheduleLint = (model, path) => {
|
|
4184
|
+
if (GUFA_LINT_ENABLED !== true) return
|
|
3892
4185
|
if (model === null || model === undefined || typeof path !== 'string' || path === '') return
|
|
3893
4186
|
const previous = lintTimers.get(path)
|
|
3894
4187
|
if (previous !== undefined) window.clearTimeout(previous)
|
|
@@ -3979,6 +4272,20 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3979
4272
|
}
|
|
3980
4273
|
}, [attempt, reportCursor, disposeAllModels])
|
|
3981
4274
|
|
|
4275
|
+
/* TS 内置 lib(parseInt 等)标签是只读预览 */
|
|
4276
|
+
const activeExternal = activeTab !== null && activeTab.external === true
|
|
4277
|
+
useEffect(() => {
|
|
4278
|
+
if (status !== 'ready') return undefined
|
|
4279
|
+
const instance = editorRef.current
|
|
4280
|
+
if (instance === null || instance === undefined) return undefined
|
|
4281
|
+
try {
|
|
4282
|
+
instance.updateOptions({ readOnly: activeExternal })
|
|
4283
|
+
} catch {
|
|
4284
|
+
/* ignore */
|
|
4285
|
+
}
|
|
4286
|
+
return undefined
|
|
4287
|
+
}, [activeExternal, status])
|
|
4288
|
+
|
|
3982
4289
|
/* ── 同步 tabs ↔ models,并切换当前 model ──────────────────────── */
|
|
3983
4290
|
useEffect(() => {
|
|
3984
4291
|
if (status !== 'ready') return
|
|
@@ -4212,7 +4519,10 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
4212
4519
|
minimap: { enabled: false },
|
|
4213
4520
|
scrollBeyondLastLine: false,
|
|
4214
4521
|
lineNumbers: 'on',
|
|
4215
|
-
|
|
4522
|
+
/* diff 编辑器也显示右侧 overview ruler:新增/删除改动在滚动条旁有红绿标记 */
|
|
4523
|
+
renderOverviewRuler: true,
|
|
4524
|
+
overviewRulerLanes: 1,
|
|
4525
|
+
overviewRulerBorder: false,
|
|
4216
4526
|
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',
|
|
4217
4527
|
fontSize: 12.5,
|
|
4218
4528
|
lineHeight: 1.15,
|
|
@@ -5156,6 +5466,8 @@ function GufaTerminalView(props) {
|
|
|
5156
5466
|
|
|
5157
5467
|
const fitNow = () => {
|
|
5158
5468
|
if (fit === null || term === null || disposed) return
|
|
5469
|
+
/* 拖分割条时尺寸每帧都在变,xterm.fit() 很重;等 layout:resize-end 一次算到位 */
|
|
5470
|
+
if (G.__gufaSplitterDragging === true) return
|
|
5159
5471
|
const host = hostRef.current
|
|
5160
5472
|
if (host === null || host.clientWidth <= 0 || host.clientHeight <= 0) return
|
|
5161
5473
|
try {
|
|
@@ -5557,12 +5869,19 @@ function GufaTerminalView(props) {
|
|
|
5557
5869
|
openFrame = window.requestAnimationFrame(tryOpen)
|
|
5558
5870
|
}
|
|
5559
5871
|
props.register(terminalId, channel)
|
|
5872
|
+
const offLayoutEnd = G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function'
|
|
5873
|
+
? () => {}
|
|
5874
|
+
: G.bus.on('layout:resize-end', () => {
|
|
5875
|
+
fitNow()
|
|
5876
|
+
sendCurrentSize()
|
|
5877
|
+
})
|
|
5560
5878
|
|
|
5561
5879
|
startStream()
|
|
5562
5880
|
if (mode === 'xterm') tryOpen()
|
|
5563
5881
|
|
|
5564
5882
|
return () => {
|
|
5565
5883
|
disposed = true
|
|
5884
|
+
try { offLayoutEnd() } catch { /* ignore */ }
|
|
5566
5885
|
if (retryTimer !== null) clearTimeout(retryTimer)
|
|
5567
5886
|
if (replayTimer !== null) clearTimeout(replayTimer)
|
|
5568
5887
|
if (openFrame !== 0) window.cancelAnimationFrame(openFrame)
|
|
@@ -6087,7 +6406,7 @@ G.TerminalPane = function TerminalPane(props) {
|
|
|
6087
6406
|
{
|
|
6088
6407
|
className: 'gufa-termpane',
|
|
6089
6408
|
style: {
|
|
6090
|
-
height,
|
|
6409
|
+
height: `var(--gufa-h-terminal, ${height}px)`,
|
|
6091
6410
|
flex: '0 0 auto',
|
|
6092
6411
|
display: 'flex',
|
|
6093
6412
|
flexDirection: 'column',
|
|
@@ -9702,6 +10021,57 @@ G.BackdropParticles = function BackdropParticles(props) {
|
|
|
9702
10021
|
return h('canvas', { ref: canvasRef, className: 'gufa-backdrop-particles', 'aria-hidden': 'true', style: { mixBlendMode: 'screen' } })
|
|
9703
10022
|
}
|
|
9704
10023
|
|
|
10024
|
+
/** 进入古法 IDE 时临时关掉皮肤自身的粒子/动效(它们会在覆盖层下面持续跑 WebGL/rAF);
|
|
10025
|
+
* 退出时恢复用户原设置,不改变用户偏好。 */
|
|
10026
|
+
let gufaSkinEffectsSaved = null
|
|
10027
|
+
G.suspendSkinEffects = function suspendSkinEffects() {
|
|
10028
|
+
try {
|
|
10029
|
+
if (gufaSkinEffectsSaved !== null) return
|
|
10030
|
+
const raw = localStorage.getItem(SKIN_SETTINGS_KEY)
|
|
10031
|
+
if (raw === null || raw === '') return
|
|
10032
|
+
const record = JSON.parse(raw)
|
|
10033
|
+
if (record === null || typeof record !== 'object' || record.values === null || typeof record.values !== 'object') return
|
|
10034
|
+
const values = record.values
|
|
10035
|
+
if (values.particlesEnabled !== true && values.motionEnabled !== true) return
|
|
10036
|
+
gufaSkinEffectsSaved = raw
|
|
10037
|
+
const next = { ...record, values: { ...values, particlesEnabled: false, motionEnabled: false } }
|
|
10038
|
+
const payload = JSON.stringify(next)
|
|
10039
|
+
localStorage.setItem(SKIN_SETTINGS_KEY, payload)
|
|
10040
|
+
try {
|
|
10041
|
+
window.dispatchEvent(new StorageEvent('storage', {
|
|
10042
|
+
key: SKIN_SETTINGS_KEY,
|
|
10043
|
+
oldValue: raw,
|
|
10044
|
+
newValue: payload,
|
|
10045
|
+
storageArea: localStorage,
|
|
10046
|
+
}))
|
|
10047
|
+
} catch {
|
|
10048
|
+
/* ignore */
|
|
10049
|
+
}
|
|
10050
|
+
} catch {
|
|
10051
|
+
gufaSkinEffectsSaved = null
|
|
10052
|
+
}
|
|
10053
|
+
}
|
|
10054
|
+
G.resumeSkinEffects = function resumeSkinEffects() {
|
|
10055
|
+
try {
|
|
10056
|
+
if (gufaSkinEffectsSaved === null) return
|
|
10057
|
+
const raw = gufaSkinEffectsSaved
|
|
10058
|
+
gufaSkinEffectsSaved = null
|
|
10059
|
+
localStorage.setItem(SKIN_SETTINGS_KEY, raw)
|
|
10060
|
+
try {
|
|
10061
|
+
window.dispatchEvent(new StorageEvent('storage', {
|
|
10062
|
+
key: SKIN_SETTINGS_KEY,
|
|
10063
|
+
oldValue: null,
|
|
10064
|
+
newValue: raw,
|
|
10065
|
+
storageArea: localStorage,
|
|
10066
|
+
}))
|
|
10067
|
+
} catch {
|
|
10068
|
+
/* ignore */
|
|
10069
|
+
}
|
|
10070
|
+
} catch {
|
|
10071
|
+
/* ignore */
|
|
10072
|
+
}
|
|
10073
|
+
}
|
|
10074
|
+
|
|
9705
10075
|
/** 背景浓度滑杆(无级、连续;双击恢复「跟随皮肤」)。 */
|
|
9706
10076
|
G.BackdropStrengthSlider = function BackdropStrengthSlider(props) {
|
|
9707
10077
|
const t = G.useT()
|
|
@@ -10551,6 +10921,8 @@ function gufaRestoreDockTarget(node, saved) {
|
|
|
10551
10921
|
}
|
|
10552
10922
|
}
|
|
10553
10923
|
|
|
10924
|
+
G.findConversationRoot = gufaFindConversationRoot
|
|
10925
|
+
|
|
10554
10926
|
/**
|
|
10555
10927
|
* 把会话根浮到停靠区的位置与尺寸;返回是否成功。
|
|
10556
10928
|
*
|
|
@@ -10562,6 +10934,7 @@ function gufaRestoreDockTarget(node, saved) {
|
|
|
10562
10934
|
* 用「测实际位置 → 补偿差值」迭代 2 次把会话对齐到停靠区。
|
|
10563
10935
|
*/
|
|
10564
10936
|
function gufaPlaceDockedConversation(root, host, options) {
|
|
10937
|
+
try { root.removeAttribute('data-gufa-hide') } catch { /* ignore */ }
|
|
10565
10938
|
const rect = host.getBoundingClientRect()
|
|
10566
10939
|
if (!(rect.width >= 80 && rect.height >= 80)) return false
|
|
10567
10940
|
const target = { left: Math.round(rect.left), top: Math.round(rect.top), width: Math.round(rect.width), height: Math.round(rect.height) }
|
|
@@ -10587,10 +10960,20 @@ function gufaPlaceDockedConversation(root, host, options) {
|
|
|
10587
10960
|
let floatMode = false
|
|
10588
10961
|
try { floatMode = document.documentElement.hasAttribute('data-gufa-float') } catch { floatMode = false }
|
|
10589
10962
|
if (floatMode) root.style.background = dockBackground === '' ? 'rgba(13, 15, 19, 0.55)' : `color-mix(in srgb, ${dockBackground} 45%, transparent)`
|
|
10590
|
-
else if (backdropMode
|
|
10963
|
+
else if (backdropMode) {
|
|
10964
|
+
/* 背景模式下必须半透明:解析不到实色时也用 color-mix + 变量兜底,
|
|
10965
|
+
不能掉进不透明实色分支(之前右侧对话背景变实色就是这个原因)。 */
|
|
10966
|
+
root.style.background = dockBackground === ''
|
|
10967
|
+
? 'color-mix(in srgb, var(--gufa-solid-bg, #1a1b1f) 34%, transparent)'
|
|
10968
|
+
: `color-mix(in srgb, ${dockBackground} 34%, transparent)`
|
|
10969
|
+
}
|
|
10591
10970
|
else root.style.background = dockBackground === '' ? 'var(--gufa-solid-bg, #1a1b1f)' : dockBackground
|
|
10592
10971
|
root.style.borderLeft = '1px solid var(--dsw-alias-border-l1)'
|
|
10593
10972
|
root.style.boxSizing = 'border-box'
|
|
10973
|
+
/* 注意:不要给会话根加 will-change/contain——实测会增加每次滚动时的样式/布局成本 */
|
|
10974
|
+
try {
|
|
10975
|
+
root.style.contain = 'layout paint'
|
|
10976
|
+
} catch { /* ignore */ }
|
|
10594
10977
|
root.style.setProperty('--dsh-chat-user-width', 'calc(100% - 24px)')
|
|
10595
10978
|
root.style.setProperty('--dsh-conversation-column-width', `${target.width}px`)
|
|
10596
10979
|
root.setAttribute('data-gufa-dock', '1')
|
|
@@ -10915,6 +11298,68 @@ G.__dock = {
|
|
|
10915
11298
|
restore: gufaRestoreDockTarget,
|
|
10916
11299
|
}
|
|
10917
11300
|
|
|
11301
|
+
/** 从 DSH 会话里的文件引用按钮提取路径/行号,然后在古法编辑器里打开。 */
|
|
11302
|
+
function gufaParseMentionButton(button) {
|
|
11303
|
+
if (button === null || button === undefined || typeof button.closest !== 'function') return null
|
|
11304
|
+
const className = typeof button.className === 'string' ? button.className : ''
|
|
11305
|
+
const dataRef = typeof button.getAttribute === 'function' ? (button.getAttribute('data-ref-chip') ?? '') : ''
|
|
11306
|
+
const isMention = className.includes('fileMention') || className.includes('fileLink') || dataRef !== ''
|
|
11307
|
+
if (!isMention) return null
|
|
11308
|
+
const title = typeof button.getAttribute === 'function' ? (button.getAttribute('title') ?? '').trim() : ''
|
|
11309
|
+
const text = String(button.textContent ?? '').replace(/\s+/g, ' ').trim()
|
|
11310
|
+
const parseRef = (value) => {
|
|
11311
|
+
const source = String(value ?? '').trim()
|
|
11312
|
+
if (source === '') return null
|
|
11313
|
+
const match = /^(.*?)(?::(\d+)(?:\s*[-,]\s*\d+)*|#L(\d+)(?:-L?\d+)?)$/.exec(source)
|
|
11314
|
+
if (match === null) return { path: source, line: 0 }
|
|
11315
|
+
return { path: match[1].trim(), line: Number(match[2] ?? match[3]) || 0 }
|
|
11316
|
+
}
|
|
11317
|
+
const titleLooksPath = /[\\/]/.test(title) || /\.[A-Za-z0-9]{1,8}$/.test(title)
|
|
11318
|
+
const fromTitle = titleLooksPath ? parseRef(title) : null
|
|
11319
|
+
const fromText = parseRef(text)
|
|
11320
|
+
/* 关键:title 通常只有完整路径(无行号),行号在按钮文本 `xxx.js:165` 里;
|
|
11321
|
+
两者要合并,不能 title 命中就忽略文本的行号。 */
|
|
11322
|
+
let path = fromTitle !== null && fromTitle.path !== '' ? fromTitle.path : (fromText !== null ? fromText.path : '')
|
|
11323
|
+
let line = (fromTitle !== null ? fromTitle.line : 0) || (fromText !== null ? fromText.line : 0)
|
|
11324
|
+
if (path === '') return null
|
|
11325
|
+
if (dataRef !== '') {
|
|
11326
|
+
let dataPath = ''
|
|
11327
|
+
let dataLine = 0
|
|
11328
|
+
if (dataRef.trim().startsWith('{')) {
|
|
11329
|
+
try {
|
|
11330
|
+
const parsedData = JSON.parse(dataRef)
|
|
11331
|
+
dataPath = typeof parsedData?.path === 'string' ? parsedData.path : ''
|
|
11332
|
+
dataLine = Number(parsedData?.line) || 0
|
|
11333
|
+
} catch {
|
|
11334
|
+
/* ignore */
|
|
11335
|
+
}
|
|
11336
|
+
}
|
|
11337
|
+
if (dataPath !== '') {
|
|
11338
|
+
path = dataPath
|
|
11339
|
+
if (dataLine > 0) line = dataLine
|
|
11340
|
+
}
|
|
11341
|
+
}
|
|
11342
|
+
return { path: path.replace(/^\.\//, ''), line }
|
|
11343
|
+
}
|
|
11344
|
+
|
|
11345
|
+
async function gufaOpenMention(mention) {
|
|
11346
|
+
if (mention === null || mention === undefined || typeof mention.path !== 'string' || mention.path === '') return
|
|
11347
|
+
const root = typeof G.projectRoot === 'string' ? G.projectRoot.replace(/\\/g, '/').replace(/\/+$/, '') : ''
|
|
11348
|
+
if (root === '') return
|
|
11349
|
+
let resolved = null
|
|
11350
|
+
try {
|
|
11351
|
+
resolved = await G.api('code.resolvePath', { root, path: mention.path })
|
|
11352
|
+
} catch {
|
|
11353
|
+
return
|
|
11354
|
+
}
|
|
11355
|
+
if (resolved === null || resolved === undefined || typeof resolved.path !== 'string' || resolved.path === '') return
|
|
11356
|
+
try {
|
|
11357
|
+
G.bus.emit('editor:open-at', { path: resolved.path, line: Math.max(1, Number(mention.line) || 1), column: 1 })
|
|
11358
|
+
} catch {
|
|
11359
|
+
/* ignore */
|
|
11360
|
+
}
|
|
11361
|
+
}
|
|
11362
|
+
|
|
10918
11363
|
/**
|
|
10919
11364
|
* 停靠栏:官方会话本体(浮动) + 顶部工具条(新建会话 / 打开完整对话 / 收起)。
|
|
10920
11365
|
* props = { project, activeFile, selection, theme, width, onInsertCode, backdrop, active, sessionTitle, sessions, onOpenSession }
|
|
@@ -10928,11 +11373,56 @@ G.ChatDock = function ChatDock(props) {
|
|
|
10928
11373
|
if (followRef.current === null) followRef.current = gufaCreateChatFollowKeeper()
|
|
10929
11374
|
const tickRef = useRef(null)
|
|
10930
11375
|
const startedRef = useRef(0)
|
|
11376
|
+
const mentionRootRef = useRef(null)
|
|
11377
|
+
const mentionHandlerRef = useRef(null)
|
|
11378
|
+
const detachMentionRef = useRef(null)
|
|
10931
11379
|
const [phase, setPhase] = useState('searching')
|
|
10932
11380
|
const [error, setError] = useState('')
|
|
10933
11381
|
const active = props.active !== false && props.paused !== true
|
|
10934
11382
|
|
|
11383
|
+
const detachMention = useCallback(() => {
|
|
11384
|
+
const root = mentionRootRef.current
|
|
11385
|
+
const handler = mentionHandlerRef.current
|
|
11386
|
+
if (root !== null && handler !== null) {
|
|
11387
|
+
try { root.removeEventListener('click', handler, true) } catch { /* ignore */ }
|
|
11388
|
+
}
|
|
11389
|
+
mentionRootRef.current = null
|
|
11390
|
+
mentionHandlerRef.current = null
|
|
11391
|
+
}, [])
|
|
11392
|
+
detachMentionRef.current = detachMention
|
|
11393
|
+
|
|
11394
|
+
const ensureMentionHandler = useCallback((root) => {
|
|
11395
|
+
if (root === null) {
|
|
11396
|
+
detachMention()
|
|
11397
|
+
return
|
|
11398
|
+
}
|
|
11399
|
+
if (mentionRootRef.current === root && mentionHandlerRef.current !== null) return
|
|
11400
|
+
detachMention()
|
|
11401
|
+
const handler = (event) => {
|
|
11402
|
+
try {
|
|
11403
|
+
if (event.button !== 0 || event.defaultPrevented === true) return
|
|
11404
|
+
const target = event.target instanceof Element ? event.target.closest('button, [data-ref-chip]') : null
|
|
11405
|
+
if (target === null) return
|
|
11406
|
+
const mention = gufaParseMentionButton(target)
|
|
11407
|
+
if (mention === null) return
|
|
11408
|
+
event.preventDefault()
|
|
11409
|
+
event.stopPropagation()
|
|
11410
|
+
void gufaOpenMention(mention)
|
|
11411
|
+
} catch {
|
|
11412
|
+
/* ignore */
|
|
11413
|
+
}
|
|
11414
|
+
}
|
|
11415
|
+
try {
|
|
11416
|
+
root.addEventListener('click', handler, true)
|
|
11417
|
+
mentionRootRef.current = root
|
|
11418
|
+
mentionHandlerRef.current = handler
|
|
11419
|
+
} catch {
|
|
11420
|
+
/* ignore */
|
|
11421
|
+
}
|
|
11422
|
+
}, [detachMention])
|
|
11423
|
+
|
|
10935
11424
|
const undock = useCallback(() => {
|
|
11425
|
+
detachMentionRef.current?.()
|
|
10936
11426
|
const current = dockRef.current
|
|
10937
11427
|
if (current.root !== null) gufaRestoreDockTarget(current.root, current.saved)
|
|
10938
11428
|
dockRef.current = { root: null, saved: null }
|
|
@@ -10958,6 +11448,7 @@ G.ChatDock = function ChatDock(props) {
|
|
|
10958
11448
|
dockRef.current = { root, saved: gufaSnapshotDockTarget(root) }
|
|
10959
11449
|
}
|
|
10960
11450
|
if (gufaPlaceDockedConversation(root, host, { translucent: props.backdrop === true })) {
|
|
11451
|
+
ensureMentionHandler(root)
|
|
10961
11452
|
try {
|
|
10962
11453
|
const scroller = root.querySelector(GUFA_CONVERSATION_SCROLL_SELECTOR)
|
|
10963
11454
|
if (scroller !== null && scroller !== undefined) followRef.current?.attach(scroller)
|
|
@@ -10966,7 +11457,32 @@ G.ChatDock = function ChatDock(props) {
|
|
|
10966
11457
|
}
|
|
10967
11458
|
setPhase((previous) => (previous === 'docked' ? previous : 'docked'))
|
|
10968
11459
|
}
|
|
10969
|
-
}, [active, undock, props.backdrop])
|
|
11460
|
+
}, [active, undock, props.backdrop, ensureMentionHandler])
|
|
11461
|
+
|
|
11462
|
+
/* 拖拽分割条时的轻量重定位:只改宿主几何,不 getComputedStyle、不读自身 rect、不 setState。
|
|
11463
|
+
完整 tick 每次都会 getComputedStyle + 最多两次 getBoundingClientRect,按帧跑会把拖拽拖卡。 */
|
|
11464
|
+
const lightTickRef = useRef(null)
|
|
11465
|
+
const lightTick = useCallback(() => {
|
|
11466
|
+
const host = hostRef.current
|
|
11467
|
+
if (host === null) return
|
|
11468
|
+
const root = dockRef.current.root
|
|
11469
|
+
if (root === null) return
|
|
11470
|
+
try {
|
|
11471
|
+
const rect = host.getBoundingClientRect()
|
|
11472
|
+
if (!(rect.width >= 80 && rect.height >= 80)) return
|
|
11473
|
+
root.style.position = 'fixed'
|
|
11474
|
+
root.style.left = `${Math.round(rect.left)}px`
|
|
11475
|
+
root.style.top = `${Math.round(rect.top)}px`
|
|
11476
|
+
root.style.width = `${Math.round(rect.width)}px`
|
|
11477
|
+
root.style.height = `${Math.round(rect.height)}px`
|
|
11478
|
+
root.style.setProperty('--dsh-conversation-column-width', `${Math.round(rect.width)}px`)
|
|
11479
|
+
} catch {
|
|
11480
|
+
/* ignore */
|
|
11481
|
+
}
|
|
11482
|
+
}, [])
|
|
11483
|
+
useEffect(() => {
|
|
11484
|
+
lightTickRef.current = lightTick
|
|
11485
|
+
}, [lightTick])
|
|
10970
11486
|
|
|
10971
11487
|
useEffect(() => {
|
|
10972
11488
|
tickRef.current = tick
|
|
@@ -10981,13 +11497,30 @@ G.ChatDock = function ChatDock(props) {
|
|
|
10981
11497
|
startedRef.current = Date.now()
|
|
10982
11498
|
setPhase((previous) => (previous === 'docked' ? previous : 'searching'))
|
|
10983
11499
|
let disposed = false
|
|
11500
|
+
/* dock 住之后彻底断开 body MutationObserver:Monaco 滚动会不断增删行 DOM,
|
|
11501
|
+
observer 即使不跑 tick,浏览器也要为整棵 body 维护/遍历 mutation record,依然拖慢滚动。
|
|
11502
|
+
发现/替换会话根交给 300ms 轮询(未 dock 时才观察)。 */
|
|
11503
|
+
let observer = typeof MutationObserver === 'function' ? new MutationObserver(() => { run() }) : null
|
|
11504
|
+
let observing = false
|
|
11505
|
+
const setObserving = (next) => {
|
|
11506
|
+
if (observer === null || observing === next) return
|
|
11507
|
+
observing = next
|
|
11508
|
+
try {
|
|
11509
|
+
if (next) observer.observe(document.body, { childList: true, subtree: true })
|
|
11510
|
+
else observer.disconnect()
|
|
11511
|
+
} catch {
|
|
11512
|
+
/* ignore */
|
|
11513
|
+
}
|
|
11514
|
+
}
|
|
10984
11515
|
const run = () => {
|
|
10985
|
-
if (
|
|
11516
|
+
if (disposed) return
|
|
11517
|
+
tickRef.current?.()
|
|
11518
|
+
const current = dockRef.current.root
|
|
11519
|
+
setObserving(!(current !== null && current.isConnected === true))
|
|
10986
11520
|
}
|
|
11521
|
+
setObserving(true)
|
|
10987
11522
|
run()
|
|
10988
|
-
const timer = window.setInterval(run,
|
|
10989
|
-
const observer = typeof MutationObserver === 'function' ? new MutationObserver(run) : null
|
|
10990
|
-
if (observer !== null) observer.observe(document.body, { childList: true, subtree: true })
|
|
11523
|
+
const timer = window.setInterval(run, 300)
|
|
10991
11524
|
let resizeObserver = null
|
|
10992
11525
|
if (typeof ResizeObserver === 'function') {
|
|
10993
11526
|
resizeObserver = new ResizeObserver(run)
|
|
@@ -11012,6 +11545,36 @@ G.ChatDock = function ChatDock(props) {
|
|
|
11012
11545
|
tickRef.current?.()
|
|
11013
11546
|
}, [props.width, props.backdrop])
|
|
11014
11547
|
|
|
11548
|
+
// 拖拽过程中宽高每帧变化(App 不重渲染),DSH 浮层需要跟着宿主矩形逐帧重定位
|
|
11549
|
+
useEffect(() => {
|
|
11550
|
+
if (G.bus === undefined || G.bus === null || typeof G.bus.on !== 'function') return undefined
|
|
11551
|
+
let frame = 0
|
|
11552
|
+
let lastTickAt = 0
|
|
11553
|
+
const off = G.bus.on('layout:resize', (detail) => {
|
|
11554
|
+
/* 只有横向聊天栏/宽度变化才需要动 DSH 浮层;终端高度拖拽不用每帧重定位 */
|
|
11555
|
+
const varName = detail !== null && detail !== undefined && typeof detail.varName === 'string' ? detail.varName : ''
|
|
11556
|
+
if (varName !== '' && varName !== '--gufa-w-chat') return
|
|
11557
|
+
/* 拖拽中 20fps 足够跟上视觉;每帧 getBoundingClientRect 会强制布局,反而拖慢分割条 */
|
|
11558
|
+
const now = Date.now()
|
|
11559
|
+
if (now - lastTickAt < 45) return
|
|
11560
|
+
lastTickAt = now
|
|
11561
|
+
if (frame !== 0) return
|
|
11562
|
+
frame = typeof requestAnimationFrame === 'function' ? requestAnimationFrame(() => {
|
|
11563
|
+
frame = 0
|
|
11564
|
+
lightTickRef.current?.()
|
|
11565
|
+
}) : window.setTimeout(() => { frame = 0; lightTickRef.current?.() }, 16)
|
|
11566
|
+
})
|
|
11567
|
+
return () => {
|
|
11568
|
+
try { off?.() } catch { /* ignore */ }
|
|
11569
|
+
if (frame !== 0) {
|
|
11570
|
+
try {
|
|
11571
|
+
if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)
|
|
11572
|
+
else window.clearTimeout(frame)
|
|
11573
|
+
} catch { /* ignore */ }
|
|
11574
|
+
}
|
|
11575
|
+
}
|
|
11576
|
+
}, [])
|
|
11577
|
+
|
|
11015
11578
|
const newSession = useCallback(() => {
|
|
11016
11579
|
const ui = G.ctx === null || G.ctx === undefined ? undefined : G.ctx.get('uiWorkspace')
|
|
11017
11580
|
if (ui === undefined || ui === null || typeof ui.startSession !== 'function') {
|
|
@@ -11959,30 +12522,106 @@ function selectSessionCwd(state) {
|
|
|
11959
12522
|
return picked?.projectionValues?.workingDirectory ?? picked?.cwd ?? null
|
|
11960
12523
|
}
|
|
11961
12524
|
|
|
11962
|
-
/** 可拖拽尺寸 hook:返回 [size, onMouseDown, setSize]。
|
|
12525
|
+
/** 可拖拽尺寸 hook:返回 [size, onMouseDown, setSize]。
|
|
12526
|
+
* 拖拽过程只改根节点 CSS 变量(rAF 合帧),不触发 GufaApp 整棵树重渲染;
|
|
12527
|
+
* 松手时才 setSize 一次,避免拖边框卡顿。 */
|
|
11963
12528
|
G.useSplitter = function useSplitter(options) {
|
|
11964
|
-
const { initial, min, max, axis = 'x', invert = false, storageKey } = options
|
|
12529
|
+
const { initial, min, max, axis = 'x', invert = false, storageKey, cssVar, targetSelector } = options
|
|
11965
12530
|
const [size, setSize] = useState(() => {
|
|
11966
12531
|
const stored = storageKey === undefined ? null : Number(localStorage.getItem(storageKey))
|
|
11967
12532
|
return Number.isFinite(stored) && stored > 0 ? Math.min(max, Math.max(min, stored)) : initial
|
|
11968
12533
|
})
|
|
12534
|
+
const findTarget = () => {
|
|
12535
|
+
if (typeof targetSelector !== 'string' || targetSelector === '') return null
|
|
12536
|
+
try {
|
|
12537
|
+
return typeof document !== 'undefined' ? document.querySelector(targetSelector) : null
|
|
12538
|
+
} catch {
|
|
12539
|
+
return null
|
|
12540
|
+
}
|
|
12541
|
+
}
|
|
12542
|
+
const applyToTarget = (target, value) => {
|
|
12543
|
+
if (target === null || target === undefined) return false
|
|
12544
|
+
try {
|
|
12545
|
+
if (axis === 'x') target.style.width = `${value}px`
|
|
12546
|
+
else target.style.height = `${value}px`
|
|
12547
|
+
return true
|
|
12548
|
+
} catch {
|
|
12549
|
+
return false
|
|
12550
|
+
}
|
|
12551
|
+
}
|
|
12552
|
+
/* 初始/恢复持久化尺寸:直接写目标元素,不往 documentElement 挂 CSS 变量
|
|
12553
|
+
(根节点自定义属性变化会让整棵文档(含 Monaco/DSH)样式重算,拖拽时非常伤) */
|
|
12554
|
+
React.useLayoutEffect(() => {
|
|
12555
|
+
const target = findTarget()
|
|
12556
|
+
if (!applyToTarget(target, size)) {
|
|
12557
|
+
if (typeof cssVar !== 'string' || cssVar === '') return
|
|
12558
|
+
try {
|
|
12559
|
+
document.documentElement.style.setProperty(cssVar, `${size}px`)
|
|
12560
|
+
} catch {
|
|
12561
|
+
/* ignore */
|
|
12562
|
+
}
|
|
12563
|
+
}
|
|
12564
|
+
return undefined
|
|
12565
|
+
}, [cssVar, size])
|
|
11969
12566
|
const onMouseDown = useCallback((event) => {
|
|
11970
12567
|
if (event.button !== 0) return
|
|
11971
12568
|
event.preventDefault()
|
|
12569
|
+
const splitter = event.currentTarget
|
|
12570
|
+
const target = findTarget()
|
|
11972
12571
|
const startPosition = axis === 'x' ? event.clientX : event.clientY
|
|
11973
12572
|
const startSize = size
|
|
11974
12573
|
let latest = size
|
|
11975
|
-
|
|
11976
|
-
|
|
11977
|
-
|
|
12574
|
+
let frame = 0
|
|
12575
|
+
let pendingPosition = null
|
|
12576
|
+
const applySize = () => {
|
|
12577
|
+
frame = 0
|
|
12578
|
+
if (pendingPosition === null) return
|
|
12579
|
+
const delta = (pendingPosition - startPosition) * (invert ? -1 : 1)
|
|
11978
12580
|
latest = Math.min(max, Math.max(min, startSize + delta))
|
|
11979
|
-
|
|
12581
|
+
pendingPosition = null
|
|
12582
|
+
/* 只改目标元素自身的 width/height:不发散到整个 root 的 CSS 变量 */
|
|
12583
|
+
if (!applyToTarget(target, latest)) {
|
|
12584
|
+
try {
|
|
12585
|
+
if (typeof cssVar === 'string' && cssVar !== '') document.documentElement.style.setProperty(cssVar, `${latest}px`)
|
|
12586
|
+
} catch {
|
|
12587
|
+
/* ignore */
|
|
12588
|
+
}
|
|
12589
|
+
}
|
|
12590
|
+
/* 聊天栏是 DSH 原生浮层,需要跟着宿主矩形重新定位;终端/Monaco 各自有 ResizeObserver */
|
|
12591
|
+
try {
|
|
12592
|
+
G.bus.emit('layout:resize', { varName: cssVar ?? '', size: latest })
|
|
12593
|
+
} catch {
|
|
12594
|
+
/* ignore */
|
|
12595
|
+
}
|
|
12596
|
+
}
|
|
12597
|
+
const onMove = (moveEvent) => {
|
|
12598
|
+
pendingPosition = axis === 'x' ? moveEvent.clientX : moveEvent.clientY
|
|
12599
|
+
if (frame === 0) {
|
|
12600
|
+
frame = typeof requestAnimationFrame === 'function' ? requestAnimationFrame(applySize) : window.setTimeout(applySize, 16)
|
|
12601
|
+
}
|
|
11980
12602
|
}
|
|
11981
12603
|
const onUp = () => {
|
|
11982
12604
|
window.removeEventListener('mousemove', onMove)
|
|
11983
12605
|
window.removeEventListener('mouseup', onUp)
|
|
12606
|
+
window.removeEventListener('blur', onUp)
|
|
12607
|
+
if (frame !== 0) {
|
|
12608
|
+
try {
|
|
12609
|
+
if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)
|
|
12610
|
+
else window.clearTimeout(frame)
|
|
12611
|
+
} catch {
|
|
12612
|
+
/* ignore */
|
|
12613
|
+
}
|
|
12614
|
+
frame = 0
|
|
12615
|
+
}
|
|
12616
|
+
if (pendingPosition !== null) applySize()
|
|
12617
|
+
setSize(latest)
|
|
11984
12618
|
document.body.style.cursor = ''
|
|
11985
12619
|
document.body.style.userSelect = ''
|
|
12620
|
+
try {
|
|
12621
|
+
if (splitter !== null && splitter !== undefined && typeof splitter.removeAttribute === 'function') splitter.removeAttribute('data-dragging')
|
|
12622
|
+
} catch {
|
|
12623
|
+
/* ignore */
|
|
12624
|
+
}
|
|
11986
12625
|
if (storageKey !== undefined) {
|
|
11987
12626
|
try {
|
|
11988
12627
|
localStorage.setItem(storageKey, String(latest))
|
|
@@ -11990,16 +12629,35 @@ G.useSplitter = function useSplitter(options) {
|
|
|
11990
12629
|
/* ignore */
|
|
11991
12630
|
}
|
|
11992
12631
|
}
|
|
12632
|
+
G.__gufaSplitterDragging = false
|
|
12633
|
+
try {
|
|
12634
|
+
G.bus.emit('layout:resize-end', { varName: cssVar ?? '', size: latest })
|
|
12635
|
+
} catch {
|
|
12636
|
+
/* ignore */
|
|
12637
|
+
}
|
|
12638
|
+
}
|
|
12639
|
+
try {
|
|
12640
|
+
if (splitter !== null && splitter !== undefined && typeof splitter.setAttribute === 'function') splitter.setAttribute('data-dragging', '')
|
|
12641
|
+
} catch {
|
|
12642
|
+
/* ignore */
|
|
11993
12643
|
}
|
|
11994
12644
|
document.body.style.cursor = axis === 'x' ? 'col-resize' : 'row-resize'
|
|
11995
12645
|
document.body.style.userSelect = 'none'
|
|
12646
|
+
G.__gufaSplitterDragging = true
|
|
12647
|
+
try {
|
|
12648
|
+
G.bus.emit('layout:resize-start', { varName: cssVar ?? '' })
|
|
12649
|
+
} catch {
|
|
12650
|
+
/* ignore */
|
|
12651
|
+
}
|
|
11996
12652
|
window.addEventListener('mousemove', onMove)
|
|
11997
12653
|
window.addEventListener('mouseup', onUp)
|
|
11998
|
-
|
|
12654
|
+
window.addEventListener('blur', onUp)
|
|
12655
|
+
}, [axis, cssVar, invert, max, min, size, storageKey])
|
|
11999
12656
|
return [size, onMouseDown, setSize]
|
|
12000
12657
|
}
|
|
12001
12658
|
|
|
12002
|
-
|
|
12659
|
+
|
|
12660
|
+
|
|
12003
12661
|
G.GufaApp = function GufaApp(props) {
|
|
12004
12662
|
const t = G.useT()
|
|
12005
12663
|
const theme = G.useTheme()
|
|
@@ -12159,9 +12817,9 @@ G.GufaApp = function GufaApp(props) {
|
|
|
12159
12817
|
const [modalPending, setModalPending] = useState(false)
|
|
12160
12818
|
const [modalError, setModalError] = useState('')
|
|
12161
12819
|
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' })
|
|
12820
|
+
const [explorerWidth, explorerDrag] = G.useSplitter({ initial: 260, min: 190, max: 520, storageKey: 'gufa-code:w:explorer', cssVar: '--gufa-w-explorer', targetSelector: '.gufa-sidepanel' })
|
|
12821
|
+
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' })
|
|
12822
|
+
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
12823
|
useEffect(() => {
|
|
12166
12824
|
tabsRef.current = tabs
|
|
12167
12825
|
}, [tabs])
|
|
@@ -12588,6 +13246,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
12588
13246
|
if (project === null) return
|
|
12589
13247
|
const tab = tabsRef.current.find((item) => item !== null && item.path === path)
|
|
12590
13248
|
if (tab === undefined) return
|
|
13249
|
+
if (tab.external === true) return
|
|
12591
13250
|
/* 缓冲里可能有比 tabs 更新的内容(按键后 300ms 内保存/自动保存) */
|
|
12592
13251
|
const content = editorBuffersRef.current.has(path) ? editorBuffersRef.current.get(path) : tab.content
|
|
12593
13252
|
if (content === tab.savedContent) {
|
|
@@ -13039,6 +13698,65 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13039
13698
|
}
|
|
13040
13699
|
}, [project, tabs, patchTab, refreshGit, t])
|
|
13041
13700
|
|
|
13701
|
+
/* TS 内置 lib 定义(parseInt/Promise 等):以只读标签打开 */
|
|
13702
|
+
const openExternalTab = useCallback(async (detail) => {
|
|
13703
|
+
if (detail === null || detail === undefined) return
|
|
13704
|
+
const absolutePath = typeof detail.absolutePath === 'string' ? detail.absolutePath : ''
|
|
13705
|
+
const libName = typeof detail.libName === 'string' ? detail.libName : ''
|
|
13706
|
+
if (absolutePath === '' && libName === '') return
|
|
13707
|
+
const relative = libName !== ''
|
|
13708
|
+
? libName
|
|
13709
|
+
: (typeof detail.path === 'string' && detail.path !== '' ? detail.path.replace(/^\/+/, '') : 'lib.d.ts')
|
|
13710
|
+
const pseudoPath = `~typescript/${relative}`
|
|
13711
|
+
flushBuffersRef.current?.()
|
|
13712
|
+
const existing = (tabsRef.current ?? []).find((tab) => tab !== null && tab !== undefined && tab.path === pseudoPath)
|
|
13713
|
+
if (existing !== undefined) {
|
|
13714
|
+
setActivePath(pseudoPath)
|
|
13715
|
+
window.setTimeout(() => {
|
|
13716
|
+
try {
|
|
13717
|
+
G.bus.emit('editor:reveal', { path: pseudoPath, line: Number(detail.line) || 1, column: Number(detail.column) || 1 })
|
|
13718
|
+
} catch {
|
|
13719
|
+
/* ignore */
|
|
13720
|
+
}
|
|
13721
|
+
}, 120)
|
|
13722
|
+
return
|
|
13723
|
+
}
|
|
13724
|
+
const doc = await G.api('code.readTsLib', libName !== '' ? { libName } : { absolutePath })
|
|
13725
|
+
const content = doc !== null && doc !== undefined && typeof doc.content === 'string' ? doc.content : ''
|
|
13726
|
+
const tab = {
|
|
13727
|
+
path: pseudoPath,
|
|
13728
|
+
content,
|
|
13729
|
+
savedContent: content,
|
|
13730
|
+
revision: 'external',
|
|
13731
|
+
savedRevision: 'external',
|
|
13732
|
+
dirty: false,
|
|
13733
|
+
size: content.length,
|
|
13734
|
+
language: doc !== null && doc !== undefined && typeof doc.language === 'string' ? doc.language : 'typescript',
|
|
13735
|
+
external: true,
|
|
13736
|
+
absolutePath: detail.absolutePath,
|
|
13737
|
+
name: doc !== null && doc !== undefined && typeof doc.name === 'string' ? doc.name : pseudoPath,
|
|
13738
|
+
}
|
|
13739
|
+
setTabs((current) => (current.some((item) => item !== null && item !== undefined && item.path === pseudoPath) ? current : [...current, tab]))
|
|
13740
|
+
setActivePath(pseudoPath)
|
|
13741
|
+
window.setTimeout(() => {
|
|
13742
|
+
try {
|
|
13743
|
+
G.bus.emit('editor:reveal', { path: pseudoPath, line: Number(detail.line) || 1, column: Number(detail.column) || 1 })
|
|
13744
|
+
} catch {
|
|
13745
|
+
/* ignore */
|
|
13746
|
+
}
|
|
13747
|
+
}, 120)
|
|
13748
|
+
}, [])
|
|
13749
|
+
|
|
13750
|
+
useEffect(() => {
|
|
13751
|
+
if (G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function') return undefined
|
|
13752
|
+
const offExternal = G.bus.on('editor:open-external', (detail) => {
|
|
13753
|
+
void openExternalTab(detail).catch((error) => setBanner(G.errorText(error)))
|
|
13754
|
+
})
|
|
13755
|
+
return () => {
|
|
13756
|
+
offExternal?.()
|
|
13757
|
+
}
|
|
13758
|
+
}, [openExternalTab])
|
|
13759
|
+
|
|
13042
13760
|
/* 自动保存:dirty 后 700ms 静默保存(普通文件 / 工作树 diff / 两文件对比) */
|
|
13043
13761
|
const saveFileRef = useRef(null)
|
|
13044
13762
|
const saveCompareRef = useRef(null)
|
|
@@ -14338,7 +15056,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
14338
15056
|
{
|
|
14339
15057
|
className: 'gufa-root',
|
|
14340
15058
|
'data-backdrop': backdropActive ? 'on' : undefined,
|
|
14341
|
-
style: { '--gufa-dock-width': ui.chatOpen ?
|
|
15059
|
+
style: { '--gufa-dock-width': ui.chatOpen ? `var(--gufa-w-chat, ${Math.round(chatWidth)}px)` : '0px' },
|
|
14342
15060
|
},
|
|
14343
15061
|
backdropActive ? h(G.SkinBackdrop, { meta: skinBackdrop, enabled: true, strength: backdropStrength }) : null,
|
|
14344
15062
|
h(
|
|
@@ -14473,7 +15191,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
14473
15191
|
? null
|
|
14474
15192
|
: h(
|
|
14475
15193
|
'div',
|
|
14476
|
-
{ className: 'gufa-sidepanel', style: { width: explorerWidth } },
|
|
15194
|
+
{ className: 'gufa-sidepanel', style: { width: `var(--gufa-w-explorer, ${explorerWidth}px)` } },
|
|
14477
15195
|
h('div', { style: { flex: '1 1 auto', minHeight: 0, display: 'flex', flexDirection: 'column' } }, leftPanel),
|
|
14478
15196
|
),
|
|
14479
15197
|
ui.sidebarOpen === false ? null : h('div', { className: 'gufa-splitter', onMouseDown: explorerDrag, title: '' }),
|
|
@@ -14555,7 +15273,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
14555
15273
|
h('div', { className: 'gufa-splitter', onMouseDown: chatDrag }),
|
|
14556
15274
|
h(
|
|
14557
15275
|
'div',
|
|
14558
|
-
{ className: 'gufa-chatpane', style: { width: chatWidth } },
|
|
15276
|
+
{ className: 'gufa-chatpane', style: { width: `var(--gufa-w-chat, ${chatWidth}px)` } },
|
|
14559
15277
|
h(G.ChatDock, {
|
|
14560
15278
|
project,
|
|
14561
15279
|
activeFile: activeFileForChat,
|