dsh-gufa-code 1.3.57 → 1.3.59

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.57'
19
+ G.BUILD = '1.3.59'
20
20
  G.PANEL_ID = 'gufa-code'
21
21
  /** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
22
22
  G.pendingEntryWorkspace = null
@@ -3160,14 +3160,24 @@ G.FooterAction = function FooterAction(props) {
3160
3160
  lastPropContentRef.current.set(tab.path, content)
3161
3161
  continue
3162
3162
  }
3163
- if (lastPropContentRef.current.get(tab.path) !== content) {
3163
+ const knownContent = lastPropContentRef.current.get(tab.path)
3164
+ if (knownContent !== content) {
3164
3165
  lastPropContentRef.current.set(tab.path, content)
3165
3166
  if (model.getValue() !== content) {
3166
- suppressChangeRef.current = true
3167
- try {
3168
- model.setValue(content)
3169
- } finally {
3170
- suppressChangeRef.current = false
3167
+ /* 用户在编辑器里持续输入时,App 的 tabs 状态可能落后(内容缓冲/React 批处理)。
3168
+ 如果当前 model 正好还是上次上报的内容,说明这是「状态落后」而不是外部修改,
3169
+ 绝不能 setValue 回灌旧内容——否则光标会跳回开头、刚输入的字符也会被覆盖。
3170
+ 外部修改(如切回文件、外部刷新)通常发生在编辑器没有焦点时,仍然照常同步。 */
3171
+ const modelValue = model.getValue()
3172
+ const modelMatchesKnown = knownContent === undefined || knownContent === null || knownContent === modelValue
3173
+ const focused = typeof editor.hasTextFocus === 'function' ? editor.hasTextFocus() : false
3174
+ if (!(focused && modelMatchesKnown)) {
3175
+ suppressChangeRef.current = true
3176
+ try {
3177
+ model.setValue(content)
3178
+ } finally {
3179
+ suppressChangeRef.current = false
3180
+ }
3171
3181
  }
3172
3182
  }
3173
3183
  }
@@ -6743,6 +6753,37 @@ G.Explorer = function Explorer(props) {
6743
6753
  void loadDir('')
6744
6754
  }, [root, loadDir])
6745
6755
 
6756
+ /* 刷新已加载过的所有目录(根 + 展开过的子目录),而不是只刷根目录:
6757
+ 用户在系统 Finder 里新建/改名/删除文件后,点刷新也能看到子目录里的变化。 */
6758
+ const refreshAll = useCallback(() => {
6759
+ const paths = Object.keys(dirsRef.current)
6760
+ if (paths.length === 0) return
6761
+ for (const path of paths) void loadDir(path)
6762
+ }, [loadDir])
6763
+
6764
+ /* 从别的 App(Finder/终端)切回古法编程时,自动刷新已加载目录,不需要手动点刷新。 */
6765
+ useEffect(() => {
6766
+ if (!root) return undefined
6767
+ let timer = null
6768
+ const scheduleRefresh = () => {
6769
+ if (timer !== null) window.clearTimeout(timer)
6770
+ timer = window.setTimeout(() => {
6771
+ timer = null
6772
+ refreshAll()
6773
+ }, 180)
6774
+ }
6775
+ const onVisibilityChange = () => {
6776
+ if (document.visibilityState === 'visible') scheduleRefresh()
6777
+ }
6778
+ window.addEventListener('focus', scheduleRefresh)
6779
+ document.addEventListener('visibilitychange', onVisibilityChange)
6780
+ return () => {
6781
+ if (timer !== null) window.clearTimeout(timer)
6782
+ window.removeEventListener('focus', scheduleRefresh)
6783
+ document.removeEventListener('visibilitychange', onVisibilityChange)
6784
+ }
6785
+ }, [root, refreshAll])
6786
+
6746
6787
  // 刷新令牌:重新读取已展开过的目录,保留展开状态
6747
6788
  const dirsRef = useRef(dirs)
6748
6789
  dirsRef.current = dirs
@@ -7066,7 +7107,7 @@ G.Explorer = function Explorer(props) {
7066
7107
  multi.length > 1 ? h('span', { className: 'gufa-badge' }, String(multi.length)) : null,
7067
7108
  h(G.IconButton, { title: t('explorer.newFile'), onClick: () => props.onNewFile?.(selectedDir()) }, h(G.Icon, { name: 'plus', size: 14 })),
7068
7109
  h(G.IconButton, { title: t('explorer.newFolder'), onClick: () => props.onNewFolder?.(selectedDir()) }, h(G.Icon, { name: 'folder', size: 14 })),
7069
- h(G.IconButton, { title: t('explorer.refresh'), onClick: () => void loadDir('') }, h(G.Icon, { name: 'refresh', size: 13 })),
7110
+ h(G.IconButton, { title: t('explorer.refresh'), onClick: () => refreshAll() }, h(G.Icon, { name: 'refresh', size: 13 })),
7070
7111
  ),
