diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f4645738..a9196c20f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,8 +53,9 @@ * [241](https://github.com/Vanessa219/vditor/issues/241) When editing the heading, not converted using the cursor key `修复缺陷` * [242](https://github.com/Vanessa219/vditor/issues/242) combined lists "+" and "-" `修复缺陷` -* [248](https://github.com/Vanessa219/vditor/issues/248) enter after heading `修复缺陷` +* [243](https://github.com/Vanessa219/vditor/issues/243) can not delete the table with "backspace" `修复缺陷` * [246](https://github.com/Vanessa219/vditor/issues/246) 报错index.min.js:27 `修复缺陷` +* [248](https://github.com/Vanessa219/vditor/issues/248) enter after heading `修复缺陷` ### v3.0.5 / 2020-03-26 diff --git a/src/ts/ir/processKeydown.ts b/src/ts/ir/processKeydown.ts index 5bce52364..9c6c4d1fc 100644 --- a/src/ts/ir/processKeydown.ts +++ b/src/ts/ir/processKeydown.ts @@ -1,7 +1,16 @@ import {Constants} from "../constants"; import {isCtrl} from "../util/compatibility"; import {scrollCenter} from "../util/editorCommenEvent"; -import {fixBlockquote, fixCodeBlock, fixList, fixMarkdown, fixTab, fixTable, fixTask} from "../util/fixBrowserBehavior"; +import { + fixBlockquote, + fixCodeBlock, + fixDelete, + fixList, + fixMarkdown, + fixTab, + fixTable, + fixTask, +} from "../util/fixBrowserBehavior"; import {hasClosestByAttribute, hasClosestByClassName, hasClosestByMatchTag} from "../util/hasClosest"; import {getSelectPosition, setRangeByWbr} from "../util/selection"; @@ -132,6 +141,12 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => { return true; } + if (event.key === "Backspace" && !isCtrl(event) && !event.shiftKey && !event.altKey && range.toString() === "") { + if (fixDelete(range, event)) { + return true; + } + } + if (event.key === "Enter") { scrollCenter(vditor.ir.element); } diff --git a/src/ts/util/fixBrowserBehavior.ts b/src/ts/util/fixBrowserBehavior.ts index 289344fde..fbeadc9fd 100644 --- a/src/ts/util/fixBrowserBehavior.ts +++ b/src/ts/util/fixBrowserBehavior.ts @@ -36,6 +36,7 @@ const goPreviousCell = (cellElement: HTMLElement, range: Range, isSelected = tru range.collapse(false); } } + return previousElement }; export const listToggle = (vditor: IVditor, range: Range, type: string, cancel = true) => { @@ -455,14 +456,6 @@ export const fixTable = (vditor: IVditor, event: KeyboardEvent, range: Range) => return true; } - // Backspace:光标移动到前一个 cell - if (!isCtrl(event) && !event.shiftKey && !event.altKey && event.key === "Backspace" - && range.startOffset === 0 && range.toString() === "") { - goPreviousCell(cellElement, range, false); - event.preventDefault(); - return true; - } - // tab:光标移向下一个 cell if (event.key === "Tab") { if (event.shiftKey) { @@ -532,8 +525,31 @@ export const fixTable = (vditor: IVditor, event: KeyboardEvent, range: Range) => return true; } - // 后方新添加一列 + // focus row input, only wysiwyg + if (vditor.currentMode === "wysiwyg" && + !isCtrl(event) && event.key === "Enter" && !event.shiftKey && event.altKey) { + const inputElement = (vditor.wysiwyg.popover.querySelector(".vditor-input") as HTMLInputElement); + inputElement.focus(); + inputElement.select(); + event.preventDefault(); + return true; + } + + // Backspace:光标移动到前一个 cell const tableElement = cellElement.parentElement.parentElement.parentElement as HTMLTableElement; + if (!isCtrl(event) && !event.shiftKey && !event.altKey && event.key === "Backspace" + && range.startOffset === 0 && range.toString() === "") { + const previousCellElement = goPreviousCell(cellElement, range, false); + if (!previousCellElement && tableElement) { + tableElement.outerHTML = `