mirror of
https://github.com/heyman/heynote.git
synced 2025-06-20 09:37:50 +02:00
Add functionality for creating new cursors using Cmd/Ctrl + Alt + Up/Down
This commit is contained in:
parent
9015986b82
commit
1c78aca88a
@ -244,4 +244,36 @@ export function gotoPreviousParagraph({state, dispatch}) {
|
|||||||
|
|
||||||
export function selectPreviousParagraph({state, dispatch}) {
|
export function selectPreviousParagraph({state, dispatch}) {
|
||||||
return extendSel(state, dispatch, range => previousParagraph(state, range))
|
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)
|
||||||
|
}
|
||||||
|
@ -13,6 +13,7 @@ import {
|
|||||||
selectNextBlock, selectPreviousBlock,
|
selectNextBlock, selectPreviousBlock,
|
||||||
gotoPreviousParagraph, gotoNextParagraph,
|
gotoPreviousParagraph, gotoNextParagraph,
|
||||||
selectNextParagraph, selectPreviousParagraph,
|
selectNextParagraph, selectPreviousParagraph,
|
||||||
|
newCursorBelow, newCursorAbove,
|
||||||
} from "./block/commands.js"
|
} from "./block/commands.js"
|
||||||
|
|
||||||
import { formatBlockContent } from "./block/format-code.js"
|
import { formatBlockContent } from "./block/format-code.js"
|
||||||
@ -44,6 +45,8 @@ export function heynoteKeymap(editor) {
|
|||||||
["Alt-ArrowDown", moveLineDown],
|
["Alt-ArrowDown", moveLineDown],
|
||||||
["Mod-l", () => editor.openLanguageSelector()],
|
["Mod-l", () => editor.openLanguageSelector()],
|
||||||
["Alt-Shift-f", formatBlockContent],
|
["Alt-Shift-f", formatBlockContent],
|
||||||
|
["Mod-Alt-ArrowDown", newCursorBelow],
|
||||||
|
["Mod-Alt-ArrowUp", newCursorAbove],
|
||||||
{key:"Mod-ArrowUp", run:gotoPreviousBlock, shift:selectPreviousBlock},
|
{key:"Mod-ArrowUp", run:gotoPreviousBlock, shift:selectPreviousBlock},
|
||||||
{key:"Mod-ArrowDown", run:gotoNextBlock, shift:selectNextBlock},
|
{key:"Mod-ArrowDown", run:gotoNextBlock, shift:selectNextBlock},
|
||||||
{key:"Ctrl-ArrowUp", run:gotoPreviousParagraph, shift:selectPreviousParagraph},
|
{key:"Ctrl-ArrowUp", run:gotoPreviousParagraph, shift:selectPreviousParagraph},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user