Skip to content

Commit

Permalink
🐛 fix #118
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Feb 9, 2020
1 parent fc7b983 commit 2887084
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

### v2.1.12 / 2020-02-07

* [123](https://github.com/Vanessa219/vditor/issues/123) 加粗、强调前导空格问题 `修复缺陷`
* [118](https://github.com/Vanessa219/vditor/issues/118) Firefox no cursor when ctrl+b pressed `修复缺陷`
* [117](https://github.com/Vanessa219/vditor/issues/117) cursor moving problem near inline code `修复缺陷`
* [115](https://github.com/Vanessa219/vditor/issues/115) codeblock difference between ``` and ctrl+u `修复缺陷`
* [114](https://github.com/Vanessa219/vditor/issues/114) 有序列表合并问题 `修复缺陷`
Expand Down
14 changes: 7 additions & 7 deletions src/ts/undo/WysiwygUndo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,29 @@ class WysiwygUndo {

public recordFirstWbr(vditor: IVditor) {
if (this.undoStack.length === 1) {
getSelection().getRangeAt(0).insertNode(document.createElement("wbr"));
const range = getSelection().getRangeAt(0).cloneRange()
range.insertNode(document.createElement("wbr"));
const cloneEditorElement = document.createElement("pre");
cloneEditorElement.innerHTML = vditor.wysiwyg.element.innerHTML;
addP2Li(cloneEditorElement);
this.undoStack[0][0].diffs[0][1] = vditor.lute.SpinVditorDOM(cloneEditorElement.innerHTML);
this.lastText = this.undoStack[0][0].diffs[0][1];
vditor.wysiwyg.element.querySelector("wbr").remove();
setRangeByWbr(vditor.wysiwyg.element, range);
}
}

public addToUndoStack(vditor: IVditor) {
// wysiwyg/afterRenderEvent.ts 已经 debounce
const range = getSelection().getRangeAt(0).cloneRange()
if (getSelection().rangeCount !== 0 && !vditor.wysiwyg.element.querySelector("wbr") &&
vditor.wysiwyg.element.contains(getSelection().getRangeAt(0).startContainer)) {
getSelection().getRangeAt(0).insertNode(document.createElement("wbr"));
vditor.wysiwyg.element.contains(range.startContainer)) {
range.insertNode(document.createElement("wbr"));
}
const cloneEditorElement = document.createElement("pre");
cloneEditorElement.innerHTML = vditor.wysiwyg.element.innerHTML;
addP2Li(cloneEditorElement);
const text = vditor.lute.SpinVditorDOM(cloneEditorElement.innerHTML);
if (vditor.wysiwyg.element.querySelector("wbr")) {
vditor.wysiwyg.element.querySelector("wbr").remove();
}
setRangeByWbr(vditor.wysiwyg.element, range);
const diff = this.dmp.diff_main(text, this.lastText, true);
const patchList = this.dmp.patch_make(text, this.lastText, diff);
if (patchList.length === 0) {
Expand Down

0 comments on commit 2887084

Please sign in to comment.