Liyuan Li 5 years ago
parent
commit
1d0c15f25b
5 changed files with 5 additions and 9 deletions
  1. 1 0
      CHANGELOG.md
  2. 2 2
      demo/index.js
  3. 1 1
      src/ts/ir/input.ts
  4. 0 5
      src/ts/util/fixBrowserBehavior.ts
  5. 1 1
      src/ts/util/processCode.ts

+ 1 - 0
CHANGELOG.md

@@ -81,6 +81,7 @@
 
 ### v3.4.0 / 2020-07-xx
 
+* [644](https://github.com/Vanessa219/vditor/pull/644) 粘贴多行代码时,避免代码段与当前行内容混淆在一起 `改进功能`
 * [639](https://github.com/Vanessa219/vditor/issues/639) 列表嵌套代码块后输入中文的问题 `修复缺陷`
 * [641](https://github.com/Vanessa219/vditor/issues/641) 清空 undo 栈后,第一次编辑操作无法进行记录 `修复缺陷`
 * [640](https://github.com/Vanessa219/vditor/issues/640) options.icon 无法进行切换 `改进功能`

+ 2 - 2
demo/index.js

@@ -50,8 +50,8 @@ if (window.innerWidth < 768) {
 }
 
 window.vditor = new Vditor('vditor', {
-  _lutePath: `http://192.168.0.107:9090/lute.min.js?${new Date().getTime()}`,
-  // _lutePath: 'src/js/lute/lute.min.js',
+  // _lutePath: `http://192.168.0.107:9090/lute.min.js?${new Date().getTime()}`,
+  _lutePath: 'src/js/lute/lute.min.js',
   toolbar,
   mode: 'wysiwyg',
   height: window.innerHeight + 100,

+ 1 - 1
src/ts/ir/input.ts

@@ -78,7 +78,7 @@ export const input = (vditor: IVditor, range: Range, ignoreSpace = false) => {
 
     if (!blockElement.querySelector("wbr")) {
         const previewRenderElement = hasClosestByClassName(range.startContainer, "vditor-ir__preview");
-        if (previewRenderElement) {
+        if (previewRenderElement && previewRenderElement.previousElementSibling) {
             // 光标如果落在预览区域中,则重置到代码区域
             if (previewRenderElement.previousElementSibling.firstElementChild) {
                 range.selectNodeContents(previewRenderElement.previousElementSibling.firstElementChild);

+ 0 - 5
src/ts/util/fixBrowserBehavior.ts

@@ -1292,11 +1292,6 @@ export const paste = (vditor: IVditor, event: ClipboardEvent & { target: HTMLEle
             }
         }
     } else if (code) {
-        let codeFix = code;
-        if (/\n/.test(code)) {
-            // 粘贴多行代码时,避免代码段的 ``` 与当前行内容混淆在一起
-            codeFix = `\n${code}`;
-        }
         callback.pasteCode(code);
     } else {
         if (textHTML.trim() !== "") {

+ 1 - 1
src/ts/util/processCode.ts

@@ -40,7 +40,7 @@ export const processPasteCode = (html: string, text: string, type = "sv") => {
                 return `<div class="vditor-wysiwyg__block" data-block="0" data-type="code-block"><pre><code>${
                     code.replace(/&/g, "&amp;").replace(/</g, "&lt;")}<wbr></code></pre></div>`;
             }
-            return "```\n" + code.replace(/&/g, "&amp;").replace(/</g, "&lt;") + "\n```";
+            return "\n```\n" + code.replace(/&/g, "&amp;").replace(/</g, "&lt;") + "\n```";
         } else {
             if (type === "wysiwyg") {
                 return `<code>${code.replace(/&/g, "&amp;").replace(/</g, "&lt;")}</code><wbr>`;