@ptengine/inline-editor 0.1.10 → 0.1.11
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/CHANGELOG.md +11 -0
- package/dist/panels/CodeMirrorField.js +20 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.11
|
|
4
|
+
|
|
5
|
+
依赖不变,可以直接发。
|
|
6
|
+
|
|
7
|
+
**修复**
|
|
8
|
+
|
|
9
|
+
- 代码框输入被吞、补全不出:宿主回传值是异步的,回传落后于编辑器时(用户已经又敲了字)旧值会整篇覆盖编辑器 ——
|
|
10
|
+
刚敲的字丢失、光标重置、补全弹层被关掉,每次覆盖还要整篇重新解析(真机:敲 `ptKit.` 只剩 `p`)。
|
|
11
|
+
现在记住自己交出去过的值,落后的回传不再覆盖;格式化 / AI 追加 / 宿主回填等真正的外部写入照常生效。
|
|
12
|
+
- 全选看不到选区:当前行高亮改成半透明(不透明时会盖住光标所在行的选区,单行代码全选什么都看不见),选区颜色加深。
|
|
13
|
+
|
|
3
14
|
## 0.1.10
|
|
4
15
|
|
|
5
16
|
新增依赖:`@codemirror/*`(state / view / commands / language / autocomplete / lint / lang-css / lang-javascript)与 `js-beautify`。
|
|
@@ -77,8 +77,11 @@ const theme = EditorView.theme({
|
|
|
77
77
|
borderRight: '1px solid #EBECF0',
|
|
78
78
|
color: '#97A0AF'
|
|
79
79
|
},
|
|
80
|
-
'.cm-activeLine': { backgroundColor: '
|
|
81
|
-
'.cm-activeLineGutter': { backgroundColor: '
|
|
80
|
+
'.cm-activeLine': { backgroundColor: 'rgba(9, 30, 66, 0.04)' },
|
|
81
|
+
'.cm-activeLineGutter': { backgroundColor: 'rgba(9, 30, 66, 0.06)' },
|
|
82
|
+
'.cm-selectionBackground': { backgroundColor: '#c7dbf7 !important' },
|
|
83
|
+
'&.cm-focused .cm-selectionBackground': { backgroundColor: '#a9c8f5 !important' },
|
|
84
|
+
'.cm-content ::selection': { backgroundColor: '#a9c8f5' },
|
|
82
85
|
'.cm-tooltip': { fontSize: '12px' }
|
|
83
86
|
});
|
|
84
87
|
function languageExtensions(language, errorMessage) {
|
|
@@ -94,6 +97,7 @@ export default function CodeMirrorField({ language, value, onChange, onBlur, pla
|
|
|
94
97
|
const hostRef = useRef(null);
|
|
95
98
|
const viewRef = useRef(null);
|
|
96
99
|
const onChangeRef = useRef(onChange);
|
|
100
|
+
const emittedRef = useRef(new Set());
|
|
97
101
|
onChangeRef.current = onChange;
|
|
98
102
|
const onBlurRef = useRef(onBlur);
|
|
99
103
|
onBlurRef.current = onBlur;
|
|
@@ -132,8 +136,14 @@ export default function CodeMirrorField({ language, value, onChange, onBlur, pla
|
|
|
132
136
|
spellcheck: 'false'
|
|
133
137
|
}),
|
|
134
138
|
EditorView.updateListener.of(update => {
|
|
135
|
-
if (update.docChanged)
|
|
136
|
-
|
|
139
|
+
if (update.docChanged) {
|
|
140
|
+
const next = update.state.doc.toString();
|
|
141
|
+
const emitted = emittedRef.current;
|
|
142
|
+
emitted.add(next);
|
|
143
|
+
if (emitted.size > 64)
|
|
144
|
+
emitted.delete(emitted.values().next().value);
|
|
145
|
+
onChangeRef.current(next);
|
|
146
|
+
}
|
|
137
147
|
if (update.focusChanged && !update.view.hasFocus)
|
|
138
148
|
onBlurRef.current?.();
|
|
139
149
|
}),
|
|
@@ -152,8 +162,13 @@ export default function CodeMirrorField({ language, value, onChange, onBlur, pla
|
|
|
152
162
|
if (!view)
|
|
153
163
|
return;
|
|
154
164
|
const current = view.state.doc.toString();
|
|
155
|
-
if (current === value)
|
|
165
|
+
if (current === value) {
|
|
166
|
+
emittedRef.current.clear();
|
|
156
167
|
return;
|
|
168
|
+
}
|
|
169
|
+
if (emittedRef.current.has(value))
|
|
170
|
+
return;
|
|
171
|
+
emittedRef.current.clear();
|
|
157
172
|
view.dispatch({ changes: { from: 0, to: current.length, insert: value } });
|
|
158
173
|
}, [value]);
|
|
159
174
|
return _jsx("div", { ref: hostRef, "data-testid": testId, className: "h-full min-h-0 overflow-hidden" });
|