mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 12:44:07 -08:00
fix(editor): Skip error line highlighting if out of range (#6721)
This commit is contained in:
parent
4029386349
commit
a62d00a479
|
@ -24,7 +24,7 @@ import type { PropType } from 'vue';
|
||||||
import { mapStores } from 'pinia';
|
import { mapStores } from 'pinia';
|
||||||
|
|
||||||
import type { LanguageSupport } from '@codemirror/language';
|
import type { LanguageSupport } from '@codemirror/language';
|
||||||
import type { Extension } from '@codemirror/state';
|
import type { Extension, Line } from '@codemirror/state';
|
||||||
import { Compartment, EditorState } from '@codemirror/state';
|
import { Compartment, EditorState } from '@codemirror/state';
|
||||||
import type { ViewUpdate } from '@codemirror/view';
|
import type { ViewUpdate } from '@codemirror/view';
|
||||||
import { EditorView } from '@codemirror/view';
|
import { EditorView } from '@codemirror/view';
|
||||||
|
@ -154,18 +154,29 @@ export default defineComponent({
|
||||||
changes: { from: 0, to: this.content.length, insert: this.placeholder },
|
changes: { from: 0, to: this.content.length, insert: this.placeholder },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
highlightLine(line: number | 'final') {
|
line(lineNumber: number): Line | null {
|
||||||
|
try {
|
||||||
|
return this.editor?.state.doc.line(lineNumber) ?? null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
highlightLine(lineNumber: number | 'final') {
|
||||||
if (!this.editor) return;
|
if (!this.editor) return;
|
||||||
|
|
||||||
if (line === 'final') {
|
if (lineNumber === 'final') {
|
||||||
this.editor.dispatch({
|
this.editor.dispatch({
|
||||||
selection: { anchor: this.content.length },
|
selection: { anchor: this.content.length },
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const line = this.line(lineNumber);
|
||||||
|
|
||||||
|
if (!line) return;
|
||||||
|
|
||||||
this.editor.dispatch({
|
this.editor.dispatch({
|
||||||
selection: { anchor: this.editor.state.doc.line(line).from },
|
selection: { anchor: line.from },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
trackCompletion(viewUpdate: ViewUpdate) {
|
trackCompletion(viewUpdate: ViewUpdate) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { acceptCompletion, autocompletion, ifNotIn } from '@codemirror/autocompl
|
||||||
import { indentWithTab, history, redo, toggleComment } from '@codemirror/commands';
|
import { indentWithTab, history, redo, toggleComment } from '@codemirror/commands';
|
||||||
import { bracketMatching, foldGutter, indentOnInput, LanguageSupport } from '@codemirror/language';
|
import { bracketMatching, foldGutter, indentOnInput, LanguageSupport } from '@codemirror/language';
|
||||||
import { EditorState } from '@codemirror/state';
|
import { EditorState } from '@codemirror/state';
|
||||||
|
import type { Line } from '@codemirror/state';
|
||||||
import type { Extension } from '@codemirror/state';
|
import type { Extension } from '@codemirror/state';
|
||||||
import {
|
import {
|
||||||
dropCursor,
|
dropCursor,
|
||||||
|
@ -189,18 +190,29 @@ export default defineComponent({
|
||||||
onBlur() {
|
onBlur() {
|
||||||
this.isFocused = false;
|
this.isFocused = false;
|
||||||
},
|
},
|
||||||
highlightLine(line: number | 'final') {
|
line(lineNumber: number): Line | null {
|
||||||
|
try {
|
||||||
|
return this.editor?.state.doc.line(lineNumber) ?? null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
highlightLine(lineNumber: number | 'final') {
|
||||||
if (!this.editor) return;
|
if (!this.editor) return;
|
||||||
|
|
||||||
if (line === 'final') {
|
if (lineNumber === 'final') {
|
||||||
this.editor.dispatch({
|
this.editor.dispatch({
|
||||||
selection: { anchor: this.query.length },
|
selection: { anchor: this.query.length },
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const line = this.line(lineNumber);
|
||||||
|
|
||||||
|
if (!line) return;
|
||||||
|
|
||||||
this.editor.dispatch({
|
this.editor.dispatch({
|
||||||
selection: { anchor: this.editor.state.doc.line(line).from },
|
selection: { anchor: line.from },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue