Skip to content

Commit 8f4cf8f

Browse files
fix: Cursor jump while editing header
1 parent f4f27e0 commit 8f4cf8f

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

frontend/src/components/TextBlock.vue

+22-13
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,34 @@ watch(
239239
240240
watch(
241241
() => textContent.value,
242-
(newValue, oldValue) => {
243-
const isSame = newValue === editor.value?.getHTML();
242+
(newValue) => {
243+
const innerHTML = getInnerHTML(editor.value);
244+
const isSame = newValue === innerHTML;
244245
if (isSame) {
245246
return;
246247
}
247248
editor.value?.commands.setContent(newValue || "", false);
248249
},
249250
);
250251
252+
const getInnerHTML = (editor: Editor | null) => {
253+
if (!editor) {
254+
return "";
255+
}
256+
let innerHTML = editor.isEmpty ? "" : editor.getHTML();
257+
if (
258+
props.block.isHeader() &&
259+
!(
260+
editor.isActive("heading", { level: 1 }) ||
261+
editor.isActive("heading", { level: 2 }) ||
262+
editor.isActive("heading", { level: 3 })
263+
)
264+
) {
265+
innerHTML = editor?.getText();
266+
}
267+
return innerHTML;
268+
};
269+
251270
if (!props.preview) {
252271
watch(
253272
() => store.activeCanvas?.isSelected(props.block),
@@ -268,17 +287,7 @@ if (!props.preview) {
268287
],
269288
enablePasteRules: false,
270289
onUpdate({ editor }) {
271-
let innerHTML = editor.isEmpty ? "" : editor.getHTML();
272-
if (
273-
props.block.isHeader() &&
274-
!(
275-
editor.isActive("heading", { level: 1 }) ||
276-
editor.isActive("heading", { level: 2 }) ||
277-
editor.isActive("heading", { level: 3 })
278-
)
279-
) {
280-
innerHTML = editor.getText();
281-
}
290+
let innerHTML = getInnerHTML(editor as Editor);
282291
if (props.block.getInnerHTML() === innerHTML) {
283292
return;
284293
}

0 commit comments

Comments
 (0)