From 1d961d5dacb71638690d06e91866d121e43edf9c Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 4 Feb 2018 09:37:46 +0000 Subject: Handle on keypress (not keydown) in Vomnibar and HUD. Proposing this as a simpler alternative to #2934. Additionally, this puts the logic for fixing #2915 in a single place. Credit to @regmarmcem for figuring out the source of #2915. Mention @regmarmcem. Fixes #2915. Replaces #2934. --- pages/hud.coffee | 10 +++++++++- pages/vomnibar.coffee | 9 +++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'pages') diff --git a/pages/hud.coffee b/pages/hud.coffee index 5ff2e07e..332db0e4 100644 --- a/pages/hud.coffee +++ b/pages/hud.coffee @@ -15,7 +15,12 @@ setTextInInputElement = (inputElement, text) -> document.addEventListener "DOMContentLoaded", -> DomUtils.injectUserCss() # Manually inject custom user styles. -document.addEventListener "keydown", (event) -> +onKeyEvent = (event) -> + # Handle on "keypress", and other events on "keydown"; this avoids interence with CJK translation + # (see #2915 and #2934). + return null if event.type == "keypress" and event.key != "Enter" + return null if event.type == "keydown" and event.key == "Enter" + inputElement = document.getElementById "hud-find-input" return unless inputElement? # Don't do anything if we're not in find mode. @@ -44,6 +49,9 @@ document.addEventListener "keydown", (event) -> DomUtils.suppressEvent event false +document.addEventListener "keydown", onKeyEvent +document.addEventListener "keypress", onKeyEvent + handlers = show: (data) -> document.getElementById("hud").innerText = data.text diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee index ec5f818f..c53e7170 100644 --- a/pages/vomnibar.coffee +++ b/pages/vomnibar.coffee @@ -104,6 +104,10 @@ class VomnibarUI # arrow keys and various other shortcuts, and this function hides the event-decoding complexity. actionFromKeyEvent: (event) -> key = KeyboardUtils.getKeyChar(event) + # Handle on "keypress", and other events on "keydown"; this avoids interence with CJK translation + # (see #2915 and #2934). + return null if event.type == "keypress" and key != "enter" + return null if event.type == "keydown" and key == "enter" if (KeyboardUtils.isEscape(event)) return "dismiss" else if (key == "up" || @@ -122,7 +126,7 @@ class VomnibarUI null - onKeydown: (event) => + onKeyEvent: (event) => @lastAction = action = @actionFromKeyEvent event return true unless action # pass through @@ -250,7 +254,8 @@ class VomnibarUI @input = @box.querySelector("input") @input.addEventListener "input", @onInput - @input.addEventListener "keydown", @onKeydown + @input.addEventListener "keydown", @onKeyEvent + @input.addEventListener "keypress", @onKeyEvent @completionList = @box.querySelector("ul") @completionList.style.display = "" -- cgit v1.2.3