7071
7112
  notice !== ''
7072
7113
  ? h('div', { className: 'gufa-explorer-notice', title: notice }, notice)
@@ -10160,10 +10201,12 @@ G.GufaApp = function GufaApp(props) {
10160
10201
  let changed = false
10161
10202
  const next = current.map((item) => {
10162
10203
  if (item === null || item.path !== path) return item
10163
- const dirty = content !== item.savedContent
10204
+ /* 用缓冲里的最新内容而不是本次按键的内容:避免 React 批处理时把「第一次按键」的旧内容回灌给编辑器。 */
10205
+ const latest = editorBuffersRef.current.has(path) ? editorBuffersRef.current.get(path) : content
10206
+ const dirty = latest !== item.savedContent
10164
10207
  if (item.dirty === dirty) return item
10165
10208
  changed = true
10166
- return { ...item, dirty }
10209
+ return { ...item, content: latest, dirty }
10167
10210
  })
10168
10211
  if (!changed) return current
10169
10212
  tabsRef.current = next
@@ -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.57</string>
11
- <key>CFBundleVersion</key><string>1.3.57</string>
10
+ <key>CFBundleShortVersionString</key><string>1.3.59</string>
11
+ <key>CFBundleVersion</key><string>1.3.59</string>
12
12
  <key>LSUIElement</key><true/>
13
13
  <key>NSHighResolutionCapable</key><true/>
14
14
  <key>NSPrincipalClass</key><string>NSApplication</string>
@@ -117,6 +117,18 @@
117
117
  - 排查要点:`float-hittest` 日志会打印 elementFromPoint 与临时 `.gufa-modal` 的计算样式(bg/color),
118
118
  `float-styles` 打印覆盖层透明度;终端输入问题优先看窗口是否 key,而不是 transport。
119
119
 
120
+ ## 资源管理器外部文件变化(1.3.59 修复)
121
+
122
+ 问题:在 Finder/终端里新建/删除文件后切回古法编程,资源管理器不显示;点右上角刷新也只刷新根目录,
123
+ 展开的子目录里新建的文件仍然看不到。
124
+
125
+ 原因:刷新按钮只调用 `loadDir('')`(根目录),没有刷新已经展开/加载过的子目录;
126
+ 切换回窗口时也不会自动刷新。
127
+
128
+ 修复:
129
+ - 刷新按钮改为 `refreshAll()`:重读「根目录 + 所有已加载目录」;
130
+ - 窗口 `focus` / `visibilitychange`(可见)时防抖 180ms 自动 `refreshAll()`,从 Finder 切回来无需手动刷新。
131
+
120
132
  ## 5.1 摸鱼会话框比编辑器黑:官方会话根节点自己又画了一层底
121
133
 
122
134
  - 现象:摸鱼里编辑器/终端都统一了,右侧会话框看起来明显更黑更实。
@@ -30,6 +30,20 @@ Monaco 本身很快;古法编程编辑器之前卡顿的主要原因是 **Reac
30
30
  - `Cmd+Z` 撤销后自动保存把文件恢复为原始内容(与 baseline 全等);
31
31
  - 三套测试 99 / 44 / 19 全过。
32
32
 
33
+ ## 坑:内容缓冲不能把旧内容回灌给 Monaco(1.3.58 修复)
34
+
35
+ 缓冲方案第一版在「干净→脏」的状态更新里只改了 `dirty`、没带最新 `content`,
36
+ 导致 App 用旧的 `tabs.content` 重渲染 → EditorPane 的 model 同步逻辑误判为外部修改并
37
+ `model.setValue(旧内容)` → 用户刚输入的内容被覆盖、光标跳回开头。
38
+
39
+ 修复:
40
+ 1. 脏标记更新时把**缓冲里最新内容**一起写进 tabs;
41
+ 2. EditorPane 同步 model 时增加保护:如果编辑器有焦点、且 model 内容仍等于上次上报内容,
42
+ 就认定是 App 状态暂时落后,**不 setValue**;只有非焦点场景/真正外部更新才同步。
43
+
44
+ 回归验证:主窗口 113 行文件输入 `abcdef` → 内容保留、光标不跳;自动保存写入 +6 字节;
45
+ `Cmd+Z` 后恢复原始内容(1498 字节逐字节相等)。
46
+
33
47
  ## 后续可继续优化(未做)
34
48
 
35
49
  - 超大文件(数万行)时 Monaco `model.getValue()` 每次变更复制整个字符串,可改为增量取内容/仅在 flush 时取;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.57",
3
+ "version": "1.3.59",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -919,14 +919,24 @@
919
919
  lastPropContentRef.current.set(tab.path, content)
920
920
  continue
921
921
  }
