From 4f426affde34c895cf342dac256895ffe98ee4f3 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 13 Jun 2015 13:03:10 +0100 Subject: Refactor duplicate code. --- content_scripts/hud.coffee | 2 +- content_scripts/mode_find.coffee | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/content_scripts/hud.coffee b/content_scripts/hud.coffee index 2f4e008c..bfad71b7 100644 --- a/content_scripts/hud.coffee +++ b/content_scripts/hud.coffee @@ -57,7 +57,7 @@ HUD = @tween.fade 0, 150, => @hide true, updateIndicator hideFindMode: (data) -> - window.scrollTo @findMode.scrollX, @findMode.scrollY if @findMode.options.returnToViewport + @findMode.checkReturnToViewPort() # An element element won't receive a focus event if the search landed on it while we were in the HUD # iframe. To end up with the correct modes active, we create a focus/blur event manually after refocusing diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index 297c4158..bba457b6 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -87,7 +87,7 @@ class FindMode extends Mode findInPlace: (query) -> # If requested, restore the scroll position (so that failed searches leave the scroll position unchanged). - window.scrollTo @scrollX, @scrollY if @options.returnToViewport + @checkReturnToViewPort() FindMode.updateQuery query # Restore the selection. That way, we're always searching forward from the same place, so we find the right # match as the user adds matching characters, or removes previously-matched characters. See #1434. @@ -196,6 +196,9 @@ class FindMode extends Mode @restoreDefaultSelectionHighlight: -> document.body.classList.remove("vimiumFindMode") + checkReturnToViewPort: -> + window.scrollTo @scrollX, @scrollY if @options.returnToViewport + getCurrentRange = -> selection = getSelection() if selection.type == "None" -- cgit v1.2.3