mirror of
https://github.com/heyman/heynote.git
synced 2024-11-22 16:03:28 +01:00
Move keymap into its own JS module
This commit is contained in:
parent
c8e4861ffe
commit
51bb893836
@ -2,12 +2,11 @@ import { Annotation, EditorState, Compartment } from "@codemirror/state"
|
||||
import { EditorView, keymap, drawSelection } from "@codemirror/view"
|
||||
import { indentUnit, forceParsing } from "@codemirror/language"
|
||||
|
||||
import { indentWithTab, insertTab, indentLess, indentMore } from "@codemirror/commands"
|
||||
import { nord } from "./theme/nord.mjs"
|
||||
import { customSetup } from "./setup.js"
|
||||
import { heynoteLang } from "./lang-heynote/heynote.js"
|
||||
import { noteBlockExtension } from "./block/note-block.js"
|
||||
import { insertNewNote, moveLineUp, selectAll } from "./block/commands.js";
|
||||
import { heynoteKeymap } from "./keymap.js"
|
||||
|
||||
|
||||
export class HeynoteEditor {
|
||||
@ -15,46 +14,9 @@ export class HeynoteEditor {
|
||||
this.state = EditorState.create({
|
||||
doc: content || "",
|
||||
extensions: [
|
||||
/*keymap.of([
|
||||
{
|
||||
key: "Shift-Tab",
|
||||
preventDefault: true,
|
||||
run: () => {
|
||||
console.log("debug:", syntaxTree(editor.state).toString())
|
||||
},
|
||||
},
|
||||
]),*/
|
||||
heynoteKeymap,
|
||||
|
||||
//minimalSetup,
|
||||
|
||||
keymap.of([
|
||||
{
|
||||
key: "Tab",
|
||||
preventDefault: true,
|
||||
//run: insertTab,
|
||||
run: indentMore,
|
||||
},
|
||||
{
|
||||
key: 'Shift-Tab',
|
||||
preventDefault: true,
|
||||
run: indentLess,
|
||||
},
|
||||
{
|
||||
key: "Mod-Enter",
|
||||
preventDefault: true,
|
||||
run: insertNewNote,
|
||||
},
|
||||
{
|
||||
key: "Mod-a",
|
||||
preventDefault: true,
|
||||
run: selectAll,
|
||||
},
|
||||
{
|
||||
key: "Alt-ArrowUp",
|
||||
preventDefault: true,
|
||||
run: moveLineUp,
|
||||
}
|
||||
]),
|
||||
|
||||
customSetup,
|
||||
nord,
|
||||
indentUnit.of(" "),
|
||||
|
32
heynote-codemirror/src/keymap.js
Normal file
32
heynote-codemirror/src/keymap.js
Normal file
@ -0,0 +1,32 @@
|
||||
import { keymap } from "@codemirror/view"
|
||||
import { indentWithTab, insertTab, indentLess, indentMore } from "@codemirror/commands"
|
||||
import { insertNewNote, moveLineUp, selectAll } from "./block/commands.js";
|
||||
|
||||
export const heynoteKeymap = keymap.of([
|
||||
{
|
||||
key: "Tab",
|
||||
preventDefault: true,
|
||||
//run: insertTab,
|
||||
run: indentMore,
|
||||
},
|
||||
{
|
||||
key: 'Shift-Tab',
|
||||
preventDefault: true,
|
||||
run: indentLess,
|
||||
},
|
||||
{
|
||||
key: "Mod-Enter",
|
||||
preventDefault: true,
|
||||
run: insertNewNote,
|
||||
},
|
||||
{
|
||||
key: "Mod-a",
|
||||
preventDefault: true,
|
||||
run: selectAll,
|
||||
},
|
||||
{
|
||||
key: "Alt-ArrowUp",
|
||||
preventDefault: true,
|
||||
run: moveLineUp,
|
||||
}
|
||||
])
|
Loading…
Reference in New Issue
Block a user