diff options
| -rw-r--r-- | content_scripts/mode_visual_edit.coffee | 4 | ||||
| -rw-r--r-- | lib/dom_utils.coffee | 19 |
2 files changed, 14 insertions, 9 deletions
diff --git a/content_scripts/mode_visual_edit.coffee b/content_scripts/mode_visual_edit.coffee index 9e597cca..8bcde6cb 100644 --- a/content_scripts/mode_visual_edit.coffee +++ b/content_scripts/mode_visual_edit.coffee @@ -554,6 +554,10 @@ class VisualMode extends Movement if document.activeElement and DomUtils.isEditable document.activeElement document.activeElement.blur() unless event?.type == "click" + if @options.parentMode + # E.g. when exiting visual mode under edit mode, we no longer want the selection. + @collapseSelectionToFocus() + super event, target if @yankedText? unless @options.noCopyToClipboard diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index ee7d415f..027188bf 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -223,15 +223,16 @@ DomUtils = handlerStack.bubbleEvent "click", target: element else element.focus() - # If the cursor is at the start of the element's contents, send it to the end. Motivation: - # * the end is a more useful place to focus than the start, - # * this way preserves the last used position (except when it's at the beginning), so the user can - # 'resume where they left off'. - # NOTE(mrmr1993): Some elements throw an error when we try to access their selection properties, so - # wrap this with a try. - try - if element.selectionStart == 0 and element.selectionEnd == 0 - element.setSelectionRange element.value.length, element.value.length + if element.tagName.toLowerCase() != "textarea" + # If the cursor is at the start of the (non-textarea) element's contents, send it to the end. Motivation: + # * the end is a more useful place to focus than the start, + # * this way preserves the last used position (except when it's at the beginning), so the user can + # 'resume where they left off'. + # NOTE(mrmr1993): Some elements throw an error when we try to access their selection properties, so + # wrap this with a try. + try + if element.selectionStart == 0 and element.selectionEnd == 0 + element.setSelectionRange element.value.length, element.value.length |
