kosei-n 2 лет назад
Родитель
Сommit
bd923eac20

+ 20 - 20
packages/editor/src/components/CodeMirrorEditor/CodeMirrorEditor.tsx

@@ -10,7 +10,7 @@ import { GlobalCodeMirrorEditorKey, AcceptedUploadFileType } from '../../consts'
 import { useFileDropzone, FileDropzoneOverlay } from '../../services';
 import {
   getLineToCursor, adjustPasteData,
-  useNewlineAndIndentContinueMarkdownList,
+  // useNewlineAndIndentContinueMarkdownList,
 } from '../../services/list-util/markdown-list-util';
 import { useCodeMirrorEditorIsolated } from '../../stores';
 
@@ -55,25 +55,25 @@ export const CodeMirrorEditor = (props: Props): JSX.Element => {
 
   const editor = codeMirrorEditor?.view;
 
-  const newlineAndIndentContinueMarkdownList = useNewlineAndIndentContinueMarkdownList(editor);
-
-  useEffect(() => {
-    const handleEnterKey = (event: KeyboardEvent) => {
-      if (event.key === 'Enter') {
-        event.preventDefault();
-        if (editor == null) {
-          return;
-        }
-        newlineAndIndentContinueMarkdownList?.(editor);
-      }
-    };
-
-    editor?.dom.addEventListener('keydown', handleEnterKey);
-
-    return () => {
-      editor?.dom.removeEventListener('keydown', handleEnterKey);
-    };
-  }, [codeMirrorEditor, editor, newlineAndIndentContinueMarkdownList]);
+  // const newlineAndIndentContinueMarkdownList = useNewlineAndIndentContinueMarkdownList(editor);
+
+  // useEffect(() => {
+  //   const handleEnterKey = (event: KeyboardEvent) => {
+  //     if (event.key === 'Enter') {
+  //       event.preventDefault();
+  //       if (editor == null) {
+  //         return;
+  //       }
+  //       newlineAndIndentContinueMarkdownList?.(editor);
+  //     }
+  //   };
+
+  //   editor?.dom.addEventListener('keydown', handleEnterKey);
+
+  //   return () => {
+  //     editor?.dom.removeEventListener('keydown', handleEnterKey);
+  //   };
+  // }, [codeMirrorEditor, editor, newlineAndIndentContinueMarkdownList]);
 
   useEffect(() => {
     if (indentSize == null) {

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

@@ -5,7 +5,7 @@ import {
   markdown, markdownLanguage,
 } from '@codemirror/lang-markdown';
 import { syntaxHighlighting, HighlightStyle, defaultHighlightStyle } from '@codemirror/language';
-import { languages } from '@codemirror/language-data';
+import { languages, deleteMarkupBackward } from '@codemirror/language-data';
 import {
   EditorState, Prec, type Extension,
 } from '@codemirror/state';
@@ -27,6 +27,10 @@ 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';
 
+const markdownKeymap = [
+  { key: 'Backspace', run: deleteMarkupBackward },
+  { key: 'Enter', run:  }
+];
 
 const markdownHighlighting = HighlightStyle.define([
   { tag: tags.heading1, class: 'cm-header-1 cm-header' },
@@ -58,6 +62,7 @@ export type UseCodeMirrorEditor = {
 const defaultExtensions: Extension[] = [
   EditorView.lineWrapping,
   markdown({ base: markdownLanguage, codeLanguages: languages }),
+  // keymap.of(markdownKeymap),
   keymap.of([indentWithTab]),
   Prec.lowest(keymap.of(defaultKeymap)),
   syntaxHighlighting(markdownHighlighting),

+ 2 - 2
packages/editor/src/services/list-util/markdown-list-util.ts

@@ -24,7 +24,7 @@ export const getLineToCursor = (editor: EditorView, lineNumBeforeCursor = 0): st
 export const useNewlineAndIndentContinueMarkdownList = (editor?: EditorView): NewlineAndIndentContinueMarkdownList => {
   const insertText = useInsertText(editor);
 
-  const NewlineAndIndentContinueMarkdownList = useCallback((view: EditorView) => {
+  const newlineAndIndentContinueMarkdownList = useCallback((view: EditorView) => {
 
     const curPos = view?.state.selection.main.head;
     const lineStartPos = view?.state.doc.lineAt(curPos).from;
@@ -43,7 +43,7 @@ export const useNewlineAndIndentContinueMarkdownList = (editor?: EditorView): Ne
     return;
   }
 
-  return () => { NewlineAndIndentContinueMarkdownList(editor) };
+  return () => { newlineAndIndentContinueMarkdownList(editor) };
 };
 
 export const adjustPasteData = (indentAndMark: string, text: string): string => {