From 1d9eb4c23f218eec87d109612980447555899894 Mon Sep 17 00:00:00 2001 From: Van Date: Thu, 5 Mar 2020 11:29:07 +0800 Subject: [PATCH] :bug: fix #199 and hotkey --- CHANGELOG.md | 2 +- src/ts/util/compatibility.ts | 10 +++++++--- src/ts/util/hotKey.ts | 4 ++-- src/ts/wysiwyg/highlightToolbar.ts | 15 +++++++++------ src/ts/wysiwyg/processKeydown.ts | 7 +++---- src/ts/wysiwyg/toolbarEvent.ts | 4 ++-- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0df6c48f6..0d35b80fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,10 +47,10 @@ ### v2.2.16 / 未发布 -* [199](https://github.com/Vanessa219/vditor/pull/199) heading at first time(windows firefox) `修复缺陷` ### v2.2.15 / 2020-03-04 +* [199](https://github.com/Vanessa219/vditor/pull/199) heading at first time(windows firefox) `修复缺陷` * [202](https://github.com/Vanessa219/vditor/pull/202) 第一次进入代码块后 ctrl+a 无作用 `修复缺陷` * [201](https://github.com/Vanessa219/vditor/pull/201) table (windows firefox) `修复缺陷` * [200](https://github.com/Vanessa219/vditor/pull/200) copy in wysiwyg bug `修复缺陷` diff --git a/src/ts/util/compatibility.ts b/src/ts/util/compatibility.ts index 9492952f6..c38ccf096 100644 --- a/src/ts/util/compatibility.ts +++ b/src/ts/util/compatibility.ts @@ -46,10 +46,14 @@ export const updateHotkeyTip = (hotkey: string) => { hotkey = hotkey.replace("ctrl", "⌘").replace("shift", "⇧") .replace("alt", "⌥"); if (hotkey.indexOf("⇧") > -1) { - hotkey = hotkey.replace(":", ";").replace("+", "=") - .replace("_", "-"); + if (!isFirefox()) { + hotkey = hotkey.replace(":", ";").replace("+", "=") + .replace("_", "-"); + } else { + // Mac Firefox 按下 shift 后,key 同 windows 系统 + hotkey = hotkey.replace(";", ":").replace("=", "+"); + } } - } else { hotkey = hotkey.replace("⌘", "ctrl").replace("⇧", "shift") .replace("⌥", "alt"); diff --git a/src/ts/util/hotKey.ts b/src/ts/util/hotKey.ts index e84cb59bd..a1f02df10 100644 --- a/src/ts/util/hotKey.ts +++ b/src/ts/util/hotKey.ts @@ -1,11 +1,11 @@ -import {isCtrl, updateHotkeyTip} from "./compatibility"; +import {isCtrl, isFirefox, updateHotkeyTip} from "./compatibility"; // 是否匹配 ⌘-⇧-[] / ⌘-[] export const matchHotKey = (hotKey: string, event: KeyboardEvent) => { const hotKeys = updateHotkeyTip(hotKey).split("-"); const hasShift = hotKeys.length > 2 && (hotKeys[1] === "shift" || hotKeys[1] === "⇧"); let key = (hasShift ? hotKeys[2] : hotKeys[1]) || "-"; - if (hasShift && key === "-" && !/Mac/.test(navigator.platform)) { + if (hasShift && key === "-" && (isFirefox() || !/Mac/.test(navigator.platform))) { key = "_"; } if (isCtrl(event) && event.key.toLowerCase() === key.toLowerCase() && !event.altKey diff --git a/src/ts/wysiwyg/highlightToolbar.ts b/src/ts/wysiwyg/highlightToolbar.ts index 8865bb134..f948bb0b5 100644 --- a/src/ts/wysiwyg/highlightToolbar.ts +++ b/src/ts/wysiwyg/highlightToolbar.ts @@ -214,9 +214,9 @@ export const highlightToolbar = (vditor: IVditor) => { if (columnDiff > 0) { for (let j = 0; j < columnDiff; j++) { if (i === 0) { - tableElement.rows[i].lastElementChild.insertAdjacentHTML("afterend", ""); + tableElement.rows[i].lastElementChild.insertAdjacentHTML("afterend", " "); } else { - tableElement.rows[i].insertCell(); + tableElement.rows[i].lastElementChild.insertAdjacentHTML("afterend", " "); } } } else { @@ -232,7 +232,7 @@ export const highlightToolbar = (vditor: IVditor) => { if (rowDiff > 0) { let rowHTML = ""; for (let m = 0; m < column; m++) { - rowHTML += ""; + rowHTML += " "; } for (let l = 0; l < rowDiff; l++) { if (tableElement.querySelector("tbody")) { @@ -300,7 +300,8 @@ export const highlightToolbar = (vditor: IVditor) => { } const left = document.createElement("button"); - left.setAttribute("aria-label", i18n[vditor.options.lang].alignLeft); + left.setAttribute("aria-label", i18n[vditor.options.lang].alignLeft + + "<" + updateHotkeyTip("⌘-⇧-L") + ">"); left.setAttribute("data-type", "left"); left.innerHTML = outdentSVG; left.className = "vditor-icon vditor-tooltipped vditor-tooltipped__n" + @@ -310,7 +311,8 @@ export const highlightToolbar = (vditor: IVditor) => { }; const center = document.createElement("button"); - center.setAttribute("aria-label", i18n[vditor.options.lang].alignCenter); + center.setAttribute("aria-label", i18n[vditor.options.lang].alignCenter + + "<" + updateHotkeyTip("⌘-⇧-C") + ">"); center.setAttribute("data-type", "center"); center.innerHTML = alignCenterSVG; center.className = "vditor-icon vditor-tooltipped vditor-tooltipped__n" + @@ -320,7 +322,8 @@ export const highlightToolbar = (vditor: IVditor) => { }; const right = document.createElement("button"); - right.setAttribute("aria-label", i18n[vditor.options.lang].alignRight); + right.setAttribute("aria-label", i18n[vditor.options.lang].alignRight + + "<" + updateHotkeyTip("⌘-⇧-R") + ">"); right.setAttribute("data-type", "right"); right.innerHTML = indentSVG; right.className = "vditor-icon vditor-tooltipped vditor-tooltipped__n" + diff --git a/src/ts/wysiwyg/processKeydown.ts b/src/ts/wysiwyg/processKeydown.ts index c82a35c74..b69a95a11 100644 --- a/src/ts/wysiwyg/processKeydown.ts +++ b/src/ts/wysiwyg/processKeydown.ts @@ -190,7 +190,7 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => { if (matchHotKey("⌘-=", event)) { let rowHTML = ""; for (let m = 0; m < cellElement.parentElement.childElementCount; m++) { - rowHTML += `${m === 0 ? "" : ""}`; + rowHTML += `${m === 0 ? " " : " "}`; } if (cellElement.tagName === "TH") { cellElement.parentElement.parentElement.insertAdjacentHTML("afterend", @@ -207,7 +207,6 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => { // 后方新添加一列 const tableElement = cellElement.parentElement.parentElement.parentElement as HTMLTableElement; - if (matchHotKey("⌘-⇧-=", event)) { let index = 0; let previousElement = cellElement.previousElementSibling; @@ -217,9 +216,9 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => { } for (let i = 0; i < tableElement.rows.length; i++) { if (i === 0) { - tableElement.rows[i].cells[index].insertAdjacentHTML("afterend", ""); + tableElement.rows[i].cells[index].insertAdjacentHTML("afterend", " "); } else { - tableElement.rows[i].cells[index].insertAdjacentHTML("afterend", ""); + tableElement.rows[i].cells[index].insertAdjacentHTML("afterend", " "); } } diff --git a/src/ts/wysiwyg/toolbarEvent.ts b/src/ts/wysiwyg/toolbarEvent.ts index 71e6317e7..e3442547c 100644 --- a/src/ts/wysiwyg/toolbarEvent.ts +++ b/src/ts/wysiwyg/toolbarEvent.ts @@ -311,8 +311,8 @@ export const toolbarEvent = (vditor: IVditor, actionBtn: Element) => { } else if (commandName === "table") { document.execCommand("insertHTML", false, "" - + "
col1col2col3
" - + "
"); + + " " + + " "); range.selectNode(vditor.wysiwyg.element.querySelector("wbr").previousSibling); vditor.wysiwyg.element.querySelector("wbr").remove(); setSelectionFocus(range);