Skip to content

Commit

Permalink
🐛 fix #199 and hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Mar 5, 2020
1 parent b8835f1 commit 4b9d6ec
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `修复缺陷`
Expand Down
10 changes: 7 additions & 3 deletions src/ts/util/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/ts/util/hotKey.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 9 additions & 6 deletions src/ts/wysiwyg/highlightToolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<th></th>");
tableElement.rows[i].lastElementChild.insertAdjacentHTML("afterend", "<th> </th>");
} else {
tableElement.rows[i].insertCell();
tableElement.rows[i].lastElementChild.insertAdjacentHTML("afterend", "<td> </td>");
}
}
} else {
Expand All @@ -232,7 +232,7 @@ export const highlightToolbar = (vditor: IVditor) => {
if (rowDiff > 0) {
let rowHTML = "<tr>";
for (let m = 0; m < column; m++) {
rowHTML += "<td></td>";
rowHTML += "<td> </td>";
}
for (let l = 0; l < rowDiff; l++) {
if (tableElement.querySelector("tbody")) {
Expand Down Expand Up @@ -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" +
Expand All @@ -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" +
Expand All @@ -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" +
Expand Down
7 changes: 3 additions & 4 deletions src/ts/wysiwyg/processKeydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 += `<td>${m === 0 ? "<wbr>" : ""}</td>`;
rowHTML += `<td>${m === 0 ? " <wbr>" : " "}</td>`;
}
if (cellElement.tagName === "TH") {
cellElement.parentElement.parentElement.insertAdjacentHTML("afterend",
Expand All @@ -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;
Expand All @@ -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", "<th></th>");
tableElement.rows[i].cells[index].insertAdjacentHTML("afterend", "<th> </th>");
} else {
tableElement.rows[i].cells[index].insertAdjacentHTML("afterend", "<td></td>");
tableElement.rows[i].cells[index].insertAdjacentHTML("afterend", "<td> </td>");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ts/wysiwyg/toolbarEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ export const toolbarEvent = (vditor: IVditor, actionBtn: Element) => {
} else if (commandName === "table") {
document.execCommand("insertHTML", false,
"<table data-block=\"0\"><thead><tr><th>col1<wbr></th><th>col2</th><th>col3</th></tr></thead>"
+ "<tbody><tr><td></td><td></td><td>"
+ "</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>");
+ "<tbody><tr><td> </td><td> </td><td> "
+ "</td></tr><tr><td> </td><td> </td><td> </td></tr></tbody></table>");
range.selectNode(vditor.wysiwyg.element.querySelector("wbr").previousSibling);
vditor.wysiwyg.element.querySelector("wbr").remove();
setSelectionFocus(range);
Expand Down

0 comments on commit 4b9d6ec

Please sign in to comment.