Liyuan Li 5 years ago
parent
commit
d9c5374c78
4 changed files with 38 additions and 44 deletions
  1. 3 0
      CHANGELOG.md
  2. 3 3
      demo/index.js
  3. 0 0
      src/js/lute/lute.min.js
  4. 32 41
      src/ts/undo/index.ts

+ 3 - 0
CHANGELOG.md

@@ -68,6 +68,9 @@
 
 ### v3.3.12 / 2020-07-xx
 
+* [621](https://github.com/Vanessa219/vditor/issues/621) 粘贴数学公式时渲染报错 `修复缺陷`
+* [619](https://github.com/Vanessa219/vditor/issues/619) 即时渲染下list删除(或剪切)的问题 `修复缺陷`
+* [633](https://github.com/Vanessa219/vditor/issues/633) SV 模式光标在列表标记符中的问题 `修复缺陷`
 * [623](https://github.com/Vanessa219/vditor/pull/623) 修复即时渲染模式下复制光标位置错误和添加位置错误的问题 `修复缺陷`
 * [608](https://github.com/Vanessa219/vditor/issues/608) 更新使用截图和演示动画 `文档相关`
 * [587](https://github.com/Vanessa219/vditor/issues/587) IR & SV 保留 Setext 风格标题 `改进功能`

+ 3 - 3
demo/index.js

@@ -50,10 +50,10 @@ 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',
+  mode: 'ir',
   height: window.innerHeight + 100,
   outline: true,
   debugger: true,

File diff suppressed because it is too large
+ 0 - 0
src/js/lute/lute.min.js


+ 32 - 41
src/ts/undo/index.ts

@@ -93,56 +93,24 @@ class Undo {
             // Safari keydown 在 input 之后,不需要重复记录历史
             return;
         }
-        getSelection().getRangeAt(0).insertNode(document.createElement("wbr"));
-        if (vditor.currentMode === "wysiwyg") {
-            this[vditor.currentMode].undoStack[0][0].diffs[0][1] =
-                vditor.lute.SpinVditorDOM(vditor[vditor.currentMode].element.innerHTML);
-        } else if (vditor.currentMode === "ir") {
-            this[vditor.currentMode].undoStack[0][0].diffs[0][1] =
-                vditor.lute.SpinVditorIRDOM(vditor[vditor.currentMode].element.innerHTML);
-        } else {
-            this[vditor.currentMode].undoStack[0][0].diffs[0][1] = vditor[vditor.currentMode].element.innerHTML;
-        }
-        this[vditor.currentMode].lastText = this[vditor.currentMode].undoStack[0][0].diffs[0][1];
-        const wbrElement =
-            vditor[vditor.currentMode].element.querySelector("wbr");
-        if (wbrElement) {
-            wbrElement.remove();
-        }
+        const caretObj = this.addCaret(vditor);
+        this[vditor.currentMode].undoStack[0][0].diffs[0][1] = caretObj.text;
+        this[vditor.currentMode].lastText = caretObj.text;
         // 不能添加 setSelectionFocus(cloneRange); 否则 windows chrome 首次输入会烂
     }
 
     public addToUndoStack(vditor: IVditor) {
         // afterRenderEvent.ts 已经 debounce
-        let cloneRange: Range;
-        if (getSelection().rangeCount !== 0 && !vditor[vditor.currentMode].element.querySelector("wbr")) {
-            const range = getSelection().getRangeAt(0);
-            if (vditor[vditor.currentMode].element.contains(range.startContainer)) {
-                cloneRange = range.cloneRange();
-                range.insertNode(document.createElement("wbr"));
-            }
-        }
-        let text;
-        if (vditor.currentMode === "wysiwyg") {
-            text = vditor.lute.SpinVditorDOM(vditor[vditor.currentMode].element.innerHTML);
-        } else if (vditor.currentMode === "ir") {
-            text = vditor.lute.SpinVditorIRDOM(vditor[vditor.currentMode].element.innerHTML);
-        } else {
-            text = vditor[vditor.currentMode].element.innerHTML;
-        }
-        const wbrElement = vditor[vditor.currentMode].element.querySelector("wbr");
-        if (wbrElement) {
-            wbrElement.remove();
+        const caretObj = this.addCaret(vditor);
+        if (caretObj.cloneRange) {
+            setSelectionFocus(caretObj.cloneRange);
         }
-        if (cloneRange) {
-            setSelectionFocus(cloneRange);
-        }
-        const diff = this.dmp.diff_main(text, this[vditor.currentMode].lastText, true);
-        const patchList = this.dmp.patch_make(text, this[vditor.currentMode].lastText, diff);
+        const diff = this.dmp.diff_main(caretObj.text, this[vditor.currentMode].lastText, true);
+        const patchList = this.dmp.patch_make(caretObj.text, this[vditor.currentMode].lastText, diff);
         if (patchList.length === 0 && this[vditor.currentMode].undoStack.length > 0) {
             return;
         }
-        this[vditor.currentMode].lastText = text;
+        this[vditor.currentMode].lastText = caretObj.text;
         this[vditor.currentMode].undoStack.push(patchList);
         if (this[vditor.currentMode].undoStack.length > this.stackSize) {
             this[vditor.currentMode].undoStack.shift();
@@ -232,6 +200,29 @@ class Undo {
             undoStack: [],
         };
     }
+
+    private addCaret(vditor: IVditor) {
+        let cloneRange: Range;
+        if (getSelection().rangeCount !== 0 && !vditor[vditor.currentMode].element.querySelector("wbr")) {
+            const range = getSelection().getRangeAt(0);
+            if (vditor[vditor.currentMode].element.contains(range.startContainer)) {
+                cloneRange = range.cloneRange();
+                const wbrTempElement = document.createElement("span");
+                wbrTempElement.className = "vditor-wbr";
+                range.insertNode(wbrTempElement);
+            }
+        }
+
+        const text = vditor[vditor.currentMode].element.innerHTML;
+        const wbrElement = vditor[vditor.currentMode].element.querySelector(".wbr");
+        if (wbrElement) {
+            wbrElement.remove();
+        }
+        return {
+            cloneRange,
+            text: text.replace('<span class="vditor-wbr"></span>', "<wbr>"),
+        };
+    }
 }
 
 export {Undo};

Some files were not shown because too many files changed in this diff