diff options
| author | Stephen Blott | 2018-02-04 09:37:46 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2018-02-04 15:17:39 +0000 | 
| commit | 1d961d5dacb71638690d06e91866d121e43edf9c (patch) | |
| tree | 66f597a905bd685be35084c8f7e6a848b50f118c /pages | |
| parent | aa1e81193140586bc64e4c8ef68210486e95c2fc (diff) | |
| download | vimium-1d961d5dacb71638690d06e91866d121e43edf9c.tar.bz2 | |
Handle <Enter> 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.
Diffstat (limited to 'pages')
| -rw-r--r-- | pages/hud.coffee | 10 | ||||
| -rw-r--r-- | pages/vomnibar.coffee | 9 | 
2 files changed, 16 insertions, 3 deletions
| 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 <Enter> 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 <Enter> 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 = "" | 
