Skip to content

Commit

Permalink
Fixed scrolling on enter
Browse files Browse the repository at this point in the history
Make editor always consume 100% height
Cleaned-up some comments
  • Loading branch information
grolu committed Sep 16, 2024
1 parent fed8458 commit 5c8c6ca
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 4 additions & 0 deletions frontend/src/components/GShootEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,8 @@ onBeforeUnmount(() => {
}
}
.cm-editor {
height: 100%;
}
</style>
6 changes: 3 additions & 3 deletions frontend/src/composables/useEditorLineHighlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 2 additions & 6 deletions frontend/src/composables/useEditorWhitespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
Expand All @@ -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),
Expand Down
1 change: 1 addition & 0 deletions frontend/src/composables/useShootEditor/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
}
}

0 comments on commit 5c8c6ca

Please sign in to comment.