Add new command for adding a new block after the current one, and moving the cursor to it. Change default Mod-Enter keybinding to use the new command, and added a new Mod-Shift-Enter keybinding to use the old command that inserts a new block separator at the cursor position (e.g. splits the current block).

#windows-build
This commit is contained in:
Jonatan Heyman 2023-01-19 14:29:03 +01:00
parent 1abefce1ec
commit aa628a4f08
3 changed files with 42 additions and 16 deletions

View File

@ -6,12 +6,13 @@ export const initialContent = `
text
Welcome to Heynote!
[${modChar} + Enter] Insert new note block at cursor
[${modChar} + L] Change block language
[${modChar} + Down] Goto next block
[${modChar} + Up] Goto previous block
[${modChar} + A] Select all text in a note block. Press again to select the whole scratchpad
[${modChar} + + Up/Down]  Add additional cursor above/below
[${modChar} + Enter] Add new block and move cursor to it
[${modChar} + Shift + Enter] Split the current block at cursor position
[${modChar} + L] Change block language
[${modChar} + Down] Goto next block
[${modChar} + Up] Goto previous block
[${modChar} + A] Select all text in a note block. Press again to select the whole scratchpad
[${modChar} + + Up/Down]  Add additional cursor above/below
text-a
`
@ -19,12 +20,13 @@ export const initialDevContent = `
text-a
Welcome to Heynote!
[ + Enter] Insert new note block
[ + F] Find text
[ + A] Select all text in a note block. Press again to select the whole scratchpad
[ + Up] Go to start of note (or start of previous note if already at the start)
[ + Down] Go to end of note (or end of next note if already at the end)
[ + + Up/Down]  Add additional cursor above/below
[${modChar} + Enter] Add new block and move cursor to it
[${modChar} + Shift + Enter] Split the current block at cursor position
[${modChar} + L] Change block language
[${modChar} + Down] Goto next block
[${modChar} + Up] Goto previous block
[${modChar} + A] Select all text in a note block. Press again to select the whole scratchpad
[${modChar} + + Up/Down]  Add additional cursor above/below
python-a
# hmm

View File

@ -9,7 +9,7 @@ import { blockState, getActiveNoteBlock, getNoteBlockFromPos } from "./block"
import { levenshtein_distance } from "../language-detection/levenshtein"
export const insertNewNote = ({ state, dispatch }) => {
export const insertNewBlockAtCursor = ({ state, dispatch }) => {
if (state.readOnly)
return false
@ -24,6 +24,25 @@ export const insertNewNote = ({ state, dispatch }) => {
return true;
}
export const addNewBlockAfterCurrent = ({ state, dispatch }) => {
if (state.readOnly)
return false
const block = getActiveNoteBlock(state)
const delimText = "\n∞∞∞text-a\n"
dispatch(state.update({
changes: {
from: block.content.to,
insert: delimText,
},
selection: EditorSelection.cursor(block.content.to + delimText.length)
}, {
scrollIntoView: true,
userEvent: "input",
}))
return true;
}
export const selectAll = ({ state, dispatch }) => {
const range = state.selection.asSingle().ranges[0]
const block = getActiveNoteBlock(state)

View File

@ -1,6 +1,6 @@
import { keymap } from "@codemirror/view"
import { indentWithTab, insertTab, indentLess, indentMore } from "@codemirror/commands"
import { insertNewNote, moveLineUp, selectAll, gotoPreviousBlock, gotoNextBlock } from "./block/commands.js";
import { insertNewBlockAtCursor, addNewBlockAfterCurrent, moveLineUp, selectAll, gotoPreviousBlock, gotoNextBlock } from "./block/commands.js";
export function heynoteKeymap(editor) {
return keymap.of([
@ -18,7 +18,12 @@ export function heynoteKeymap(editor) {
{
key: "Mod-Enter",
preventDefault: true,
run: insertNewNote,
run: addNewBlockAfterCurrent,
},
{
key: "Mod-Shift-Enter",
preventDefault: true,
run: insertNewBlockAtCursor,
},
{
key: "Mod-a",
@ -44,6 +49,6 @@ export function heynoteKeymap(editor) {
key: "Mod-l",
preventDefault: true,
run: () => editor.openLanguageSelector(),
}
},
])
}