aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content_scripts/mode_passkeys.coffee2
-rw-r--r--lib/dom_utils.coffee21
2 files changed, 14 insertions, 9 deletions
diff --git a/content_scripts/mode_passkeys.coffee b/content_scripts/mode_passkeys.coffee
index 94a7c7ec..64db5447 100644
--- a/content_scripts/mode_passkeys.coffee
+++ b/content_scripts/mode_passkeys.coffee
@@ -6,7 +6,7 @@ class PassKeysMode extends Mode
trackState: true # Maintain @enabled, @passKeys and @keyQueue.
keydown: (event) => @handleKeyChar KeyboardUtils.getKeyChar event
keypress: (event) => @handleKeyChar String.fromCharCode event.charCode
- keyup: (event) => @handleKeyChar String.fromCharCode event.charCode
+ keyup: (event) => @handleKeyChar KeyboardUtils.getKeyChar event
# Keystrokes are *never* considered passKeys if the keyQueue is not empty. So, for example, if 't' is a
# passKey, then 'gt' and '99t' will neverthless be handled by Vimium.
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index 846ed142..1d1b67ba 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -173,18 +173,23 @@ DomUtils =
node = document.getSelection()?.anchorNode
node and @isDOMDescendant element, node
else
- element.selectionStart? and element.selectionEnd? and element.selectionStart != element.selectionEnd
+ # Note. This makes the wrong decision if the user has placed the caret at the start of element. We
+ # cannot distinguish that case from the user having made no selection.
+ element.selectionStart? and element.selectionEnd? and element.selectionEnd != 0
simulateSelect: (element) ->
- # If element == document.activeElement, then we won't get a new focus event. So, we pretend (to any
- # active modes which care, e.g. PostFindMode) that element has been clicked.
+ # If element is already active, then we don't move the selection. However, we also won't get a new focus
+ # event. So, instead we pretend (to any active modes which care, e.g. PostFindMode) that element has been
+ # clicked.
if element == document.activeElement and DomUtils.isEditable document.activeElement
handlerStack.bubbleEvent "click", target: element
-
- element.focus()
- # When focusing a textbox, put the selection caret at the end of the textbox's contents.
- # For some HTML5 input types (eg. date) we can't position the caret, so we wrap this with a try.
- try element.setSelectionRange(element.value.length, element.value.length)
+ else
+ element.focus()
+ unless @isSelected element
+ # When focusing a textbox (without an existing selection), put the selection caret at the end of the
+ # textbox's contents. For some HTML5 input types (eg. date) we can't position the caret, so we wrap
+ # this with a try.
+ try element.setSelectionRange(element.value.length, element.value.length)
simulateClick: (element, modifiers) ->
modifiers ||= {}