Procházet zdrojové kódy

add comments to make it easier to understand

kosei-n před 2 roky
rodič
revize
bac88e45b1

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

@@ -28,7 +28,7 @@ import { useInsertText, type InsertText } from './utils/insert-text';
 import { useReplaceText, type ReplaceText } from './utils/replace-text';
 import { useSetCaretLine, type SetCaretLine } from './utils/set-caret-line';
 
-
+// set new markdownKeymap instead of default one
 const markdownKeymap = [
   { key: 'Backspace', run: deleteMarkupBackward },
   { key: 'Enter', run: insertNewlineContinueMarkup },

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

@@ -17,6 +17,7 @@ export const insertNewlineContinueMarkup: StateCommand = ({ state, dispatch }) =
 
   const strFromBol = state.sliceDoc(bolPos, curPos);
 
+  // If the text before the cursor is only markdown symbols
   if (indentAndMarkOnlyRE.test(strFromBol)) {
     const insert = state.lineBreak;
 
@@ -27,6 +28,7 @@ export const insertNewlineContinueMarkup: StateCommand = ({ state, dispatch }) =
     });
   }
 
+  // If the text before the cursor is markdown text
   else if (indentAndMarkRE.test(strFromBol)) {
     const indentAndMark = strFromBol.match(indentAndMarkRE)?.[0];
 
@@ -45,6 +47,7 @@ export const insertNewlineContinueMarkup: StateCommand = ({ state, dispatch }) =
     });
   }
 
+  // If the text before the cursor is regular text
   else {
     const insert = state.lineBreak;
     const nextCurPos = curPos + insert.length;