Skip to content

Commit 334eb73

Browse files
committed
Fix scrolling not working horizontally
1 parent 7747cb3 commit 334eb73

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/components/CodeEditor.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {ref, onMounted} from 'vue';
44
import {lintKeymap} from '@codemirror/lint';
55
import {EditorState} from '@codemirror/state';
66
import {javascript} from '@codemirror/lang-javascript';
7-
import {StateEffect, StateField} from '@codemirror/state';
7+
import {StateEffect, StateField, SelectionRange} from '@codemirror/state';
88
import {defaultKeymap, history, historyKeymap} from '@codemirror/commands';
99
import {highlightSelectionMatches, searchKeymap} from '@codemirror/search';
1010
import {autocompletion, closeBrackets, closeBracketsKeymap, completionKeymap} from '@codemirror/autocomplete';
@@ -79,12 +79,13 @@ function highlightRange(start, end) {
7979
this.dispatch({
8080
effects: highlightEffect.of([highlight_decoration.range(start, end)]),
8181
});
82-
const lineNumber = this.state.doc.lineAt(start).number;
83-
const linePos = this.state.doc.line(lineNumber).from;
84-
store.getEditor(store.editorIds.inputCodeEditor).dispatch({
85-
effects: EditorView.scrollIntoView(linePos, {
82+
const range = new SelectionRange(start, end);
83+
const ed = store.getEditor(store.editorIds.inputCodeEditor);
84+
ed.dispatch({
85+
effects: EditorView.scrollIntoView(range, {
8686
y: 'center',
87-
})
87+
x: 'center',
88+
}),
8889
});
8990
}
9091
}

0 commit comments

Comments
 (0)