mirror of
https://github.com/heyman/heynote.git
synced 2025-06-28 05:21:48 +02:00
Fix binding of Enter key
This commit is contained in:
parent
829806d265
commit
2859250def
@ -8,9 +8,11 @@ import {
|
|||||||
deleteToLineEnd, deleteToLineStart,
|
deleteToLineEnd, deleteToLineStart,
|
||||||
simplifySelection,
|
simplifySelection,
|
||||||
splitLine,
|
splitLine,
|
||||||
|
insertNewlineAndIndent,
|
||||||
} from "@codemirror/commands"
|
} from "@codemirror/commands"
|
||||||
import { foldCode, unfoldCode } from "@codemirror/language"
|
import { foldCode, unfoldCode } from "@codemirror/language"
|
||||||
import { selectNextOccurrence } from "@codemirror/search"
|
import { selectNextOccurrence } from "@codemirror/search"
|
||||||
|
import { insertNewlineContinueMarkup } from "@codemirror/lang-markdown"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
addNewBlockAfterCurrent, addNewBlockBeforeCurrent, addNewBlockAfterLast, addNewBlockBeforeFirst, insertNewBlockAtCursor,
|
addNewBlockAfterCurrent, addNewBlockBeforeCurrent, addNewBlockAfterLast, addNewBlockBeforeFirst, insertNewBlockAtCursor,
|
||||||
@ -113,6 +115,8 @@ const NON_EDITOR_CONTEXT_COMMANDS = {
|
|||||||
simplifySelection,
|
simplifySelection,
|
||||||
splitLine,
|
splitLine,
|
||||||
transposeChars,
|
transposeChars,
|
||||||
|
insertNewlineAndIndent,
|
||||||
|
insertNewlineContinueMarkup,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [key, cmCommand] of Object.entries(NON_EDITOR_CONTEXT_COMMANDS)) {
|
for (const [key, cmCommand] of Object.entries(NON_EDITOR_CONTEXT_COMMANDS)) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Annotation, EditorState, Compartment, Facet, EditorSelection, Transaction, Prec } from "@codemirror/state"
|
import { Annotation, EditorState, Compartment, Facet, EditorSelection, Transaction, Prec } from "@codemirror/state"
|
||||||
import { EditorView, keymap, drawSelection, ViewPlugin, lineNumbers } from "@codemirror/view"
|
import { EditorView, keymap as cmKeymap, drawSelection, ViewPlugin, lineNumbers } from "@codemirror/view"
|
||||||
import { indentUnit, forceParsing, foldGutter, ensureSyntaxTree } from "@codemirror/language"
|
import { indentUnit, forceParsing, foldGutter, ensureSyntaxTree } from "@codemirror/language"
|
||||||
import { markdown } from "@codemirror/lang-markdown"
|
import { markdown, markdownKeymap } from "@codemirror/lang-markdown"
|
||||||
import { closeBrackets } from "@codemirror/autocomplete";
|
import { closeBrackets } from "@codemirror/autocomplete";
|
||||||
import { undo, redo } from "@codemirror/commands"
|
import { undo, redo } from "@codemirror/commands"
|
||||||
|
|
||||||
@ -110,8 +110,12 @@ export class HeynoteEditor {
|
|||||||
|
|
||||||
autoSaveContent(this, AUTO_SAVE_INTERVAL),
|
autoSaveContent(this, AUTO_SAVE_INTERVAL),
|
||||||
|
|
||||||
|
// Markdown extensions, we need to add markdownKeymap manually with the highest precedence
|
||||||
|
// so that it takes precedence over the default keymap
|
||||||
todoCheckboxPlugin,
|
todoCheckboxPlugin,
|
||||||
markdown(),
|
markdown({addKeymap: false}),
|
||||||
|
Prec.highest(cmKeymap.of(markdownKeymap)),
|
||||||
|
|
||||||
links,
|
links,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
@ -40,6 +40,8 @@ const isLinux = window.heynote.platform.isLinux
|
|||||||
const isWindows = window.heynote.platform.isWindows
|
const isWindows = window.heynote.platform.isWindows
|
||||||
|
|
||||||
export const DEFAULT_KEYMAP = [
|
export const DEFAULT_KEYMAP = [
|
||||||
|
cmd("Enter", "insertNewlineAndIndent"),
|
||||||
|
|
||||||
cmd("Mod-a", "selectAll"),
|
cmd("Mod-a", "selectAll"),
|
||||||
cmd("Mod-Enter", "addNewBlockAfterCurrent"),
|
cmd("Mod-Enter", "addNewBlockAfterCurrent"),
|
||||||
cmd("Mod-Shift-Enter", "addNewBlockAfterLast"),
|
cmd("Mod-Shift-Enter", "addNewBlockAfterLast"),
|
||||||
@ -149,6 +151,13 @@ export const EMACS_KEYMAP = [
|
|||||||
|
|
||||||
|
|
||||||
export function heynoteKeymap(editor, keymap, userKeymap) {
|
export function heynoteKeymap(editor, keymap, userKeymap) {
|
||||||
|
//return [
|
||||||
|
// keymapFromSpec([
|
||||||
|
// ...Object.entries(userKeymap).map(([key, command]) => cmd(key, command)),
|
||||||
|
// ...keymap,
|
||||||
|
// ], editor),
|
||||||
|
//]
|
||||||
|
|
||||||
// merge the default keymap with the custom keymap
|
// merge the default keymap with the custom keymap
|
||||||
const defaultKeys = Object.fromEntries(keymap.map(km => [km.key, km.command]))
|
const defaultKeys = Object.fromEntries(keymap.map(km => [km.key, km.command]))
|
||||||
//let mergedKeys = Object.entries({...defaultKeys, ...Object.fromEntries(userKeymap.map(km => [km.key, km.command]))}).map(([key, command]) => cmd(key, command))
|
//let mergedKeys = Object.entries({...defaultKeys, ...Object.fromEntries(userKeymap.map(km => [km.key, km.command]))}).map(([key, command]) => cmd(key, command))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user