From 5c8c6cade247a3494a78fe3ee1c14b20ff142170 Mon Sep 17 00:00:00 2001 From: "Gross, Lukas" Date: Mon, 16 Sep 2024 18:25:23 +0200 Subject: [PATCH] Fixed scrolling on enter Make editor always consume 100% height Cleaned-up some comments --- frontend/src/components/GShootEditor.vue | 4 ++++ frontend/src/composables/useEditorLineHighlighter.js | 6 +++--- frontend/src/composables/useEditorWhitespace.js | 8 ++------ frontend/src/composables/useShootEditor/helper.js | 1 + 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/GShootEditor.vue b/frontend/src/components/GShootEditor.vue index e9d3be4d20..b574d0700b 100644 --- a/frontend/src/components/GShootEditor.vue +++ b/frontend/src/components/GShootEditor.vue @@ -291,4 +291,8 @@ onBeforeUnmount(() => { } } + .cm-editor { + height: 100%; + } + diff --git a/frontend/src/composables/useEditorLineHighlighter.js b/frontend/src/composables/useEditorLineHighlighter.js index a8e6c6b054..ce7f154fcc 100644 --- a/frontend/src/composables/useEditorLineHighlighter.js +++ b/frontend/src/composables/useEditorLineHighlighter.js @@ -48,12 +48,12 @@ export function useEditorLineHighlighter (cmView) { return valuesFromParams() }, set (values = []) { - const valuesOld = valuesFromParams() + const valuesCurrent = valuesFromParams() let [startLine, endLine = startLine] = values - const [startLineOld, endLineOld] = valuesOld + const [startLineCurrent, endLineCurrent] = valuesCurrent - if (endLine === startLine && startLine === startLineOld && !endLineOld) { + if (endLine === startLine && startLine === startLineCurrent && !endLineCurrent) { startLine = null } diff --git a/frontend/src/composables/useEditorWhitespace.js b/frontend/src/composables/useEditorWhitespace.js index f25a80c064..409687ed11 100644 --- a/frontend/src/composables/useEditorWhitespace.js +++ b/frontend/src/composables/useEditorWhitespace.js @@ -12,9 +12,8 @@ import { } from '@codemirror/view' export function useEditorWhitespace () { - // Match leading spaces or tabs (modify the regexp as necessary for tabs or spaces) const matchDecorator = new MatchDecorator({ - regexp: /[ \t]/g, // Match each individual space or tab character + regexp: /[ \t]/g, decoration: match => { if (match[0] === '\t') { return Decoration.mark({ @@ -37,17 +36,15 @@ export function useEditorWhitespace () { } } - // Create decorations for newlines at the end of each line function addNewlineMarkers (view) { const widgets = [] for (const { from, to } of view.visibleRanges) { for (let pos = from; pos <= to;) { const line = view.state.doc.lineAt(pos) - // Only add a marker if not the last line (as there is no newline after the last line) if (line.to < view.state.doc.length) { widgets.push(Decoration.widget({ widget: new NewlineWidget(), - side: 1, // Ensure the widget is placed after the line text + side: 1, }).range(line.to)) } pos = line.to + 1 @@ -56,7 +53,6 @@ export function useEditorWhitespace () { return Decoration.set(widgets, true) } - // Define the view plugin for showing the whitespace const showAllWhitespace = ViewPlugin.define( view => ({ decorations: matchDecorator.createDeco(view), diff --git a/frontend/src/composables/useShootEditor/helper.js b/frontend/src/composables/useShootEditor/helper.js index 44f1b20088..cb85451dad 100644 --- a/frontend/src/composables/useShootEditor/helper.js +++ b/frontend/src/composables/useShootEditor/helper.js @@ -372,6 +372,7 @@ export class EditorCompletions { cmView.dispatch({ changes: { from: selection.from, to: selection.to, insert: replacementText }, selection: { anchor: newCursorPosition }, + effects: EditorView.scrollIntoView(newCursorPosition), }) } }