Browse Source

clean codes

kosei-n 2 years ago
parent
commit
84e8315932

+ 2 - 25
packages/editor/src/components/CodeMirrorEditor/CodeMirrorEditor.tsx

@@ -9,8 +9,7 @@ import type { ReactCodeMirrorProps } from '@uiw/react-codemirror';
 import { GlobalCodeMirrorEditorKey, AcceptedUploadFileType } from '../../consts';
 import { useFileDropzone, FileDropzoneOverlay } from '../../services';
 import {
-  adjustPasteData,
-  // useNewlineAndIndentContinueMarkdownList,
+  getStrFromBol, adjustPasteData,
 } from '../../services/list-util/markdown-list-util';
 import { useCodeMirrorEditorIsolated } from '../../stores';
 
@@ -53,28 +52,6 @@ export const CodeMirrorEditor = (props: Props): JSX.Element => {
   }, [onChange]);
   const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(editorKey, containerRef.current, cmProps);
 
-  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]);
-
   useEffect(() => {
     if (indentSize == null) {
       return;
@@ -108,7 +85,7 @@ export const CodeMirrorEditor = (props: Props): JSX.Element => {
 
         const textData = event.clipboardData.getData('text/plain');
 
-        // const strFromBol = getLineToCursor(editor);
+        const strFromBol = getStrFromBol(editor);
 
         const adjusted = adjustPasteData(strFromBol, textData);
 

+ 6 - 11
packages/editor/src/services/codemirror-editor/use-codemirror-editor/utils/insert-text.ts

@@ -1,28 +1,23 @@
 import { useCallback } from 'react';
 
-import { type EditorView } from '@codemirror/view';
-
-export type InsertText = (text: string, from?: number, to?: number) => void;
+import { EditorView } from '@codemirror/view';
 
+export type InsertText = (text: string) => void;
 
 export const useInsertText = (view?: EditorView): InsertText => {
-  return useCallback((text, from?, to?) => {
+
+  return useCallback((text) => {
     if (view == null) {
       return;
     }
     const insertPos = view.state.selection.main.head;
-
-    const fromPos = from ?? insertPos;
-    const toPos = to ?? insertPos;
-
     view.dispatch({
       changes: {
-        from: fromPos,
-        to: toPos,
+        from: insertPos,
+        to: insertPos,
         insert: text,
       },
       selection: { anchor: insertPos },
     });
   }, [view]);
-
 };

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

@@ -1,41 +1,6 @@
-import { useCallback } from 'react';
-
-import { EditorView } from '@codemirror/view';
-
-
-import { useInsertText } from '../codemirror-editor/use-codemirror-editor/utils/insert-text';
-
-
-export type NewlineAndIndentContinueMarkdownList = ((editor: EditorView) => void) | undefined;
-
 // https://regex101.com/r/7BN2fR/5
 const indentAndMarkRE = /^(\s*)(>[> ]*|[*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]))(\s*)/;
 
-// export const useNewlineAndIndentContinueMarkdownList = (editor?: EditorView): NewlineAndIndentContinueMarkdownList => {
-//   const insertText = useInsertText(editor);
-
-//   const newlineAndIndentContinueMarkdownList = useCallback((view: EditorView) => {
-
-//     const curPos = view?.state.selection.main.head;
-//     const lineStartPos = view?.state.doc.lineAt(curPos).from;
-
-//     const getStrFromAboveLine = getLineToCursor(view, 1);
-
-//     const matchResult = getStrFromAboveLine.match(indentAndMarkRE);
-
-//     if (matchResult != null) {
-//       const indentAndMark = matchResult[0];
-//       insertText(indentAndMark, lineStartPos, curPos);
-//     }
-//   }, [insertText]);
-
-//   if (editor == null) {
-//     return;
-//   }
-
-//   return () => { newlineAndIndentContinueMarkdownList(editor) };
-// };
-
 export const adjustPasteData = (indentAndMark: string, text: string): string => {
 
   let adjusted;