Skip to content

Commit

Permalink
🐛 fix Vanessa219#211
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 authored and stevapple committed Apr 8, 2020
1 parent e75fe35 commit 75b0b82
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

### v3.0.7 / 2020-03-xx

* [211](https://github.com/Vanessa219/vditor/issues/211) Heading when backspace (Windows Firefox) `修复缺陷`
* [239](https://github.com/Vanessa219/vditor/issues/239) be converted after spaces in FF `修复缺陷`

### v3.0.6 / 2020-03-27
Expand Down
13 changes: 8 additions & 5 deletions src/ts/ir/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {uploadFiles} from "../upload";
import {setHeaders} from "../upload/setHeaders";
import {isCtrl} from "../util/compatibility";
import {isCtrl, isFirefox} from "../util/compatibility";
import {focusEvent, hotkeyEvent, scrollCenter, selectEvent} from "../util/editorCommenEvent";
import {hasClosestByClassName, hasClosestByMatchTag} from "../util/hasClosest";
import {processPasteCode} from "../util/processPasteCode";
Expand Down Expand Up @@ -237,8 +237,12 @@ class IR {
vditor.ir.element.innerHTML = "";
return;
}

const range = getSelection().getRangeAt(0);
if (event.key === "Backspace") {
// firefox headings https://github.com/Vanessa219/vditor/issues/211
if (isFirefox() && range.startContainer.textContent === "\n" && range.startOffset === 1) {
range.startContainer.textContent = "";
}
// 数学公式前是空块,空块前是 table,在空块前删除,数学公式会多一个 br
this.element.querySelectorAll(".language-math").forEach((item) => {
const brElement = item.querySelector("br");
Expand All @@ -248,11 +252,10 @@ class IR {
});
}

if (event.key.indexOf("Arrow") > -1) {
expandMarker(getSelection().getRangeAt(0), vditor);
if (event.key.indexOf("Arrow") > -1 || event.key === "Backspace") {
expandMarker(range, vditor);
}

const range = getSelection().getRangeAt(0);
const previewRenderElement = hasClosestByClassName(range.startContainer, "vditor-ir__preview");

if (previewRenderElement) {
Expand Down
6 changes: 3 additions & 3 deletions src/ts/util/fixBrowserBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {processAfterRender} from "../ir/process";
import {afterRenderEvent} from "../wysiwyg/afterRenderEvent";
import {highlightToolbar} from "../wysiwyg/highlightToolbar";
import {processCodeRender} from "../wysiwyg/processCodeRender";
import {isCtrl, isFirefox} from "./compatibility";
import {isCtrl} from "./compatibility";
import {scrollCenter} from "./editorCommenEvent";
import {
getTopList,
Expand Down Expand Up @@ -934,9 +934,9 @@ export const fixDelete = (vditor: IVditor, range: Range, event: KeyboardEvent, p
event.preventDefault();
return true;
}
// firefox table 后删除 https://github.com/Vanessa219/vditor/issues/243
// table 后删除 https://github.com/Vanessa219/vditor/issues/243
const tableElement = pElement.previousElementSibling;
if (event.key === "Backspace" && isFirefox() && tableElement.tagName === "TABLE" &&
if (event.key === "Backspace" && tableElement.tagName === "TABLE" &&
getSelectPosition(pElement, range).start === 0) {
const lastCellElement = tableElement.lastElementChild.lastElementChild.lastElementChild;
lastCellElement.innerHTML = lastCellElement.innerHTML.trimLeft() + "<wbr>" + pElement.textContent.trim();
Expand Down
17 changes: 15 additions & 2 deletions src/ts/wysiwyg/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import {uploadFiles} from "../upload";
import {setHeaders} from "../upload/setHeaders";
import {isCtrl} from "../util/compatibility";
import {isCtrl, isFirefox} from "../util/compatibility";
import {focusEvent, hotkeyEvent, selectEvent} from "../util/editorCommenEvent";
import {isHeadingMD, isHrMD, renderToc} from "../util/fixBrowserBehavior";
import {
hasClosestBlock, hasClosestByAttribute,
hasClosestByClassName, hasClosestByMatchTag,
} from "../util/hasClosest";
import {processPasteCode} from "../util/processPasteCode";
import {getSelectPosition, insertHTML, setRangeByWbr, setSelectionByPosition, setSelectionFocus} from "../util/selection";
import {
getSelectPosition,
insertHTML,
setRangeByWbr,
setSelectionByPosition,
setSelectionFocus
} from "../util/selection";
import {afterRenderEvent} from "./afterRenderEvent";
import {highlightToolbar} from "./highlightToolbar";
import {getRenderElementNextNode, modifyPre} from "./inlineTag";
Expand Down Expand Up @@ -335,6 +341,13 @@ class WYSIWYG {

const range = getSelection().getRangeAt(0);

if (event.key === "Backspace") {
// firefox headings https://github.com/Vanessa219/vditor/issues/211
if (isFirefox() && range.startContainer.textContent === "\n" && range.startOffset === 1) {
range.startContainer.textContent = "";
}
}

// 没有被块元素包裹
modifyPre(vditor, range);

Expand Down

0 comments on commit 75b0b82

Please sign in to comment.