922
- if (lastPropContentRef.current.get(tab.path) !== content) {
922
+ const knownContent = lastPropContentRef.current.get(tab.path)
923
+ if (knownContent !== content) {
923
924
  lastPropContentRef.current.set(tab.path, content)
924
925
  if (model.getValue() !== content) {
925
- suppressChangeRef.current = true
926
- try {
927
- model.setValue(content)
928
- } finally {
929
- suppressChangeRef.current = false
926
+ /* 用户在编辑器里持续输入时,App 的 tabs 状态可能落后(内容缓冲/React 批处理)。
927
+ 如果当前 model 正好还是上次上报的内容,说明这是「状态落后」而不是外部修改,
928
+ 绝不能 setValue 回灌旧内容——否则光标会跳回开头、刚输入的字符也会被覆盖。
929
+ 外部修改(如切回文件、外部刷新)通常发生在编辑器没有焦点时,仍然照常同步。 */
930
+ const modelValue = model.getValue()
931
+ const modelMatchesKnown = knownContent === undefined || knownContent === null || knownContent === modelValue
932
+ const focused = typeof editor.hasTextFocus === 'function' ? editor.hasTextFocus() : false
933
+ if (!(focused && modelMatchesKnown)) {
934
+ suppressChangeRef.current = true
935
+ try {
936
+ model.setValue(content)
937
+ } finally {
938
+ suppressChangeRef.current = false
939
+ }
930
940
  }
931
941
  }
932
942
  }
@@ -62,6 +62,37 @@ G.Explorer = function Explorer(props) {
62
62
  void loadDir('')
63
63
  }, [root, loadDir])
64
64
 
65
+ /* 刷新已加载过的所有目录(根 + 展开过的子目录),而不是只刷根目录:
66
+ 用户在系统 Finder 里新建/改名/删除文件后,点刷新也能看到子目录里的变化。 */
67
+ const refreshAll = useCallback(() => {
68
+ const paths = Object.keys(dirsRef.current)
69
+ if (paths.length === 0) return
70
+ for (const path of paths) void loadDir(path)
71
+ }, [loadDir])
72
+
73
+ /* 从别的 App(Finder/终端)切回古法编程时,自动刷新已加载目录,不需要手动点刷新。 */
74
+ useEffect(() => {
75
+ if (!root) return undefined
76
+ let timer = null
77
+ const scheduleRefresh = () => {
78
+ if (timer !== null) window.clearTimeout(timer)
79
+ timer = window.setTimeout(() => {
80
+ timer = null
81
+ refreshAll()
82
+ }, 180)
83
+ }
84
+ const onVisibilityChange = () => {
85
+ if (document.visibilityState === 'visible') scheduleRefresh()
86
+ }
87
+ window.addEventListener('focus', scheduleRefresh)
88
+ document.addEventListener('visibilitychange', onVisibilityChange)
89
+ return () => {
90
+ if (timer !== null) window.clearTimeout(timer)
91
+ window.removeEventListener('focus', scheduleRefresh)
92
+ document.removeEventListener('visibilitychange', onVisibilityChange)
93
+ }
94
+ }, [root, refreshAll])
95
+
65
96
  // 刷新令牌:重新读取已展开过的目录,保留展开状态
66
97
  const dirsRef = useRef(dirs)
67
98
  dirsRef.current = dirs
@@ -385,7 +416,7 @@ G.Explorer = function Explorer(props) {
385
416
  multi.length > 1 ? h('span', { className: 'gufa-badge' }, String(multi.length)) : null,
386
417
  h(G.IconButton, { title: t('explorer.newFile'), onClick: () => props.onNewFile?.(selectedDir()) }, h(G.Icon, { name: 'plus', size: 14 })),
387
418
  h(G.IconButton, { title: t('explorer.newFolder'), onClick: () => props.onNewFolder?.(selectedDir()) }, h(G.Icon, { name: 'folder', size: 14 })),
388
- h(G.IconButton, { title: t('explorer.refresh'), onClick: () => void loadDir('') }, h(G.Icon, { name: 'refresh', size: 13 })),
419
+ h(G.IconButton, { title: t('explorer.refresh'), onClick: () => refreshAll() }, h(G.Icon, { name: 'refresh', size: 13 })),
389
420
  ),
390
421
  notice !== ''
391
422
  ? h('div', { className: 'gufa-explorer-notice', title: notice }, notice)
@@ -500,10 +500,12 @@ G.GufaApp = function GufaApp(props) {
500
500
  let changed = false
501
501
  const next = current.map((item) => {
502
502
  if (item === null || item.path !== path) return item
503
- const dirty = content !== item.savedContent
503
+ /* 用缓冲里的最新内容而不是本次按键的内容:避免 React 批处理时把「第一次按键」的旧内容回灌给编辑器。 */
504
+ const latest = editorBuffersRef.current.has(path) ? editorBuffersRef.current.get(path) : content
505
+ const dirty = latest !== item.savedContent
504
506
  if (item.dirty === dirty) return item
505
507
  changed = true
506
- return { ...item, dirty }
508
+ return { ...item, content: latest, dirty }
507
509
  })
508
510
  if (!changed) return current
509
511
  tabsRef.current = next