Skip to content

Commit

Permalink
🎨 fix #146
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Feb 22, 2020
1 parent a7fca54 commit a465ccb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
* [153](https://github.com/Vanessa219/vditor/issues/153) Heading toolbar is not working `修复缺陷`
* [150](https://github.com/Vanessa219/vditor/issues/150) [suggestion] deleting heading with backspace `改进功能`
* [148](https://github.com/Vanessa219/vditor/issues/148) 任务列表退格删除问题 `修复缺陷`
* [146](https://github.com/Vanessa219/vditor/issues/146) [suggestion] ctrl+k `改进功能`
* [145](https://github.com/Vanessa219/vditor/issues/145) [suggestion] ctrl+shift+j toggle checked `改进功能`
* [144](https://github.com/Vanessa219/vditor/issues/144) ctrl+shift+. 插入 blockquote `改进功能`
* [143](https://github.com/Vanessa219/vditor/issues/143) [suggestion] ctrl+m `改进功能`
Expand Down
23 changes: 23 additions & 0 deletions src/ts/wysiwyg/highlightToolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,20 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
aElement.setAttribute("title", input2.value);
};

const hotkey = (event: KeyboardEvent, nextInputElement: HTMLInputElement) => {
if (event.key === "Tab") {
nextInputElement.focus();
nextInputElement.select();
event.preventDefault();
}
if (event.altKey && event.key === "Enter") {
const range = aElement.ownerDocument.createRange()
range.selectNode(aElement.firstChild);
setSelectionFocus(range);
event.preventDefault();
}
}

const inputWrap = document.createElement("span");
inputWrap.setAttribute("aria-label", i18n[vditor.options.lang].textIsNotEmpty);
inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
Expand All @@ -595,6 +609,9 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
input.oninput = () => {
updateA();
};
input.onkeydown = (event) => {
hotkey(event, input1);
}

const input1Wrap = document.createElement("span");
input1Wrap.setAttribute("aria-label", i18n[vditor.options.lang].link);
Expand All @@ -608,6 +625,9 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
input1.oninput = () => {
updateA();
};
input1.onkeydown = (event) => {
hotkey(event, input2);
}

const input2Wrap = document.createElement("span");
input2Wrap.setAttribute("aria-label", i18n[vditor.options.lang].tooltipText);
Expand All @@ -622,6 +642,9 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
input2.oninput = () => {
updateA();
};
input2.onkeydown = (event) => {
hotkey(event, input);
}

vditor.wysiwyg.popover.insertAdjacentElement("beforeend", inputWrap);
vditor.wysiwyg.popover.insertAdjacentElement("beforeend", input1Wrap);
Expand Down
9 changes: 9 additions & 0 deletions src/ts/wysiwyg/processKeydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,15 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {
}
}

if (event.altKey && event.key === "Enter" && !isCtrl(event) && !event.shiftKey) {
const aElement = hasClosestByTag(startContainer, "A");
if (aElement) {
const inputElement = vditor.wysiwyg.popover.querySelector("input");
inputElement.focus();
inputElement.select();
}
}

// 删除有子工具栏的块
if (processKeymap("⌘-⇧-x", event, () => {
const itemElement: HTMLElement = vditor.wysiwyg.popover.querySelector('[data-type="remove"]');
Expand Down

0 comments on commit a465ccb

Please sign in to comment.