Fix bug causing note delimiter to be copied if "moveLineUp" command was executed with the first line selected

This commit is contained in:
Jonatan Heyman 2022-12-30 16:11:22 +01:00
parent 0f072b8699
commit c8e4861ffe
2 changed files with 22 additions and 3 deletions

View File

@ -1,5 +1,8 @@
import { EditorView } from "@codemirror/view" import { EditorView } from "@codemirror/view"
import { selectAll as defaultSelectAll } from "@codemirror/commands" import {
selectAll as defaultSelectAll,
moveLineUp as defaultMoveLineUp,
} from "@codemirror/commands"
import { blockState } from "./note-block" import { blockState } from "./note-block"
@ -18,7 +21,6 @@ export const insertNewNote = ({ state, dispatch }) => {
return true; return true;
} }
export const selectAll = ({ state, dispatch }) => { export const selectAll = ({ state, dispatch }) => {
// find which block the cursor is in // find which block the cursor is in
const range = state.selection.asSingle().ranges[0] const range = state.selection.asSingle().ranges[0]
@ -37,3 +39,15 @@ export const selectAll = ({ state, dispatch }) => {
return true return true
} }
/**
* Prevent moveLineUp from executing if any cursor is on the first line of the first note
*/
export function moveLineUp({ state, dispatch }) {
if (state.selection.ranges.some(range => {
let startLine = state.doc.lineAt(range.from)
return startLine.from <= state.facet(blockState)[0].content.from
})) {
return true;
}
return defaultMoveLineUp({state, dispatch})
}

View File

@ -7,7 +7,7 @@ import { nord } from "./theme/nord.mjs"
import { customSetup } from "./setup.js" import { customSetup } from "./setup.js"
import { heynoteLang } from "./lang-heynote/heynote.js" import { heynoteLang } from "./lang-heynote/heynote.js"
import { noteBlockExtension } from "./block/note-block.js" import { noteBlockExtension } from "./block/note-block.js"
import { insertNewNote, selectAll } from "./block/commands.js"; import { insertNewNote, moveLineUp, selectAll } from "./block/commands.js";
export class HeynoteEditor { export class HeynoteEditor {
@ -48,6 +48,11 @@ export class HeynoteEditor {
preventDefault: true, preventDefault: true,
run: selectAll, run: selectAll,
}, },
{
key: "Alt-ArrowUp",
preventDefault: true,
run: moveLineUp,
}
]), ]),
customSetup, customSetup,