From a465ccb0ed2d02fc3246981c4205a12654293ca5 Mon Sep 17 00:00:00 2001 From: Van Date: Sat, 22 Feb 2020 19:47:09 +0800 Subject: [PATCH] :art: fix #146 --- CHANGELOG.md | 1 + src/ts/wysiwyg/highlightToolbar.ts | 23 +++++++++++++++++++++++ src/ts/wysiwyg/processKeydown.ts | 9 +++++++++ 3 files changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index da5fd347c..21dc30f63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `改进功能` diff --git a/src/ts/wysiwyg/highlightToolbar.ts b/src/ts/wysiwyg/highlightToolbar.ts index 389d8c168..19970249f 100644 --- a/src/ts/wysiwyg/highlightToolbar.ts +++ b/src/ts/wysiwyg/highlightToolbar.ts @@ -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"; @@ -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); @@ -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); @@ -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); diff --git a/src/ts/wysiwyg/processKeydown.ts b/src/ts/wysiwyg/processKeydown.ts index 17fce2096..9427b0d04 100644 --- a/src/ts/wysiwyg/processKeydown.ts +++ b/src/ts/wysiwyg/processKeydown.ts @@ -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"]');