diff --git a/electron/initial-content.ts b/electron/initial-content.ts index 2e8cc49..24c7cb0 100644 --- a/electron/initial-content.ts +++ b/electron/initial-content.ts @@ -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 diff --git a/src/editor/block/commands.js b/src/editor/block/commands.js index 59ea6e5..ecbacb7 100644 --- a/src/editor/block/commands.js +++ b/src/editor/block/commands.js @@ -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) diff --git a/src/editor/keymap.js b/src/editor/keymap.js index 42a25e9..46369d6 100644 --- a/src/editor/keymap.js +++ b/src/editor/keymap.js @@ -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(), - } + }, ]) } \ No newline at end of file