From ca9aa228f1999540063063e6cb86a7baeba9da93 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 24 Oct 2017 19:22:20 +0100 Subject: Move FindMode exit functions into FindMode --- content_scripts/mode_find.coffee | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'content_scripts/mode_find.coffee') diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index 5238ab34..8dc3bdcc 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -79,7 +79,7 @@ class FindMode extends Mode exit: (event) -> super() - handleEscapeForFindMode() if event + FindMode.handleEscape() if event restoreSelection: -> range = @initialRange @@ -201,6 +201,24 @@ class FindMode extends Mode @restoreDefaultSelectionHighlight: forTrusted -> document.body.classList.remove("vimiumFindMode") + # The user has found what they're looking for and is finished searching. We enter insert mode, if possible. + @handleEscape: -> + document.body.classList.remove("vimiumFindMode") + # Removing the class does not re-color existing selections. we recreate the current selection so it reverts + # back to the default color. + selection = window.getSelection() + unless selection.isCollapsed + range = window.getSelection().getRangeAt(0) + window.getSelection().removeAllRanges() + window.getSelection().addRange(range) + focusFoundLink() || selectFoundInputElement() + + # Save the query so the user can do further searches with it. + @handleEnter: -> + focusFoundLink() + document.body.classList.add("vimiumFindMode") + FindMode.saveQuery() + checkReturnToViewPort: -> window.scrollTo @scrollX, @scrollY if @options.returnToViewport -- cgit v1.2.3 From d330ebd648914802453fa1e818ef9dc52de739c8 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 24 Oct 2017 19:25:53 +0100 Subject: Move findAndFocus into FindMode, rename to findNext --- content_scripts/mode_find.coffee | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'content_scripts/mode_find.coffee') diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index 8dc3bdcc..d361d4be 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -219,6 +219,16 @@ class FindMode extends Mode document.body.classList.add("vimiumFindMode") FindMode.saveQuery() + @findNext: (backwards) -> + Marks.setPreviousPosition() + FindMode.query.hasResults = FindMode.execute null, {backwards} + + if FindMode.query.hasResults + focusFoundLink() + new PostFindMode() + else + HUD.showForDuration("No matches for '#{FindMode.query.rawQuery}'", 1000) + checkReturnToViewPort: -> window.scrollTo @scrollX, @scrollY if @options.returnToViewport -- cgit v1.2.3 From 0b9287696825cb7df2301d97a54c7666d9094521 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Sun, 29 Oct 2017 10:18:42 +0000 Subject: Move focusFoundLink into mode_find, don't expose it as global --- content_scripts/mode_find.coffee | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'content_scripts/mode_find.coffee') diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index d361d4be..e02f61c9 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -243,6 +243,18 @@ getCurrentRange = -> selection.collapseToStart() if selection.type == "Range" selection.getRangeAt 0 +getLinkFromSelection = -> + node = window.getSelection().anchorNode + while (node && node != document.body) + return node if (node.nodeName.toLowerCase() == "a") + node = node.parentNode + null + +focusFoundLink = -> + if (FindMode.query.hasResults) + link = getLinkFromSelection() + link.focus() if link + root = exports ? (window.root ?= {}) root.PostFindMode = PostFindMode root.FindMode = FindMode -- cgit v1.2.3 From a00bb7d2172803bc04b3543b31345879cb434b27 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Sun, 29 Oct 2017 10:22:17 +0000 Subject: Move selectFoundInputElement into mode_find --- content_scripts/mode_find.coffee | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'content_scripts/mode_find.coffee') diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index e02f61c9..b6c80cec 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -255,6 +255,16 @@ focusFoundLink = -> link = getLinkFromSelection() link.focus() if link +selectFoundInputElement = -> + # Since the last focused element might not be the one currently pointed to by find (e.g. the current one + # might be disabled and therefore unable to receive focus), we use the approximate heuristic of checking + # that the last anchor node is an ancestor of our element. + findModeAnchorNode = document.getSelection().anchorNode + if (FindMode.query.hasResults && document.activeElement && + DomUtils.isSelectable(document.activeElement) && + DomUtils.isDOMDescendant(findModeAnchorNode, document.activeElement)) + DomUtils.simulateSelect(document.activeElement) + root = exports ? (window.root ?= {}) root.PostFindMode = PostFindMode root.FindMode = FindMode -- cgit v1.2.3