Skip to content

Commit

Permalink
Fix scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrl-escp committed Jun 7, 2024
1 parent ff8bd7e commit b5ec836
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
13 changes: 5 additions & 8 deletions src/components/CodeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ const highlightRangeExt = StateField.define({
});
const highlight_decoration = Decoration.mark({
// attributes: {style: "background-color: red"}
class: 'highlighted-code',
});
Expand All @@ -81,17 +80,15 @@ function highlightRange(start, end) {
effects: highlightEffect.of([highlight_decoration.range(start, end)]),
});
const lineNumber = this.state.doc.lineAt(start).number;
const line = document.querySelectorAll('.cm-line')[lineNumber];
if (line) line.scrollIntoView({
behavior: 'smooth',
block: 'center',
inline: 'center',
const linePos = this.state.doc.line(lineNumber).from;
store.getEditor(store.editorIds.inputCodeEditor).dispatch({
effects: EditorView.scrollIntoView(linePos, {
y: 'center',
})
});
}
}
// function scrollToLine(lineNo) {}
onMounted(() => {
// noinspection JSCheckFunctionSignatures
const ed = new EditorView({
Expand Down
17 changes: 10 additions & 7 deletions src/components/NodesList.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<script setup>
import {store} from '../store.js';
import {computed, onMounted} from 'vue';
import {computed, onMounted, reactive} from 'vue';
const state = reactive({
highlightedNodeId: -1,
});
let highlightedNodeId = null;
function highlightCode(node) {
const editor = store.getEditor(store.editorIds.inputCodeEditor);
if (highlightedNodeId !== null) {
const previouslyHighlighted = document.querySelector(`div[data-nodeId="${highlightedNodeId}"]`);
if (state.highlightedNodeId > -1) {
const previouslyHighlighted = document.querySelector(`.highlight-node`);
if (previouslyHighlighted) previouslyHighlighted.classList.remove('highlight-node');
}
if (node.nodeId === highlightedNodeId) {
highlightedNodeId = null;
if (node.nodeId === state.highlightedNodeId) {
state.highlightedNodeId = -1;
editor.highlightRange();
} else {
highlightedNodeId = node.nodeId;
state.highlightedNodeId = node.nodeId;
editor.highlightRange(node.range[0], node.range[1]);
document.querySelector(`div[data-nodeid="${node.nodeId}"]`).classList.add('highlight-node');
}
Expand Down

0 comments on commit b5ec836

Please sign in to comment.