Explorar o código

Merge pull request #8595 from weseek/imprv-142500-142716-fix-paste-operation-of-markdown

imprv: Fix paste operation of markdown
Yuki Takei %!s(int64=2) %!d(string=hai) anos
pai
achega
48ebac5995
Modificáronse 1 ficheiros con 17 adicións e 15 borrados
  1. 17 15
      packages/editor/src/services/paste-util/paste-markdown-util.ts

+ 17 - 15
packages/editor/src/services/paste-util/paste-markdown-util.ts

@@ -20,28 +20,30 @@ export const adjustPasteData = (strFromBol: string, text: string): string => {
 
 
   let adjusted = text;
   let adjusted = text;
 
 
-  if (text.match(indentAndMarkRE)) {
-    const matchResult = strFromBol.match(indentAndMarkRE);
-    const indent = matchResult ? matchResult[1] : '';
+  if (indentAndMarkOnlyRE.test(strFromBol)) {
+    if (text.match(indentAndMarkRE)) {
+      const matchResult = strFromBol.match(indentAndMarkRE);
+      const indent = matchResult ? matchResult[1] : '';
 
 
-    const lines = text.match(/[^\r\n]+/g);
+      const lines = text.match(/[^\r\n]+/g);
 
 
-    const replacedLines = lines?.map((line, index) => {
+      const replacedLines = lines?.map((line, index) => {
 
 
-      if (index === 0 && strFromBol.match(indentAndMarkOnlyRE)) {
-        return line.replace(indentAndMarkRE, '');
-      }
+        if (index === 0 && strFromBol.match(indentAndMarkOnlyRE)) {
+          return line.replace(indentAndMarkRE, '');
+        }
 
 
-      return indent + line;
-    });
+        return indent + line;
+      });
 
 
-    adjusted = replacedLines ? replacedLines.join('\n') : '';
-  }
+      adjusted = replacedLines ? replacedLines.join('\n') : '';
+    }
 
 
-  else if (strFromBol.match(indentAndMarkRE)) {
-    const replacedText = text.replace(/(\r\n|\r|\n)/g, `$1${strFromBol}`);
+    else {
+      const replacedText = text.replace(/(\r\n|\r|\n)/g, `$1${strFromBol}`);
 
 
-    adjusted = replacedText;
+      adjusted = replacedText;
+    }
   }
   }
 
 
   return adjusted;
   return adjusted;