Przeglądaj źródła

crate onPressEnter handler in use-codemiror-editor.ts

kosei-n 2 lat temu
rodzic
commit
55dbbbe44c

+ 6 - 1
packages/editor/src/services/codemirror-editor/use-codemirror-editor/use-codemirror-editor.ts

@@ -34,13 +34,18 @@ import { useReplaceText, type ReplaceText } from './utils/replace-text';
 import { useSetCaretLine, type SetCaretLine } from './utils/set-caret-line';
 
 
+const onPressEnter = ({ state, dispatch }) => {
+  // insertNewlineContinueMarkup(state, dispatch);
+  insertNewRowToMarkdownTable(state, dispatch);
+};
+
 // set new markdownKeymap instead of default one
 // I also bound the deleteMarkupBackward to the backspace key to align with the existing keymap
 // https://github.com/codemirror/lang-markdown/blob/main/src/index.ts#L17
 const markdownKeymap = [
   { key: 'Backspace', run: deleteMarkupBackward },
   // { key: 'Enter', run: insertNewlineContinueMarkup },
-  { key: 'Enter', run: insertNewRowToMarkdownTable },
+  { key: 'Enter', run: onPressEnter },
 ];
 
 const markdownHighlighting = HighlightStyle.define([

+ 4 - 2
packages/editor/src/services/codemirror-editor/use-codemirror-editor/utils/insert-newline-continue-markup.ts

@@ -1,10 +1,12 @@
-import type { ChangeSpec, StateCommand } from '@codemirror/state';
+import type {
+  ChangeSpec, StateCommand, EditorState, Transaction,
+} from '@codemirror/state';
 
 // https://regex101.com/r/7BN2fR/5
 const indentAndMarkRE = /^(\s*)(>[> ]*|[*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]))(\s*)/;
 const indentAndMarkOnlyRE = /^(\s*)(>[> ]*|[*+-] \[[x ]\]|[*+-]|(\d+)[.)])(\s*)$/;
 
-export const insertNewlineContinueMarkup: StateCommand = ({ state, dispatch }) => {
+export const insertNewlineContinueMarkup: StateCommand = (state: EditorState, dispatch: (transaction: Transaction) => boolean) => {
 
   const changes: ChangeSpec[] = [];