Răsfoiți Sursa

implement of adjustPasteData

kosei-n 2 ani în urmă
părinte
comite
e296f2efaf

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

@@ -1,7 +1,7 @@
 import { useMemo } from 'react';
 
 import { indentWithTab, defaultKeymap } from '@codemirror/commands';
-import { markdown, markdownLanguage, markdownKeymap } from '@codemirror/lang-markdown';
+import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
 import { syntaxHighlighting, HighlightStyle, defaultHighlightStyle } from '@codemirror/language';
 import { languages } from '@codemirror/language-data';
 import { EditorState, Prec, type Extension } from '@codemirror/state';

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

@@ -8,7 +8,7 @@ const getBol = (editor: EditorView) => {
   return editor.state.doc.line(aboveLine).from;
 };
 
-export const getStrFromBol = (editor: EditorView) => {
+export const getStrFromBol = (editor: EditorView): string => {
   const curPos = editor.state.selection.main.head;
   return editor.state.sliceDoc(getBol(editor), curPos);
 };
@@ -28,8 +28,6 @@ const insertText = (editor: EditorView, text: string) => {
 export const newlineAndIndentContinueMarkdownList = (editor: EditorView): void => {
   const strFromBol = getStrFromBol(editor);
 
-  console.log(strFromBol);
-
   const matchResult = strFromBol.match(indentAndMarkRE);
 
   if (matchResult != null) {
@@ -47,14 +45,6 @@ const selectUpperPos = (editor: EditorView, pos1: number, pos2: number) => {
   const pos1Ch = pos1 - editor.state.doc.lineAt(pos1).from;
   const pos2Ch = pos2 - editor.state.doc.lineAt(pos2).from;
 
-  console.log(pos1);
-  console.log(pos2);
-  console.log(pos1Line);
-  console.log(pos2Line);
-  console.log(pos1Ch);
-  console.log(pos2Ch);
-
-
   if (pos1Line === pos2Line) {
     return (pos1Ch < pos2Ch) ? pos1 : pos2;
   }
@@ -79,7 +69,12 @@ export const adjustPasteData = (indentAndMark: string, text: string): string =>
 
     const lines = text.match(/[^\r\n]+/g);
 
-    const replacedLines = lines?.map((line) => {
+    const replacedLines = lines?.map((line, index) => {
+
+      if (index === 0 && indentAndMark.match(indentAndMarkRE)) {
+        return line.replace(indentAndMarkRE, '');
+      }
+
       return indent + line;
     });