dsh-gufa-code 1.3.55 → 1.3.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js 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.55'
19
+ G.BUILD = '1.3.57'
20
20
  G.PANEL_ID = 'gufa-code'
21
21
  /** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
22
22
  G.pendingEntryWorkspace = null
@@ -832,6 +832,19 @@ G.compositeColor = function compositeColor(foreground, background) {
832
832
  * @returns {{bg:string, layer:string, layer2:string, overlay:string, sidebar:string}}
833
833
  */
834
834
  G.resolveSolidPalette = function resolveSolidPalette(container) {
835
+ /* 摸鱼悬浮窗是独立的 http origin,拿不到主窗口的 DSH 主题(默认会是浅色);
836
+ 摸鱼整窗本来就是深色半透明,这里强制返回深色实色板,避免出现浅色面板/看不清的弹窗。 */
837
+ try {
838
+ if (typeof document !== 'undefined' && document.documentElement !== null && document.documentElement.hasAttribute('data-gufa-float')) {
839
+ return {
840
+ bg: 'rgb(13, 15, 19)', layer: 'rgb(20, 22, 27)', layer2: 'rgb(26, 28, 34)', overlay: 'rgb(30, 33, 40)',
841
+ sidebar: 'rgb(18, 20, 24)', text: 'rgb(244, 241, 232)', textDim: 'rgb(166, 170, 176)',
842
+ accent: 'rgb(192, 57, 43)', isDark: true,
843
+ }
844
+ }
845
+ } catch {
846
+ /* ignore */
847
+ }
835
848
  const dark = G.theme() === 'dark'
836
849
  const fallbackPage = dark ? [26, 27, 31, 1] : [250, 250, 252, 1]
837
850
  const fallbackSurface = dark ? [45, 46, 51, 1] : [255, 255, 255, 1]
@@ -1088,7 +1101,16 @@ G.CSS = `
1088
1101
  .gufa-backdrop{position:absolute;inset:0;z-index:0;overflow:hidden;pointer-events:none}
1089
1102
  /* 桌面悬浮层(摸鱼)模式:整窗半透明,透明度由 --gufa-float-alpha 控制(标题栏滑块) */
1090
1103
  html[data-gufa-float]{--gufa-float-alpha:0.55}
1091
- html[data-gufa-float] body{background:transparent!important}
1104
+ html[data-gufa-float] body{background:transparent!important;color-scheme:dark;
1105
+ --dsw-alias-label-primary:#f4f1e8!important;--dsw-alias-label-secondary:rgba(244,241,232,0.72)!important;
1106
+ --dsw-alias-bg-base:#0d0f13!important;--dsw-alias-bg-layer-1:#14161b!important;--dsw-alias-bg-layer-2:#1a1e24!important;
1107
+ --dsw-alias-bg-overlay:#22262e!important;
1108
+ --dsw-alias-border-l1:rgba(255,255,255,0.12)!important;--dsw-alias-border-l2:rgba(255,255,255,0.2)!important;
1109
+ }
1110
+ html[data-gufa-float] .gufa-root,
1111
+ html[data-gufa-float] .gufa-overlay-root{
1112
+ --gufa-solid-text:#f4f1e8!important;--gufa-solid-text-dim:rgba(244,241,232,0.68)!important;
1113
+ }
1092
1114
  html[data-gufa-float] .gufa-overlay-root,
1093
1115
  html[data-gufa-float] .gufa-root{
1094
1116
  --gufa-solid-bg:rgba(13,15,19,var(--gufa-float-alpha))!important;--gufa-bg:rgba(13,15,19,var(--gufa-float-alpha))!important;
@@ -1108,6 +1130,29 @@ html[data-gufa-float] .gufa-overlay-root::before{
1108
1130
  background:rgba(13,15,19,var(--gufa-float-alpha));z-index:1;
1109
1131
  }
1110
1132
  html[data-gufa-float] .gufa-overlay-root{background:transparent!important;padding-top:22px;box-sizing:border-box}
1133
+ /* 摸鱼模式:弹窗/菜单都在 body 级 portal 里,拿不到摸鱼覆盖层的深色主题;
1134
+ 强制给 portal 一套深色可读变量,避免出现「浅色弹窗 + 浅色文字」看不清的问题。 */
1135
+ html[data-gufa-float] #gufa-portal-root{
1136
+ --gufa-solid-bg:#121418!important;--gufa-solid-layer:#191c21!important;--gufa-solid-layer2:#1e2228!important;--gufa-solid-overlay:#23272e!important;
1137
+ --gufa-solid-text:#f4f1e8!important;--gufa-solid-text-dim:rgba(244,241,232,0.68)!important;
1138
+ --dsw-alias-bg-base:#121418!important;--dsw-alias-bg-layer-1:#191c21!important;--dsw-alias-bg-layer-2:#1e2228!important;--dsw-alias-bg-overlay:#23272e!important;
1139
+ --dsw-alias-label-primary:#f4f1e8!important;--dsw-alias-label-secondary:rgba(244,241,232,0.68)!important;
1140
+ --dsw-alias-border-l1:rgba(255,255,255,0.12)!important;--dsw-alias-border-l2:rgba(255,255,255,0.2)!important;
1141
+ color:#f4f1e8!important;
1142
+ }
1143
+ html[data-gufa-float] #gufa-portal-root .gufa-modal,
1144
+ html[data-gufa-float] #gufa-portal-root .gufa-sessions-dialog,
1145
+ html[data-gufa-float] #gufa-portal-root .gufa-workspace-dialog,
1146
+ html[data-gufa-float] #gufa-portal-root .gufa-float-picker,
1147
+ html[data-gufa-float] #gufa-portal-root .gufa-shortcuts-dialog,
1148
+ html[data-gufa-float] #gufa-portal-root .gufa-graph-dialog{background:#1b1f26!important;color:#f4f1e8!important}
1149
+ html[data-gufa-float] #gufa-portal-root .gufa-modal-backdrop,
1150
+ html[data-gufa-float] .gufa-float-backdrop{
1151
+ background:rgba(0,0,0,0.66)!important;backdrop-filter:none!important;-webkit-backdrop-filter:none!important;
1152
+ }
1153
+ /* 摸鱼:所有 portal 弹窗/菜单/输入框不透明,保证字看得清 */
1154
+ html[data-gufa-float] #gufa-portal-root *{color:inherit}
1155
+ html[data-gufa-float] #gufa-portal-root .gufa-hint{color:rgba(244,241,232,0.72)!important}
1111
1156
  /* 摸鱼:整窗只保留「覆盖层根节点」这一层半透明底,其余面板/会话/终端全部透明,
1112
1157
  保证编辑器、会话框、终端框看到的透明度完全一致(都等于滑块的 alpha)。 */
1113
1158
  html[data-gufa-float] .gufa-overlay-root{background:rgba(13,15,19,var(--gufa-float-alpha))!important}
@@ -2690,7 +2735,7 @@ G.FooterAction = function FooterAction(props) {
2690
2735
 
2691
2736
  /* ── 组件 ───────────────────────────────────────────────────────────── */
2692
2737
 
2693
- G.EditorPane = function EditorPane(props) {
2738
+ function GufaEditorPaneComponent(props) {
2694
2739
  const tabs = useMemo(() => (Array.isArray(props.tabs) ? props.tabs : []), [props.tabs])
2695
2740
  const activePath = typeof props.activePath === 'string' ? props.activePath : null
2696
2741
  const root = typeof props.root === 'string' ? props.root : ''
@@ -3543,6 +3588,56 @@ G.FooterAction = function FooterAction(props) {
3543
3588
  )
3544
3589
  }
3545
3590
 
3591
+ /* 光标事件外部 store:App 不再为每次光标移动重渲染整个 IDE,状态栏订阅即可。 */
3592
+ G.cursorStore = (() => {
3593
+ const listeners = new Set()
3594
+ let value = null
3595
+ return {
3596
+ get: () => value,
3597
+ subscribe: (listener) => {
3598
+ listeners.add(listener)
3599
+ return () => listeners.delete(listener)
3600
+ },
3601
+ set: (next) => {
3602
+ if (value === next) return
3603
+ if (value !== null && next !== null &&
3604
+ value.path === next.path && value.line === next.line && value.column === next.column &&
3605
+ value.lineCount === next.lineCount && value.selectedText === next.selectedText) return
3606
+ value = next
3607
+ for (const listener of [...listeners]) {
3608
+ try {
3609
+ listener(next)
3610
+ } catch {
3611
+ /* 订阅者异常不影响编辑器 */
3612
+ }
3613
+ }
3614
+ },
3615
+ }
3616
+ })()
3617
+ G.useCursorStore = function useCursorStore() {
3618
+ const [snapshot, setSnapshot] = React.useState(G.cursorStore.get())
3619
+ React.useEffect(() => {
3620
+ setSnapshot(G.cursorStore.get())
3621
+ return G.cursorStore.subscribe(setSnapshot)
3622
+ }, [])
3623
+ return snapshot
3624
+ }
3625
+ /* 状态栏行数/光标:只订阅 cursorStore,光标移动不会触发 App 根组件重渲染。 */
3626
+ G.StatusCursor = function StatusCursor(props) {
3627
+ const activePath = props !== null && props !== undefined ? props.activePath : null
3628
+ const fallbackLineCount = props !== null && props !== undefined && Number.isFinite(props.fallbackLineCount) ? props.fallbackLineCount : 0
3629
+ const cursor = G.useCursorStore()
3630
+ const matched = cursor !== null && cursor.path === activePath
3631
+ const lineCount = matched && Number.isFinite(cursor.lineCount) ? cursor.lineCount : fallbackLineCount
3632
+ const cursorText = matched ? `${G.t('status.ln')} ${cursor.line},${G.t('status.col')} ${cursor.column}` : ''
3633
+ return React.createElement(React.Fragment, null,
3634
+ activePath !== null ? React.createElement('span', { className: 'gufa-status-item' }, `${lineCount} ${G.t('status.lines')}`) : null,
3635
+ cursorText !== '' ? React.createElement('span', { className: 'gufa-status-item' }, cursorText) : null,
3636
+ )
3637
+ }
3638
+ /* EditorPane 只在 props 真正变化时重渲染(光标移动不再穿透到 Monaco 外层)。 */
3639
+ G.EditorPane = typeof React.memo === 'function' ? React.memo(GufaEditorPaneComponent) : GufaEditorPaneComponent
3640
+
3546
3641
  /* 纯函数/加载状态测试钩子:供 scripts/test-editor.mjs 在无浏览器环境下校验
3547
3642
  * URI、光标推进、主题映射与 loader 失败降级 / 重试 / 单例注入。 */
3548
3643
  G.EditorPane.internals = Object.freeze({
@@ -9815,7 +9910,15 @@ G.GufaApp = function GufaApp(props) {
9815
9910
  const [banner, setBanner] = useState('')
9816
9911
  const [tabs, setTabs] = useState([])
9817
9912
  const [activePath, setActivePath] = useState(null)
9818
- const [cursor, setCursor] = useState(null)
9913
+ /* 选区(给右侧 AI 用)单独更新;光标位置/行数走 G.cursorStore,避免每次按键重渲染整个 IDE。 */
9914
+ const [selection, setSelection] = useState(null)
9915
+ /* 编辑器内容缓冲:Monaco 每次按键只写这里,300ms 停顿后才同步进 tabs(保存/自动保存直接读缓冲)。 */
9916
+ const editorBuffersRef = useRef(new Map())
9917
+ const tabsRef = useRef([])
9918
+ const flushTimerRef = useRef(null)
9919
+ const selectionTimerRef = useRef(null)
9920
+ const pendingSelectionRef = useRef(null)
9921
+ const flushBuffersRef = useRef(null)
9819
9922
  const [refreshToken, setRefreshToken] = useState(0)
9820
9923
  const [gitRefreshToken, setGitRefreshToken] = useState(0)
9821
9924
  const [sshRefreshToken, setSshRefreshToken] = useState(0)
@@ -9838,6 +9941,9 @@ G.GufaApp = function GufaApp(props) {
9838
9941
  const [explorerWidth, explorerDrag] = G.useSplitter({ initial: 260, min: 190, max: 520, storageKey: 'gufa-code:w:explorer' })
9839
9942
  const [chatWidth, chatDrag] = G.useSplitter({ initial: 430, min: 320, max: 780, axis: 'x', invert: true, storageKey: 'gufa-code:w:chat' })
9840
9943
  const [terminalHeight, terminalDrag] = G.useSplitter({ initial: 230, min: 120, max: 560, axis: 'y', invert: true, storageKey: 'gufa-code:h:terminal' })
9944
+ useEffect(() => {
9945
+ tabsRef.current = tabs
9946
+ }, [tabs])
9841
9947
 
9842
9948
  const patchUi = useCallback((patch) => {
9843
9949
  setUi((current) => {
@@ -9854,7 +9960,10 @@ G.GufaApp = function GufaApp(props) {
9854
9960
  writeJson(GUFA_LS.project, value?.root ?? null)
9855
9961
  setTabs([])
9856
9962
  setActivePath(null)
9857
- setCursor(null)
9963
+ setSelection(null)
9964
+ editorBuffersRef.current.clear()
9965
+ if (flushTimerRef.current !== null) { window.clearTimeout(flushTimerRef.current); flushTimerRef.current = null }
9966
+ G.cursorStore.set(null)
9858
9967
  setGitStatus(null)
9859
9968
  setRefreshToken((token) => token + 1)
9860
9969
  setGitRefreshToken((token) => token + 1)
@@ -9960,6 +10069,7 @@ G.GufaApp = function GufaApp(props) {
9960
10069
  /* ── 文件打开 / 保存 / 关闭 ─────────────────────────────────────────── */
9961
10070
  const openFile = useCallback(async (path) => {
9962
10071
  if (project === null) return
10072
+ flushBuffersRef.current?.()
9963
10073
  const existing = tabs.find((tab) => tab.path === path)
9964
10074
  if (existing !== undefined) {
9965
10075
  setActivePath(path)
@@ -9982,6 +10092,7 @@ G.GufaApp = function GufaApp(props) {
9982
10092
  /* 原子恢复标签集合:按快照顺序、去重、最后激活指定文件(避免 openFile 并发产生重复标签) */
9983
10093
  const applyTabs = useCallback(async (paths, active) => {
9984
10094
  if (project === null || !Array.isArray(paths)) return
10095
+ flushBuffersRef.current?.()
9985
10096
  const docs = []
9986
10097
  const seen = new Set()
9987
10098
  for (const path of paths.slice(0, 12)) {
@@ -9994,6 +10105,7 @@ G.GufaApp = function GufaApp(props) {
9994
10105
  /* 快照里的文件可能已被删除:忽略 */
9995
10106
  }
9996
10107
  }
10108
+ editorBuffersRef.current.clear()
9997
10109
  setTabs(docs)
9998
10110
  const wanted = typeof active === 'string' && docs.some((doc) => doc.path === active) ? active : (docs.length > 0 ? docs[docs.length - 1].path : null)
9999
10111
  setActivePath(wanted)
@@ -10002,27 +10114,85 @@ G.GufaApp = function GufaApp(props) {
10002
10114
  const activeTab = useMemo(() => tabs.find((tab) => tab.path === activePath) ?? null, [tabs, activePath])
10003
10115
 
10004
10116
  const patchTab = useCallback((path, patch) => {
10005
- setTabs((current) => current.map((tab) => (tab.path === path ? { ...tab, ...patch } : tab)))
10117
+ setTabs((current) => {
10118
+ const next = current.map((tab) => (tab.path === path ? { ...tab, ...patch } : tab))
10119
+ tabsRef.current = next
10120
+ return next
10121
+ })
10006
10122
  }, [])
10007
10123
 
10008
- const changeFile = useCallback((path, content) => {
10009
- setTabs((current) => current.map((tab) => (
10010
- tab.path === path ? { ...tab, content, dirty: content !== tab.savedContent } : tab
10011
- )))
10124
+ /* 把缓冲内容写回 tabs(停顿 / 保存 / 切换标签时调用),不会在每次按键触发渲染。 */
10125
+ const flushEditorBuffers = useCallback(() => {
10126
+ const buffers = editorBuffersRef.current
10127
+ if (buffers.size === 0) return
10128
+ setTabs((current) => {
10129
+ let changed = false
10130
+ const next = current.map((tab) => {
10131
+ if (tab === null || !buffers.has(tab.path)) return tab
10132
+ const content = buffers.get(tab.path)
10133
+ const dirty = content !== tab.savedContent
10134
+ if (tab.content === content && tab.dirty === dirty) return tab
10135
+ changed = true
10136
+ return { ...tab, content, dirty }
10137
+ })
10138
+ if (!changed) return current
10139
+ tabsRef.current = next
10140
+ return next
10141
+ })
10012
10142
  }, [])
10013
10143
 
10144
+ flushBuffersRef.current = flushEditorBuffers
10145
+
10146
+ const scheduleEditorFlush = useCallback(() => {
10147
+ if (flushTimerRef.current !== null) window.clearTimeout(flushTimerRef.current)
10148
+ flushTimerRef.current = window.setTimeout(() => {
10149
+ flushTimerRef.current = null
10150
+ flushEditorBuffers()
10151
+ }, 300)
10152
+ }, [flushEditorBuffers])
10153
+
10154
+ const changeFile = useCallback((path, content) => {
10155
+ editorBuffersRef.current.set(path, content)
10156
+ const tab = tabsRef.current.find((item) => item !== null && item.path === path)
10157
+ if (tab !== undefined && tab.dirty !== (content !== tab.savedContent)) {
10158
+ /* 只在「干净 ↔ 脏」变化时立刻更新标签圆点,避免每个按键重渲染整棵 IDE 树。 */
10159
+ setTabs((current) => {
10160
+ let changed = false
10161
+ const next = current.map((item) => {
10162
+ if (item === null || item.path !== path) return item
10163
+ const dirty = content !== item.savedContent
10164
+ if (item.dirty === dirty) return item
10165
+ changed = true
10166
+ return { ...item, dirty }
10167
+ })
10168
+ if (!changed) return current
10169
+ tabsRef.current = next
10170
+ return next
10171
+ })
10172
+ }
10173
+ scheduleEditorFlush()
10174
+ }, [scheduleEditorFlush])
10175
+
10014
10176
  const saveFile = useCallback(async (path) => {
10015
10177
  if (project === null) return
10016
- const tab = tabs.find((item) => item.path === path)
10017
- if (tab === undefined || tab.dirty !== true) return
10178
+ const tab = tabsRef.current.find((item) => item !== null && item.path === path)
10179
+ if (tab === undefined) return
10180
+ /* 缓冲里可能有比 tabs 更新的内容(按键后 300ms 内保存/自动保存) */
10181
+ const content = editorBuffersRef.current.has(path) ? editorBuffersRef.current.get(path) : tab.content
10182
+ if (content === tab.savedContent) {
10183
+ editorBuffersRef.current.delete(path)
10184
+ if (tab.dirty === true) patchTab(path, { content, dirty: false })
10185
+ return
10186
+ }
10018
10187
  try {
10019
10188
  const result = await G.api('fs.write', {
10020
10189
  root: project.root,
10021
10190
  path: tab.path,
10022
- content: tab.content,
10191
+ content,
10023
10192
  expectedRevision: tab.revision,
10024
10193
  })
10025
- patchTab(path, { revision: result.revision, savedRevision: result.revision, savedContent: tab.content, dirty: false, size: result.size })
10194
+ editorBuffersRef.current.delete(path)
10195
+ patchTab(path, { content, revision: result.revision, savedRevision: result.revision, savedContent: content, dirty: false, size: result.size })
10026
10196
  setBanner('')
10027
10197
  // 内容保存不改变目录结构:只刷新 Git 状态,不重载文件树(避免整页闪烁)
10028
10198
  setGitRefreshToken((token) => token + 1)
@@ -10031,7 +10201,7 @@ G.GufaApp = function GufaApp(props) {
10031
10201
  if (error.code === 'revision-conflict') setBanner(t('editor.saveConflict'))
10032
10202
  else setBanner(G.errorText(error))
10033
10203
  }
10034
- }, [project, tabs, patchTab, refreshGit, t])
10204
+ }, [project, patchTab, refreshGit, t])
10035
10205
 
10036
10206
  /** 顶栏提示:错误常驻红色;成功用绿色 toast,1.2 秒后自动消失。 */
10037
10207
  const successTimerRef = useRef(null)
@@ -10057,6 +10227,8 @@ G.GufaApp = function GufaApp(props) {
10057
10227
  }, [])
10058
10228
 
10059
10229
  const closeTab = useCallback((path) => {
10230
+ editorBuffersRef.current.delete(path)
10231
+ flushBuffersRef.current?.()
10060
10232
  setTabs((current) => {
10061
10233
  const next = current.filter((tab) => tab.path !== path)
10062
10234
  if (activePath === path) {
@@ -11367,10 +11539,7 @@ G.GufaApp = function GufaApp(props) {
11367
11539
  return { path: activeTab.path, content: activeTab.content ?? '', language: activeTab.language }
11368
11540
  }, [activeTab])
11369
11541
 
11370
- const selectionForChat = useMemo(() => {
11371
- if (cursor === null || typeof cursor.selectedText !== 'string' || cursor.selectedText === '') return null
11372
- return { text: cursor.selectedText, path: cursor.path, line: cursor.line, column: cursor.column }
11373
- }, [cursor])
11542
+ const selectionForChat = useMemo(() => selection, [selection])
11374
11543
 
11375
11544
  /* ── IDE 专属快捷键(参考 VS Code;经典模式下不生效) ──────────────── */
11376
11545
  const editorFocusedRef = useRef(false)
@@ -11582,7 +11751,7 @@ G.GufaApp = function GufaApp(props) {
11582
11751
  role: 'tab',
11583
11752
  tabIndex: 0,
11584
11753
  title: tab.title !== undefined && tab.title !== null ? tab.title : tab.path,
11585
- onClick: () => setActivePath(tab.path),
11754
+ onClick: () => handleSelectTab(tab.path),
11586
11755
  onAuxClick: (event) => { if (event.button === 1) closeTabWithConfirm(tab.path) },
11587
11756
  },
11588
11757
  h(G.Icon, { name: 'file', size: 13 }),
@@ -11637,11 +11806,41 @@ G.GufaApp = function GufaApp(props) {
11637
11806
  )
11638
11807
  : null
11639
11808
 
11640
- const cursorText =
11641
- cursor !== null && cursor.path === activePath
11642
- ? `${t('status.ln')} ${cursor.line},${t('status.col')} ${cursor.column}`
11643
- : ''
11809
+ const handleEditorCursor = useCallback((value) => {
11810
+ if (value === null || value === undefined) return
11811
+ /* 状态栏订阅 cursorStore,不再触发 App 根组件渲染 */
11812
+ G.cursorStore.set(value)
11813
+ const selectedText = typeof value.selectedText === 'string' ? value.selectedText : ''
11814
+ if (selectedText === '') {
11815
+ if (selectionTimerRef.current !== null) { window.clearTimeout(selectionTimerRef.current); selectionTimerRef.current = null }
11816
+ pendingSelectionRef.current = null
11817
+ setSelection((current) => (current === null ? current : null))
11818
+ return
11819
+ }
11820
+ pendingSelectionRef.current = { text: selectedText, path: value.path, line: value.line, column: value.column }
11821
+ if (selectionTimerRef.current !== null) return
11822
+ selectionTimerRef.current = window.setTimeout(() => {
11823
+ selectionTimerRef.current = null
11824
+ const latest = pendingSelectionRef.current
11825
+ if (latest === null) return
11826
+ setSelection((current) => {
11827
+ if (current !== null && current.text === latest.text && current.path === latest.path &&
11828
+ current.line === latest.line && current.column === latest.column) return current
11829
+ return latest
11830
+ })
11831
+ }, 180)
11832
+ }, [])
11833
+ const handleEditorSave = useCallback((path) => { void saveFile(path) }, [saveFile])
11834
+ const handleSelectTab = useCallback((path) => {
11835
+ flushBuffersRef.current?.()
11836
+ setActivePath(path)
11837
+ }, [])
11838
+ useEffect(() => () => {
11839
+ if (flushTimerRef.current !== null) { window.clearTimeout(flushTimerRef.current); flushTimerRef.current = null }
11840
+ if (selectionTimerRef.current !== null) { window.clearTimeout(selectionTimerRef.current); selectionTimerRef.current = null }
11841
+ }, [])
11644
11842
 
11843
+ const uiTheme = moyuMode ? 'dark' : theme
11645
11844
  const statusBranch = project?.isGit === true && gitStatus?.branch ? gitStatus.branch : null
11646
11845
  const lineCount = activeTab === null || activeTab.kind === 'graph' ? 0 : String(activeTab.content ?? '').split('\n').length
11647
11846
 
@@ -11832,15 +12031,15 @@ G.GufaApp = function GufaApp(props) {
11832
12031
  : h(G.EditorPane, {
11833
12032
  tabs,
11834
12033
  activePath,
11835
- theme,
12034
+ theme: uiTheme,
11836
12035
  palette: solidPalette,
11837
12036
  root: project?.root ?? '',
11838
- onSelectTab: setActivePath,
12037
+ onSelectTab: handleSelectTab,
11839
12038
  onCloseTab: closeTabWithConfirm,
11840
12039
  onChange: changeFile,
11841
- onSave: (path) => void saveFile(path),
12040
+ onSave: handleEditorSave,
11842
12041
  backdropMode: backdropActive,
11843
- onCursor: (value) => setCursor({ ...value, lineCount }),
12042
+ onCursor: handleEditorCursor,
11844
12043
  }),
11845
12044
  ),
11846
12045
  ),
@@ -11855,7 +12054,7 @@ G.GufaApp = function GufaApp(props) {
11855
12054
  root: project?.root ?? null,
11856
12055
  visible: true,
11857
12056
  height: terminalHeight,
11858
- theme,
12057
+ theme: uiTheme,
11859
12058
  palette: solidPalette,
11860
12059
  onToggleHeight: () => patchUi({ terminalOpen: false }),
11861
12060
  }),
@@ -11875,11 +12074,12 @@ G.GufaApp = function GufaApp(props) {
11875
12074
  project,
11876
12075
  activeFile: activeFileForChat,
11877
12076
  selection: selectionForChat,
11878
- theme,
12077
+ theme: uiTheme,
11879
12078
  width: chatWidth,
11880
12079
  active: true,
11881
12080
  paused: sessionsOpen,
11882
12081
  backdrop: backdropActive,
12082
+ theme: uiTheme,
11883
12083
  sessionTitle,
11884
12084
  onOpenSessions: () => setSessionsOpen(true),
11885
12085
  onInsertCode: insertCode,
@@ -11913,11 +12113,10 @@ G.GufaApp = function GufaApp(props) {
11913
12113
  : h('span', { className: 'gufa-status-item' }, t('status.noGit')),
11914
12114
  h('div', { className: 'gufa-status-fill' }),
11915
12115
  activeTab !== null ? h('span', { className: 'gufa-status-item' }, activeTab.title !== undefined && activeTab.title !== null ? activeTab.title : G.shortPath(activeTab.path, 56)) : null,
11916
- activeTab !== null ? h('span', { className: 'gufa-status-item' }, `${lineCount} ${t('status.lines')}`) : null,
11917
12116
  activeTab !== null && problems[activeTab.path] !== undefined
11918
12117
  ? h('span', { className: 'gufa-status-item', style: { color: problems[activeTab.path].errors > 0 ? '#f85149' : '#e5c07b' } }, `${problems[activeTab.path].errors} ✕ ${problems[activeTab.path].warnings} ⚠`)
11919
12118
  : null,
11920
- cursorText !== '' ? h('span', { className: 'gufa-status-item' }, cursorText) : null,
12119
+ h(G.StatusCursor, { activePath, fallbackLineCount: lineCount }),
11921
12120
  activeTab !== null && activeTab.dirty === true ? h('span', { className: 'gufa-status-item', style: { color: 'var(--gufa-accent)' } }, t('status.dirty')) : null,
11922
12121
  activeTab !== null && activeTab.dirty !== true ? h('span', { className: 'gufa-status-item' }, G.Icon ? h(G.Icon, { name: 'check', size: 11 }) : null, t('status.saved')) : null,
11923
12122
  h('button', {
@@ -13065,6 +13264,56 @@ const GUFA_PLUGIN = {
13065
13264
  }
13066
13265
  }
13067
13266
 
13267
+ // 临时诊断(1.3.57):摸鱼窗口里点不到左树/编辑器时,看看点击落到了哪个元素
13268
+ try {
13269
+ if (document.documentElement.hasAttribute('data-gufa-float') || /[?&]gufa-float=1/.test(location.search)) {
13270
+ setTimeout(() => {
13271
+ const probeAt = (x, y) => {
13272
+ try {
13273
+ const node = document.elementFromPoint(x, y)
13274
+ if (node === null) return `${x},${y}:none`
13275
+ const cls = typeof node.className === 'string' ? node.className : ''
13276
+ return `${x},${y}:${node.tagName}.${String(cls).slice(0, 60)}`
13277
+ } catch (error) {
13278
+ return `${x},${y}:err`
13279
+ }
13280
+ }
13281
+ // 模态框深色可读性:往 portal 里塞一个临时 .gufa-modal 读计算样式
13282
+ let modalInfo = 'none'
13283
+ try {
13284
+ const host = document.getElementById('gufa-portal-root')
13285
+ if (host !== null) {
13286
+ const probe = document.createElement('div')
13287
+ probe.className = 'gufa-modal'
13288
+ probe.style.cssText = 'position:fixed;left:-9999px;top:0;width:120px;height:60px'
13289
+ host.appendChild(probe)
13290
+ const cs = window.getComputedStyle(probe)
13291
+ modalInfo = `bg=${cs.backgroundColor} color=${cs.color}`
13292
+ probe.remove()
13293
+ }
13294
+ } catch {
13295
+ modalInfo = 'err'
13296
+ }
13297
+ // 找树行实际坐标(摸鱼窗半透明,肉眼看不清哪些行是古法的)
13298
+ const rows = []
13299
+ for (let y = 80; y < 1000; y += 22) {
13300
+ try {
13301
+ const node = document.elementFromPoint(100, y)
13302
+ if (node !== null && typeof node.closest === 'function') {
13303
+ const row = node.closest('.gufa-tree-row')
13304
+ if (row !== null) rows.push(`${y}:${String(row.textContent ?? '').trim().slice(0, 24)}`)
13305
+ }
13306
+ } catch {
13307
+ /* ignore */
13308
+ }
13309
+ }
13310
+ void G.api('dev.log', { message: `float-hittest ${probeAt(135, 713)} | ${probeAt(300, 713)} | ${probeAt(900, 500)} | ${probeAt(1500, 60)} | modal[${modalInfo}] | rows[${rows.slice(0, 12).join(' ; ')}]` }).catch(() => {})
13311
+ }, 5000)
13312
+ }
13313
+ } catch {
13314
+ /* ignore */
13315
+ }
13316
+
13068
13317
  // 启动诊断:记录页面地址、真实 Host 基址与传输信息(排查桌面壳 dsh-app:// 连接问题)。
13069
13318
  try {
13070
13319
  const transport = typeof globalThis.__DSH_TRANSPORT__ === 'object' && globalThis.__DSH_TRANSPORT__ !== null ? globalThis.__DSH_TRANSPORT__ : null
@@ -63,6 +63,15 @@ static void GufaInstallTermHandler(void);
63
63
 
64
64
  static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
65
65
 
66
+ /* 无边框窗口默认 canBecomeKeyWindow=NO;显式允许成为 key/main 窗口,
67
+ 否则悬浮层里的终端/编辑器/聊天输入都收不到键盘事件。 */
68
+ @interface GufaFloatWindow : NSWindow
69
+ @end
70
+ @implementation GufaFloatWindow
71
+ - (BOOL)canBecomeKeyWindow { return YES; }
72
+ - (BOOL)canBecomeMainWindow { return YES; }
73
+ @end
74
+
66
75
  @interface GufaDragStrip : NSView
67
76
  @end
68
77
 
@@ -341,7 +350,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
341
350
  }
342
351
  }
343
352
 
344
- self.window = [[NSWindow alloc] initWithContentRect:frame
353
+ self.window = [[GufaFloatWindow alloc] initWithContentRect:frame
345
354
  styleMask:(NSWindowStyleMaskBorderless | NSWindowStyleMaskResizable)
346
355
  backing:NSBackingStoreBuffered
347
356
  defer:NO];
@@ -7,8 +7,8 @@
7
7
  <key>CFBundleDisplayName</key><string>古法编程悬浮层</string>
8
8
  <key>CFBundleExecutable</key><string>gufa-float</string>
9
9
  <key>CFBundlePackageType</key><string>APPL</string>
10
- <key>CFBundleShortVersionString</key><string>1.3.55</string>
11
- <key>CFBundleVersion</key><string>1.3.55</string>
10
+ <key>CFBundleShortVersionString</key><string>1.3.57</string>
11
+ <key>CFBundleVersion</key><string>1.3.57</string>
12
12
  <key>LSUIElement</key><true/>
13
13
  <key>NSHighResolutionCapable</key><true/>
14
14
  <key>NSPrincipalClass</key><string>NSApplication</string>
@@ -104,6 +104,19 @@
104
104
  `SLSAddWindowsToSpaces` 把自己的窗口加进去(实测 `use-active-space=8234 err=0`)。
105
105
  3. 私有 API 全部 dlsym,符号缺失时只记日志不影响主流程。
106
106
 
107
+ ## 摸鱼窗口里的两个系统性问题(1.3.57 修复)
108
+
109
+ 1. **摸鱼窗口是独立 http origin,DSH 主题默认是浅色**:主窗口(dsh-app://)的深色主题在悬浮窗里不存在,
110
+ 导致 IDE 面板/弹窗呈现浅色:深色半透明底 + 浅色文字/弹窗,字看不清。
111
+ - 修复:`G.resolveSolidPalette` 在 `html[data-gufa-float]` 下强制返回深色实色板;
112
+ `html[data-gufa-float] body` 与 `#gufa-portal-root` 强制深色 `--dsw-alias-*` token;
113
+ App 在摸鱼模式把 `theme` 固定为 `dark`(Monaco/终端)。
114
+ - 注意:portal/弹窗在 body 层,CSS 变量要用 `!important`,因为 `applyPalette` 会往 portal 上写 inline 变量。
115
+ 2. **无边框 NSWindow 默认 `canBecomeKeyWindow=NO`**:悬浮窗收不到键盘事件,终端/编辑器/聊天都输入不了。
116
+ - 修复:`GufaFloatWindow` 子类覆写 `canBecomeKeyWindow/canBecomeMainWindow` 返回 YES。
117
+ - 排查要点:`float-hittest` 日志会打印 elementFromPoint 与临时 `.gufa-modal` 的计算样式(bg/color),
118
+ `float-styles` 打印覆盖层透明度;终端输入问题优先看窗口是否 key,而不是 transport。
119
+
107
120
  ## 5.1 摸鱼会话框比编辑器黑:官方会话根节点自己又画了一层底
108
121
 
109
122
  - 现象:摸鱼里编辑器/终端都统一了,右侧会话框看起来明显更黑更实。
@@ -0,0 +1,37 @@
1
+ # 编辑器性能设计(避免按键「不跟手」)
2
+
3
+ Monaco 本身很快;古法编程编辑器之前卡顿的主要原因是 **React 状态更新链路**:
4
+ 每按一个键,Monaco 的 `onDidChangeModelContent` 会同步到 App 状态,导致整个 IDE
5
+ (资源管理器、终端、右侧 AI 会话、状态栏…)重渲染一次;光标位置变化又触发一次。
6
+ 快捷键连打时就是每秒几十次整树渲染。
7
+
8
+ ## 现在的实现
9
+
10
+ 1. **内容缓冲区(不在每次按键时 setState)**
11
+ - `onChange(path, content)` 只写入 `editorBuffersRef`(ref,不触发渲染);
12
+ - 只有「干净 ↔ 脏」变化时更新一次 tabs(标签圆点),每个编辑段最多一次;
13
+ - 停顿 **300ms** 后用 `flushEditorBuffers()` 把缓冲内容同步进 tabs(一次渲染);
14
+ - 保存 / 自动保存(700ms)/ 关闭标签前**直接读缓冲**,所以不会写入旧内容;
15
+ - 撤销到与磁盘一致时会自动变回「已保存」。
16
+
17
+ 2. **光标/行号走外部 store**
18
+ - Monaco 的光标事件写入 `G.cursorStore`(module-level,去重 + 订阅),
19
+ - 状态栏的 `G.StatusCursor` 用 `useSyncExternalStore` 订阅,**只渲染状态栏那一小块**;
20
+ - App 根组件不再因为光标移动而重渲染;选区(AI 引用用)180ms 防抖后单独更新。
21
+
22
+ 3. **EditorPane 用 React.memo + 稳定回调**
23
+ - 父组件因其它原因重渲染时,只要 tabs/activePath/theme 等 props 没变,Monaco 外层不重渲染;
24
+ - `onChange/onSave/onSelectTab/onCursor` 都用 `useCallback`,依赖只包含真正会变的数据。
25
+
26
+ ## 实测(macOS,113 行文本文件)
27
+
28
+ - 连续输入 `abc`:标签立即变脏、状态栏 Ln/Col 正常更新;
29
+ - 自动保存在 700ms 档内把 `abc` 写入磁盘(通过 Host `fs.read` 校验内容 +3 字节);
30
+ - `Cmd+Z` 撤销后自动保存把文件恢复为原始内容(与 baseline 全等);
31
+ - 三套测试 99 / 44 / 19 全过。
32
+
33
+ ## 后续可继续优化(未做)
34
+
35
+ - 超大文件(数万行)时 Monaco `model.getValue()` 每次变更复制整个字符串,可改为增量取内容/仅在 flush 时取;
36
+ - 右侧 AI 流式回复时 App 的频繁更新可进一步拆分订阅;
37
+ - 资源管理器大目录可做虚拟滚动。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.55",
3
+ "version": "1.3.57",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -824,6 +824,19 @@ G.compositeColor = function compositeColor(foreground, background) {
824
824
  * @returns {{bg:string, layer:string, layer2:string, overlay:string, sidebar:string}}
825
825
  */
826
826
  G.resolveSolidPalette = function resolveSolidPalette(container) {
827
+ /* 摸鱼悬浮窗是独立的 http origin,拿不到主窗口的 DSH 主题(默认会是浅色);
828
+ 摸鱼整窗本来就是深色半透明,这里强制返回深色实色板,避免出现浅色面板/看不清的弹窗。 */
829
+ try {
830
+ if (typeof document !== 'undefined' && document.documentElement !== null && document.documentElement.hasAttribute('data-gufa-float')) {
831
+ return {
832
+ bg: 'rgb(13, 15, 19)', layer: 'rgb(20, 22, 27)', layer2: 'rgb(26, 28, 34)', overlay: 'rgb(30, 33, 40)',
833
+ sidebar: 'rgb(18, 20, 24)', text: 'rgb(244, 241, 232)', textDim: 'rgb(166, 170, 176)',
834
+ accent: 'rgb(192, 57, 43)', isDark: true,
835
+ }
836
+ }
837
+ } catch {
838
+ /* ignore */
839
+ }
827
840
  const dark = G.theme() === 'dark'
828
841
  const fallbackPage = dark ? [26, 27, 31, 1] : [250, 250, 252, 1]
829
842
  const fallbackSurface = dark ? [45, 46, 51, 1] : [255, 255, 255, 1]
@@ -1080,7 +1093,16 @@ G.CSS = `
1080
1093
  .gufa-backdrop{position:absolute;inset:0;z-index:0;overflow:hidden;pointer-events:none}
1081
1094
  /* 桌面悬浮层(摸鱼)模式:整窗半透明,透明度由 --gufa-float-alpha 控制(标题栏滑块) */
1082
1095
  html[data-gufa-float]{--gufa-float-alpha:0.55}
1083
- html[data-gufa-float] body{background:transparent!important}
1096
+ html[data-gufa-float] body{background:transparent!important;color-scheme:dark;
1097
+ --dsw-alias-label-primary:#f4f1e8!important;--dsw-alias-label-secondary:rgba(244,241,232,0.72)!important;
1098
+ --dsw-alias-bg-base:#0d0f13!important;--dsw-alias-bg-layer-1:#14161b!important;--dsw-alias-bg-layer-2:#1a1e24!important;
1099
+ --dsw-alias-bg-overlay:#22262e!important;
1100
+ --dsw-alias-border-l1:rgba(255,255,255,0.12)!important;--dsw-alias-border-l2:rgba(255,255,255,0.2)!important;
1101
+ }
1102
+ html[data-gufa-float] .gufa-root,
1103
+ html[data-gufa-float] .gufa-overlay-root{
1104
+ --gufa-solid-text:#f4f1e8!important;--gufa-solid-text-dim:rgba(244,241,232,0.68)!important;
1105
+ }
1084
1106
  html[data-gufa-float] .gufa-overlay-root,
1085
1107
  html[data-gufa-float] .gufa-root{
1086
1108
  --gufa-solid-bg:rgba(13,15,19,var(--gufa-float-alpha))!important;--gufa-bg:rgba(13,15,19,var(--gufa-float-alpha))!important;
@@ -1100,6 +1122,29 @@ html[data-gufa-float] .gufa-overlay-root::before{
1100
1122
  background:rgba(13,15,19,var(--gufa-float-alpha));z-index:1;
1101
1123
  }
1102
1124
  html[data-gufa-float] .gufa-overlay-root{background:transparent!important;padding-top:22px;box-sizing:border-box}
1125
+ /* 摸鱼模式:弹窗/菜单都在 body 级 portal 里,拿不到摸鱼覆盖层的深色主题;
1126
+ 强制给 portal 一套深色可读变量,避免出现「浅色弹窗 + 浅色文字」看不清的问题。 */
1127
+ html[data-gufa-float] #gufa-portal-root{
1128
+ --gufa-solid-bg:#121418!important;--gufa-solid-layer:#191c21!important;--gufa-solid-layer2:#1e2228!important;--gufa-solid-overlay:#23272e!important;
1129
+ --gufa-solid-text:#f4f1e8!important;--gufa-solid-text-dim:rgba(244,241,232,0.68)!important;
1130
+ --dsw-alias-bg-base:#121418!important;--dsw-alias-bg-layer-1:#191c21!important;--dsw-alias-bg-layer-2:#1e2228!important;--dsw-alias-bg-overlay:#23272e!important;
1131
+ --dsw-alias-label-primary:#f4f1e8!important;--dsw-alias-label-secondary:rgba(244,241,232,0.68)!important;
1132
+ --dsw-alias-border-l1:rgba(255,255,255,0.12)!important;--dsw-alias-border-l2:rgba(255,255,255,0.2)!important;
1133
+ color:#f4f1e8!important;
1134
+ }
1135
+ html[data-gufa-float] #gufa-portal-root .gufa-modal,
1136
+ html[data-gufa-float] #gufa-portal-root .gufa-sessions-dialog,
1137
+ html[data-gufa-float] #gufa-portal-root .gufa-workspace-dialog,
1138
+ html[data-gufa-float] #gufa-portal-root .gufa-float-picker,
1139
+ html[data-gufa-float] #gufa-portal-root .gufa-shortcuts-dialog,
1140
+ html[data-gufa-float] #gufa-portal-root .gufa-graph-dialog{background:#1b1f26!important;color:#f4f1e8!important}
1141
+ html[data-gufa-float] #gufa-portal-root .gufa-modal-backdrop,
1142
+ html[data-gufa-float] .gufa-float-backdrop{
1143
+ background:rgba(0,0,0,0.66)!important;backdrop-filter:none!important;-webkit-backdrop-filter:none!important;
1144
+ }
1145
+ /* 摸鱼:所有 portal 弹窗/菜单/输入框不透明,保证字看得清 */
1146
+ html[data-gufa-float] #gufa-portal-root *{color:inherit}
1147
+ html[data-gufa-float] #gufa-portal-root .gufa-hint{color:rgba(244,241,232,0.72)!important}
1103
1148
  /* 摸鱼:整窗只保留「覆盖层根节点」这一层半透明底,其余面板/会话/终端全部透明,
1104
1149
  保证编辑器、会话框、终端框看到的透明度完全一致(都等于滑块的 alpha)。 */
1105
1150
  html[data-gufa-float] .gufa-overlay-root{background:rgba(13,15,19,var(--gufa-float-alpha))!important}
@@ -494,7 +494,7 @@
494
494
 
495
495
  /* ── 组件 ───────────────────────────────────────────────────────────── */
496
496
 
497
- G.EditorPane = function EditorPane(props) {
497
+ function GufaEditorPaneComponent(props) {
498
498
  const tabs = useMemo(() => (Array.isArray(props.tabs) ? props.tabs : []), [props.tabs])
499
499
  const activePath = typeof props.activePath === 'string' ? props.activePath : null
500
500
  const root = typeof props.root === 'string' ? props.root : ''
@@ -1347,6 +1347,56 @@
1347
1347
  )
1348
1348
  }
1349
1349
 
1350
+ /* 光标事件外部 store:App 不再为每次光标移动重渲染整个 IDE,状态栏订阅即可。 */
1351
+ G.cursorStore = (() => {
1352
+ const listeners = new Set()
1353
+ let value = null
1354
+ return {
1355
+ get: () => value,
1356
+ subscribe: (listener) => {
1357
+ listeners.add(listener)
1358
+ return () => listeners.delete(listener)
1359
+ },
1360
+ set: (next) => {
1361
+ if (value === next) return
1362
+ if (value !== null && next !== null &&
1363
+ value.path === next.path && value.line === next.line && value.column === next.column &&
1364
+ value.lineCount === next.lineCount && value.selectedText === next.selectedText) return
1365
+ value = next
1366
+ for (const listener of [...listeners]) {
1367
+ try {
1368
+ listener(next)
1369
+ } catch {
1370
+ /* 订阅者异常不影响编辑器 */
1371
+ }
1372
+ }
1373
+ },
1374
+ }
1375
+ })()
1376
+ G.useCursorStore = function useCursorStore() {
1377
+ const [snapshot, setSnapshot] = React.useState(G.cursorStore.get())
1378
+ React.useEffect(() => {
1379
+ setSnapshot(G.cursorStore.get())
1380
+ return G.cursorStore.subscribe(setSnapshot)
1381
+ }, [])
1382
+ return snapshot
1383
+ }
1384
+ /* 状态栏行数/光标:只订阅 cursorStore,光标移动不会触发 App 根组件重渲染。 */
1385
+ G.StatusCursor = function StatusCursor(props) {
1386
+ const activePath = props !== null && props !== undefined ? props.activePath : null
1387
+ const fallbackLineCount = props !== null && props !== undefined && Number.isFinite(props.fallbackLineCount) ? props.fallbackLineCount : 0
1388
+ const cursor = G.useCursorStore()
1389
+ const matched = cursor !== null && cursor.path === activePath
1390
+ const lineCount = matched && Number.isFinite(cursor.lineCount) ? cursor.lineCount : fallbackLineCount
1391
+ const cursorText = matched ? `${G.t('status.ln')} ${cursor.line},${G.t('status.col')} ${cursor.column}` : ''
1392
+ return React.createElement(React.Fragment, null,
1393
+ activePath !== null ? React.createElement('span', { className: 'gufa-status-item' }, `${lineCount} ${G.t('status.lines')}`) : null,
1394
+ cursorText !== '' ? React.createElement('span', { className: 'gufa-status-item' }, cursorText) : null,
1395
+ )
1396
+ }
1397
+ /* EditorPane 只在 props 真正变化时重渲染(光标移动不再穿透到 Monaco 外层)。 */
1398
+ G.EditorPane = typeof React.memo === 'function' ? React.memo(GufaEditorPaneComponent) : GufaEditorPaneComponent
1399
+
1350
1400
  /* 纯函数/加载状态测试钩子:供 scripts/test-editor.mjs 在无浏览器环境下校验
1351
1401
  * URI、光标推进、主题映射与 loader 失败降级 / 重试 / 单例注入。 */
1352
1402
  G.EditorPane.internals = Object.freeze({
@@ -250,7 +250,15 @@ G.GufaApp = function GufaApp(props) {
250
250
  const [banner, setBanner] = useState('')
251
251
  const [tabs, setTabs] = useState([])
252
252
  const [activePath, setActivePath] = useState(null)
253
- const [cursor, setCursor] = useState(null)
253
+ /* 选区(给右侧 AI 用)单独更新;光标位置/行数走 G.cursorStore,避免每次按键重渲染整个 IDE。 */
254
+ const [selection, setSelection] = useState(null)
255
+ /* 编辑器内容缓冲:Monaco 每次按键只写这里,300ms 停顿后才同步进 tabs(保存/自动保存直接读缓冲)。 */
256
+ const editorBuffersRef = useRef(new Map())
257
+ const tabsRef = useRef([])
258
+ const flushTimerRef = useRef(null)
259
+ const selectionTimerRef = useRef(null)
260
+ const pendingSelectionRef = useRef(null)
261
+ const flushBuffersRef = useRef(null)
254
262
  const [refreshToken, setRefreshToken] = useState(0)
255
263
  const [gitRefreshToken, setGitRefreshToken] = useState(0)
256
264
  const [sshRefreshToken, setSshRefreshToken] = useState(0)
@@ -273,6 +281,9 @@ G.GufaApp = function GufaApp(props) {
273
281
  const [explorerWidth, explorerDrag] = G.useSplitter({ initial: 260, min: 190, max: 520, storageKey: 'gufa-code:w:explorer' })
274
282
  const [chatWidth, chatDrag] = G.useSplitter({ initial: 430, min: 320, max: 780, axis: 'x', invert: true, storageKey: 'gufa-code:w:chat' })
275
283
  const [terminalHeight, terminalDrag] = G.useSplitter({ initial: 230, min: 120, max: 560, axis: 'y', invert: true, storageKey: 'gufa-code:h:terminal' })
284
+ useEffect(() => {
285
+ tabsRef.current = tabs
286
+ }, [tabs])
276
287
 
277
288
  const patchUi = useCallback((patch) => {
278
289
  setUi((current) => {
@@ -289,7 +300,10 @@ G.GufaApp = function GufaApp(props) {
289
300
  writeJson(GUFA_LS.project, value?.root ?? null)
290
301
  setTabs([])
291
302
  setActivePath(null)
292
- setCursor(null)
303
+ setSelection(null)
304
+ editorBuffersRef.current.clear()
305
+ if (flushTimerRef.current !== null) { window.clearTimeout(flushTimerRef.current); flushTimerRef.current = null }
306
+ G.cursorStore.set(null)
293
307
  setGitStatus(null)
294
308
  setRefreshToken((token) => token + 1)
295
309
  setGitRefreshToken((token) => token + 1)
@@ -395,6 +409,7 @@ G.GufaApp = function GufaApp(props) {
395
409
  /* ── 文件打开 / 保存 / 关闭 ─────────────────────────────────────────── */
396
410
  const openFile = useCallback(async (path) => {
397
411
  if (project === null) return
412
+ flushBuffersRef.current?.()
398
413
  const existing = tabs.find((tab) => tab.path === path)
399
414
  if (existing !== undefined) {
400
415
  setActivePath(path)
@@ -417,6 +432,7 @@ G.GufaApp = function GufaApp(props) {
417
432
  /* 原子恢复标签集合:按快照顺序、去重、最后激活指定文件(避免 openFile 并发产生重复标签) */
418
433
  const applyTabs = useCallback(async (paths, active) => {
419
434
  if (project === null || !Array.isArray(paths)) return
435
+ flushBuffersRef.current?.()
420
436
  const docs = []
421
437
  const seen = new Set()
422
438
  for (const path of paths.slice(0, 12)) {
@@ -429,6 +445,7 @@ G.GufaApp = function GufaApp(props) {
429
445
  /* 快照里的文件可能已被删除:忽略 */
430
446
  }
431
447
  }
448
+ editorBuffersRef.current.clear()
432
449
  setTabs(docs)
433
450
  const wanted = typeof active === 'string' && docs.some((doc) => doc.path === active) ? active : (docs.length > 0 ? docs[docs.length - 1].path : null)
434
451
  setActivePath(wanted)
@@ -437,27 +454,85 @@ G.GufaApp = function GufaApp(props) {
437
454
  const activeTab = useMemo(() => tabs.find((tab) => tab.path === activePath) ?? null, [tabs, activePath])
438
455
 
439
456
  const patchTab = useCallback((path, patch) => {
440
- setTabs((current) => current.map((tab) => (tab.path === path ? { ...tab, ...patch } : tab)))
457
+ setTabs((current) => {
458
+ const next = current.map((tab) => (tab.path === path ? { ...tab, ...patch } : tab))
459
+ tabsRef.current = next
460
+ return next
461
+ })
441
462
  }, [])
442
463
 
443
- const changeFile = useCallback((path, content) => {
444
- setTabs((current) => current.map((tab) => (
445
- tab.path === path ? { ...tab, content, dirty: content !== tab.savedContent } : tab
446
- )))
464
+ /* 把缓冲内容写回 tabs(停顿 / 保存 / 切换标签时调用),不会在每次按键触发渲染。 */
465
+ const flushEditorBuffers = useCallback(() => {
466
+ const buffers = editorBuffersRef.current
467
+ if (buffers.size === 0) return
468
+ setTabs((current) => {
469
+ let changed = false
470
+ const next = current.map((tab) => {
471
+ if (tab === null || !buffers.has(tab.path)) return tab
472
+ const content = buffers.get(tab.path)
473
+ const dirty = content !== tab.savedContent
474
+ if (tab.content === content && tab.dirty === dirty) return tab
475
+ changed = true
476
+ return { ...tab, content, dirty }
477
+ })
478
+ if (!changed) return current
479
+ tabsRef.current = next
480
+ return next
481
+ })
447
482
  }, [])
448
483
 
484
+ flushBuffersRef.current = flushEditorBuffers
485
+
486
+ const scheduleEditorFlush = useCallback(() => {
487
+ if (flushTimerRef.current !== null) window.clearTimeout(flushTimerRef.current)
488
+ flushTimerRef.current = window.setTimeout(() => {
489
+ flushTimerRef.current = null
490
+ flushEditorBuffers()
491
+ }, 300)
492
+ }, [flushEditorBuffers])
493
+
494
+ const changeFile = useCallback((path, content) => {
495
+ editorBuffersRef.current.set(path, content)
496
+ const tab = tabsRef.current.find((item) => item !== null && item.path === path)
497
+ if (tab !== undefined && tab.dirty !== (content !== tab.savedContent)) {
498
+ /* 只在「干净 ↔ 脏」变化时立刻更新标签圆点,避免每个按键重渲染整棵 IDE 树。 */
499
+ setTabs((current) => {
500
+ let changed = false
501
+ const next = current.map((item) => {
502
+ if (item === null || item.path !== path) return item
503
+ const dirty = content !== item.savedContent
504
+ if (item.dirty === dirty) return item
505
+ changed = true
506
+ return { ...item, dirty }
507
+ })
508
+ if (!changed) return current
509
+ tabsRef.current = next
510
+ return next
511
+ })
512
+ }
513
+ scheduleEditorFlush()
514
+ }, [scheduleEditorFlush])
515
+
449
516
  const saveFile = useCallback(async (path) => {
450
517
  if (project === null) return
451
- const tab = tabs.find((item) => item.path === path)
452
- if (tab === undefined || tab.dirty !== true) return
518
+ const tab = tabsRef.current.find((item) => item !== null && item.path === path)
519
+ if (tab === undefined) return
520
+ /* 缓冲里可能有比 tabs 更新的内容(按键后 300ms 内保存/自动保存) */
521
+ const content = editorBuffersRef.current.has(path) ? editorBuffersRef.current.get(path) : tab.content
522
+ if (content === tab.savedContent) {
523
+ editorBuffersRef.current.delete(path)
524
+ if (tab.dirty === true) patchTab(path, { content, dirty: false })
525
+ return
526
+ }
453
527
  try {
454
528
  const result = await G.api('fs.write', {
455
529
  root: project.root,
456
530
  path: tab.path,
457
- content: tab.content,
531
+ content,
458
532
  expectedRevision: tab.revision,
459
533
  })
460
- patchTab(path, { revision: result.revision, savedRevision: result.revision, savedContent: tab.content, dirty: false, size: result.size })
534
+ editorBuffersRef.current.delete(path)
535
+ patchTab(path, { content, revision: result.revision, savedRevision: result.revision, savedContent: content, dirty: false, size: result.size })
461
536
  setBanner('')
462
537
  // 内容保存不改变目录结构:只刷新 Git 状态,不重载文件树(避免整页闪烁)
463
538
  setGitRefreshToken((token) => token + 1)
@@ -466,7 +541,7 @@ G.GufaApp = function GufaApp(props) {
466
541
  if (error.code === 'revision-conflict') setBanner(t('editor.saveConflict'))
467
542
  else setBanner(G.errorText(error))
468
543
  }
469
- }, [project, tabs, patchTab, refreshGit, t])
544
+ }, [project, patchTab, refreshGit, t])
470
545
 
471
546
  /** 顶栏提示:错误常驻红色;成功用绿色 toast,1.2 秒后自动消失。 */
472
547
  const successTimerRef = useRef(null)
@@ -492,6 +567,8 @@ G.GufaApp = function GufaApp(props) {
492
567
  }, [])
493
568
 
494
569
  const closeTab = useCallback((path) => {
570
+ editorBuffersRef.current.delete(path)
571
+ flushBuffersRef.current?.()
495
572
  setTabs((current) => {
496
573
  const next = current.filter((tab) => tab.path !== path)
497
574
  if (activePath === path) {
@@ -1802,10 +1879,7 @@ G.GufaApp = function GufaApp(props) {
1802
1879
  return { path: activeTab.path, content: activeTab.content ?? '', language: activeTab.language }
1803
1880
  }, [activeTab])
1804
1881
 
1805
- const selectionForChat = useMemo(() => {
1806
- if (cursor === null || typeof cursor.selectedText !== 'string' || cursor.selectedText === '') return null
1807
- return { text: cursor.selectedText, path: cursor.path, line: cursor.line, column: cursor.column }
1808
- }, [cursor])
1882
+ const selectionForChat = useMemo(() => selection, [selection])
1809
1883
 
1810
1884
  /* ── IDE 专属快捷键(参考 VS Code;经典模式下不生效) ──────────────── */
1811
1885
  const editorFocusedRef = useRef(false)
@@ -2017,7 +2091,7 @@ G.GufaApp = function GufaApp(props) {
2017
2091
  role: 'tab',
2018
2092
  tabIndex: 0,
2019
2093
  title: tab.title !== undefined && tab.title !== null ? tab.title : tab.path,
2020
- onClick: () => setActivePath(tab.path),
2094
+ onClick: () => handleSelectTab(tab.path),
2021
2095
  onAuxClick: (event) => { if (event.button === 1) closeTabWithConfirm(tab.path) },
2022
2096
  },
2023
2097
  h(G.Icon, { name: 'file', size: 13 }),
@@ -2072,11 +2146,41 @@ G.GufaApp = function GufaApp(props) {
2072
2146
  )
2073
2147
  : null
2074
2148
 
2075
- const cursorText =
2076
- cursor !== null && cursor.path === activePath
2077
- ? `${t('status.ln')} ${cursor.line},${t('status.col')} ${cursor.column}`
2078
- : ''
2149
+ const handleEditorCursor = useCallback((value) => {
2150
+ if (value === null || value === undefined) return
2151
+ /* 状态栏订阅 cursorStore,不再触发 App 根组件渲染 */
2152
+ G.cursorStore.set(value)
2153
+ const selectedText = typeof value.selectedText === 'string' ? value.selectedText : ''
2154
+ if (selectedText === '') {
2155
+ if (selectionTimerRef.current !== null) { window.clearTimeout(selectionTimerRef.current); selectionTimerRef.current = null }
2156
+ pendingSelectionRef.current = null
2157
+ setSelection((current) => (current === null ? current : null))
2158
+ return
2159
+ }
2160
+ pendingSelectionRef.current = { text: selectedText, path: value.path, line: value.line, column: value.column }
2161
+ if (selectionTimerRef.current !== null) return
2162
+ selectionTimerRef.current = window.setTimeout(() => {
2163
+ selectionTimerRef.current = null
2164
+ const latest = pendingSelectionRef.current
2165
+ if (latest === null) return
2166
+ setSelection((current) => {
2167
+ if (current !== null && current.text === latest.text && current.path === latest.path &&
2168
+ current.line === latest.line && current.column === latest.column) return current
2169
+ return latest
2170
+ })
2171
+ }, 180)
2172
+ }, [])
2173
+ const handleEditorSave = useCallback((path) => { void saveFile(path) }, [saveFile])
2174
+ const handleSelectTab = useCallback((path) => {
2175
+ flushBuffersRef.current?.()
2176
+ setActivePath(path)
2177
+ }, [])
2178
+ useEffect(() => () => {
2179
+ if (flushTimerRef.current !== null) { window.clearTimeout(flushTimerRef.current); flushTimerRef.current = null }
2180
+ if (selectionTimerRef.current !== null) { window.clearTimeout(selectionTimerRef.current); selectionTimerRef.current = null }
2181
+ }, [])
2079
2182
 
2183
+ const uiTheme = moyuMode ? 'dark' : theme
2080
2184
  const statusBranch = project?.isGit === true && gitStatus?.branch ? gitStatus.branch : null
2081
2185
  const lineCount = activeTab === null || activeTab.kind === 'graph' ? 0 : String(activeTab.content ?? '').split('\n').length
2082
2186
 
@@ -2267,15 +2371,15 @@ G.GufaApp = function GufaApp(props) {
2267
2371
  : h(G.EditorPane, {
2268
2372
  tabs,
2269
2373
  activePath,
2270
- theme,
2374
+ theme: uiTheme,
2271
2375
  palette: solidPalette,
2272
2376
  root: project?.root ?? '',
2273
- onSelectTab: setActivePath,
2377
+ onSelectTab: handleSelectTab,
2274
2378
  onCloseTab: closeTabWithConfirm,
2275
2379
  onChange: changeFile,
2276
- onSave: (path) => void saveFile(path),
2380
+ onSave: handleEditorSave,
2277
2381
  backdropMode: backdropActive,
2278
- onCursor: (value) => setCursor({ ...value, lineCount }),
2382
+ onCursor: handleEditorCursor,
2279
2383
  }),
2280
2384
  ),
2281
2385
  ),
@@ -2290,7 +2394,7 @@ G.GufaApp = function GufaApp(props) {
2290
2394
  root: project?.root ?? null,
2291
2395
  visible: true,
2292
2396
  height: terminalHeight,
2293
- theme,
2397
+ theme: uiTheme,
2294
2398
  palette: solidPalette,
2295
2399
  onToggleHeight: () => patchUi({ terminalOpen: false }),
2296
2400
  }),
@@ -2310,11 +2414,12 @@ G.GufaApp = function GufaApp(props) {
2310
2414
  project,
2311
2415
  activeFile: activeFileForChat,
2312
2416
  selection: selectionForChat,
2313
- theme,
2417
+ theme: uiTheme,
2314
2418
  width: chatWidth,
2315
2419
  active: true,
2316
2420
  paused: sessionsOpen,
2317
2421
  backdrop: backdropActive,
2422
+ theme: uiTheme,
2318
2423
  sessionTitle,
2319
2424
  onOpenSessions: () => setSessionsOpen(true),
2320
2425
  onInsertCode: insertCode,
@@ -2348,11 +2453,10 @@ G.GufaApp = function GufaApp(props) {
2348
2453
  : h('span', { className: 'gufa-status-item' }, t('status.noGit')),
2349
2454
  h('div', { className: 'gufa-status-fill' }),
2350
2455
  activeTab !== null ? h('span', { className: 'gufa-status-item' }, activeTab.title !== undefined && activeTab.title !== null ? activeTab.title : G.shortPath(activeTab.path, 56)) : null,
2351
- activeTab !== null ? h('span', { className: 'gufa-status-item' }, `${lineCount} ${t('status.lines')}`) : null,
2352
2456
  activeTab !== null && problems[activeTab.path] !== undefined
2353
2457
  ? h('span', { className: 'gufa-status-item', style: { color: problems[activeTab.path].errors > 0 ? '#f85149' : '#e5c07b' } }, `${problems[activeTab.path].errors} ✕ ${problems[activeTab.path].warnings} ⚠`)
2354
2458
  : null,
2355
- cursorText !== '' ? h('span', { className: 'gufa-status-item' }, cursorText) : null,
2459
+ h(G.StatusCursor, { activePath, fallbackLineCount: lineCount }),
2356
2460
  activeTab !== null && activeTab.dirty === true ? h('span', { className: 'gufa-status-item', style: { color: 'var(--gufa-accent)' } }, t('status.dirty')) : null,
2357
2461
  activeTab !== null && activeTab.dirty !== true ? h('span', { className: 'gufa-status-item' }, G.Icon ? h(G.Icon, { name: 'check', size: 11 }) : null, t('status.saved')) : null,
2358
2462
  h('button', {
@@ -503,6 +503,56 @@ const GUFA_PLUGIN = {
503
503
  }
504
504
  }
505
505
 
506
+ // 临时诊断(1.3.57):摸鱼窗口里点不到左树/编辑器时,看看点击落到了哪个元素
507
+ try {
508
+ if (document.documentElement.hasAttribute('data-gufa-float') || /[?&]gufa-float=1/.test(location.search)) {
509
+ setTimeout(() => {
510
+ const probeAt = (x, y) => {
511
+ try {
512
+ const node = document.elementFromPoint(x, y)
513
+ if (node === null) return `${x},${y}:none`
514
+ const cls = typeof node.className === 'string' ? node.className : ''
515
+ return `${x},${y}:${node.tagName}.${String(cls).slice(0, 60)}`
516
+ } catch (error) {
517
+ return `${x},${y}:err`
518
+ }
519
+ }
520
+ // 模态框深色可读性:往 portal 里塞一个临时 .gufa-modal 读计算样式
521
+ let modalInfo = 'none'
522
+ try {
523
+ const host = document.getElementById('gufa-portal-root')
524
+ if (host !== null) {
525
+ const probe = document.createElement('div')
526
+ probe.className = 'gufa-modal'
527
+ probe.style.cssText = 'position:fixed;left:-9999px;top:0;width:120px;height:60px'
528
+ host.appendChild(probe)
529
+ const cs = window.getComputedStyle(probe)
530
+ modalInfo = `bg=${cs.backgroundColor} color=${cs.color}`
531
+ probe.remove()
532
+ }
533
+ } catch {
534
+ modalInfo = 'err'
535
+ }
536
+ // 找树行实际坐标(摸鱼窗半透明,肉眼看不清哪些行是古法的)
537
+ const rows = []
538
+ for (let y = 80; y < 1000; y += 22) {
539
+ try {
540
+ const node = document.elementFromPoint(100, y)
541
+ if (node !== null && typeof node.closest === 'function') {
542
+ const row = node.closest('.gufa-tree-row')
543
+ if (row !== null) rows.push(`${y}:${String(row.textContent ?? '').trim().slice(0, 24)}`)
544
+ }
545
+ } catch {
546
+ /* ignore */
547
+ }
548
+ }
549
+ void G.api('dev.log', { message: `float-hittest ${probeAt(135, 713)} | ${probeAt(300, 713)} | ${probeAt(900, 500)} | ${probeAt(1500, 60)} | modal[${modalInfo}] | rows[${rows.slice(0, 12).join(' ; ')}]` }).catch(() => {})
550
+ }, 5000)
551
+ }
552
+ } catch {
553
+ /* ignore */
554
+ }
555
+
506
556
  // 启动诊断:记录页面地址、真实 Host 基址与传输信息(排查桌面壳 dsh-app:// 连接问题)。
507
557
  try {
508
558
  const transport = typeof globalThis.__DSH_TRANSPORT__ === 'object' && globalThis.__DSH_TRANSPORT__ !== null ? globalThis.__DSH_TRANSPORT__ : null