Add functionality for creating new cursors using Cmd/Ctrl + Alt + Up/Down

This commit is contained in:
Jonatan Heyman 2023-03-13 17:22:27 +01:00
parent 9015986b82
commit 1c78aca88a
2 changed files with 36 additions and 1 deletions

View File

@ -244,4 +244,36 @@ export function gotoPreviousParagraph({state, dispatch}) {
export function selectPreviousParagraph({state, dispatch}) {
return extendSel(state, dispatch, range => previousParagraph(state, range))
}
}
function newCursor(view, below) {
const sel = view.state.selection
const ranges = sel.ranges
const newRanges = [...ranges]
for (let i = 0; i < ranges.length; i++) {
let range = ranges[i]
let newRange = view.moveVertically(range, below)
let exists = false
for (let j=0; j < ranges.length; j++) {
if (newRange.eq(ranges[j])) {
exists = true
break
}
}
if (!exists) {
newRanges.push(newRange)
}
}
const newSelection = EditorSelection.create(newRanges, sel.mainIndex)
view.dispatch({selection: newSelection})
}
export function newCursorBelow(view) {
newCursor(view, true)
}
export function newCursorAbove(view) {
newCursor(view, false)
}

View File

@ -13,6 +13,7 @@ import {
selectNextBlock, selectPreviousBlock,
gotoPreviousParagraph, gotoNextParagraph,
selectNextParagraph, selectPreviousParagraph,
newCursorBelow, newCursorAbove,
} from "./block/commands.js"
import { formatBlockContent } from "./block/format-code.js"
@ -44,6 +45,8 @@ export function heynoteKeymap(editor) {
["Alt-ArrowDown", moveLineDown],
["Mod-l", () => editor.openLanguageSelector()],
["Alt-Shift-f", formatBlockContent],
["Mod-Alt-ArrowDown", newCursorBelow],
["Mod-Alt-ArrowUp", newCursorAbove],
{key:"Mod-ArrowUp", run:gotoPreviousBlock, shift:selectPreviousBlock},
{key:"Mod-ArrowDown", run:gotoNextBlock, shift:selectNextBlock},
{key:"Ctrl-ArrowUp", run:gotoPreviousParagraph, shift:selectPreviousParagraph},