Skip to content

Commit

Permalink
fix(editor): Improve expression editor performance by removing watche…
Browse files Browse the repository at this point in the history
…rs (#8900)
  • Loading branch information
elsmr authored and netroy committed Mar 15, 2024
1 parent d605854 commit 788d790
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 31 deletions.
14 changes: 4 additions & 10 deletions packages/editor-ui/src/components/HtmlEditor/HtmlEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ export default defineComponent({
editorState: null as EditorState | null,
};
},
watch: {
displayableSegments(segments, newSegments) {
if (isEqual(segments, newSegments)) return;
highlighter.removeColor(this.editor, this.plaintextSegments);
highlighter.addColor(this.editor, this.resolvableSegments);
this.$emit('update:modelValue', this.editor?.state.doc.toString());
},
},
computed: {
doc(): string {
return this.editor.state.doc.toString();
Expand Down Expand Up @@ -139,6 +129,10 @@ export default defineComponent({
// Force segments value update by keeping track of editor state
this.editorState = this.editor.state;
highlighter.removeColor(this.editor, this.plaintextSegments);
highlighter.addColor(this.editor, this.resolvableSegments);
this.$emit('update:modelValue', this.editor?.state.doc.toString());
}),
];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@ export default defineComponent({
},
});
},
displayableSegments(segments, newSegments) {
if (isEqual(segments, newSegments)) return;
highlighter.removeColor(this.editor, this.plaintextSegments);
highlighter.addColor(this.editor, this.resolvableSegments);
this.$emit('change', {
value: this.unresolvedExpression,
segments: this.displayableSegments,
});
},
},
mounted() {
const extensions = [
Expand Down Expand Up @@ -115,6 +104,13 @@ export default defineComponent({
// Force segments value update by keeping track of editor state
this.editorState = this.editor.state;
highlighter.removeColor(this.editor, this.plaintextSegments);
highlighter.addColor(this.editor, this.resolvableSegments);
this.$emit('change', {
value: this.unresolvedExpression,
segments: this.displayableSegments,
});
setTimeout(() => {
try {
Expand Down
14 changes: 4 additions & 10 deletions packages/editor-ui/src/components/SqlEditor/SqlEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,16 @@ export default defineComponent({
// Force segments value update by keeping track of editor state
this.editorState = this.editor.state;
highlighter.removeColor(this.editor, this.plaintextSegments);
highlighter.addColor(this.editor, this.resolvableSegments);
this.$emit('update:modelValue', this.editor?.state.doc.toString());
}),
);
}
return extensions;
},
},
watch: {
displayableSegments(segments, newSegments) {
if (isEqual(segments, newSegments)) return;
highlighter.removeColor(this.editor, this.plaintextSegments);
highlighter.addColor(this.editor, this.resolvableSegments);
this.$emit('update:modelValue', this.editor?.state.doc.toString());
},
},
mounted() {
if (!this.isReadOnly) codeNodeEditorEventBus.on('error-line-number', this.highlightLine);
Expand Down

0 comments on commit 788d790

Please sign in to comment.