From e7b78e9b0898c2c57bccde15d54c70c6a9cc6b74 Mon Sep 17 00:00:00 2001 From: Fangzhou Li Date: Mon, 29 Apr 2019 10:32:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=8D=E8=83=BD=E7=94=A8?= =?UTF-8?q?=20Enter=20=E9=94=AE=E8=A7=A6=E5=8F=91=E3=80=8C=E5=8F=91?= =?UTF-8?q?=E9=80=81=E3=80=8D=E6=8C=89=E9=92=AE=E6=8F=90=E4=BA=A4=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E7=9A=84=E9=97=AE=E9=A2=98=20(#66)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keyboard-shortcuts/script(page).js | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/features/keyboard-shortcuts/script(page).js b/src/features/keyboard-shortcuts/script(page).js index 3a6e157..61b26eb 100644 --- a/src/features/keyboard-shortcuts/script(page).js +++ b/src/features/keyboard-shortcuts/script(page).js @@ -24,30 +24,35 @@ export default context => { for (const [ hotkeyOpts, handler ] of hotkeyHandlers) { if (isHotkey(event, hotkeyOpts)) { - event.preventDefault() - handler() + handler(event) break } } } - function goPrevPage() { + function goPrevPage(event) { const prevPageButton = ( getPagerButtonsByText('上一页') || getPhotoPagerButtonByText('上一张') ) - if (prevPageButton) prevPageButton.click() + if (prevPageButton) { + event.preventDefault() + prevPageButton.click() + } } - function goNextPage() { + function goNextPage(event) { const nextPageButton = ( getPagerButtonsByText('下一页') || getPhotoPagerButtonByText('下一张') ) - if (nextPageButton) nextPageButton.click() + if (nextPageButton) { + event.preventDefault() + nextPageButton.click() + } } function getPagerButtonsByText(text) { @@ -66,10 +71,14 @@ export default context => { } } - function focusTextarea() { + function focusTextarea(event) { + const form = select('#phupdate form') const textarea = select('#phupdate textarea') + const isTriggeredOutsideTheForm = form && !form.contains(event.target) + const isTextareaVisible = textarea && isElementInViewport(textarea) - if (textarea && isElementInViewport(textarea)) { + if (isTriggeredOutsideTheForm && isTextareaVisible) { + event.preventDefault() textarea.focus() } }