From 291e7fd67de9e1c4bd0bc5048ab7344424f19b30 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 3 Jun 2015 15:27:45 +0100 Subject: Re-implement Marks, incl `` binding. --- content_scripts/vimium_frontend.coffee | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 7ad75514..9ff9b6db 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -241,9 +241,10 @@ unregisterFrame = -> tab_is_closing: DomUtils.isTopFrame() executePageCommand = (request) -> + commandType = request.command.split(".")[0] # Vomnibar commands are handled in the tab's main/top frame. They are handled even if Vimium is otherwise # disabled in the frame. - if request.command.split(".")[0] == "Vomnibar" + if commandType == "Vomnibar" if DomUtils.isTopFrame() # We pass the frameId from request. That's the frame which originated the request, so that's the frame # which should receive the focus when the vomnibar closes. @@ -254,7 +255,9 @@ executePageCommand = (request) -> # All other commands are handled in their frame (but only if Vimium is enabled). return unless frameId == request.frameId and isEnabledForUrl - if request.registryEntry.passCountToFunction + if commandType == "Marks" + Utils.invokeCommandString request.command, [request.registryEntry] + else if request.registryEntry.passCountToFunction Utils.invokeCommandString(request.command, [request.count]) else Utils.invokeCommandString(request.command) for i in [0...request.count] @@ -299,8 +302,12 @@ window.focusThisFrame = do -> setTimeout (-> highlightedFrameElement.remove()), 200 extend window, - scrollToBottom: -> Scroller.scrollTo "y", "max" - scrollToTop: -> Scroller.scrollTo "y", 0 + scrollToBottom: -> + Marks.markPosition() + Scroller.scrollTo "y", "max" + scrollToTop: -> + Marks.markPosition() + Scroller.scrollTo "y", 0 scrollToLeft: -> Scroller.scrollTo "x", 0 scrollToRight: -> Scroller.scrollTo "x", "max" scrollUp: -> Scroller.scrollBy "y", -1 * Settings.get("scrollStepSize") @@ -861,6 +868,7 @@ window.getFindModeQuery = (backwards) -> findModeQuery.parsedQuery findAndFocus = (backwards) -> + Marks.markPosition() query = getFindModeQuery backwards findModeQueryHasResults = @@ -1007,6 +1015,7 @@ findModeRestoreSelection = (range = findModeInitialRange) -> # Enters find mode. Returns the new find-mode instance. window.enterFindMode = (options = {}) -> + Marks.markPosition() # Save the selection, so performFindInPlace can restore it. findModeSaveSelection() findModeQuery = rawQuery: "" -- cgit v1.2.3 From 8dab334fa2fde9d4815ce0a12c0d2ab9dd44ff05 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 3 Jun 2015 16:15:31 +0100 Subject: Also set previous position for before global mark movement. --- content_scripts/vimium_frontend.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 9ff9b6db..fec0dae2 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -266,7 +266,9 @@ executePageCommand = (request) -> setScrollPosition = (scrollX, scrollY) -> if (scrollX > 0 || scrollY > 0) - DomUtils.documentReady(-> window.scrollTo(scrollX, scrollY)) + DomUtils.documentReady -> + Marks.markPosition() + window.scrollTo scrollX, scrollY # # Called from the backend in order to change frame focus. -- cgit v1.2.3 From e005d3e5b7a06a949138109b2c57555f9a5db2b9 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 3 Jun 2015 18:39:03 +0100 Subject: Refactor (to setPreviousPosition) to clarify Marks logic. --- content_scripts/vimium_frontend.coffee | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index fec0dae2..f644ea35 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -267,7 +267,7 @@ executePageCommand = (request) -> setScrollPosition = (scrollX, scrollY) -> if (scrollX > 0 || scrollY > 0) DomUtils.documentReady -> - Marks.markPosition() + Marks.setPreviousPosition() window.scrollTo scrollX, scrollY # @@ -305,10 +305,10 @@ window.focusThisFrame = do -> extend window, scrollToBottom: -> - Marks.markPosition() + Marks.setPreviousPosition() Scroller.scrollTo "y", "max" scrollToTop: -> - Marks.markPosition() + Marks.setPreviousPosition() Scroller.scrollTo "y", 0 scrollToLeft: -> Scroller.scrollTo "x", 0 scrollToRight: -> Scroller.scrollTo "x", "max" @@ -870,7 +870,7 @@ window.getFindModeQuery = (backwards) -> findModeQuery.parsedQuery findAndFocus = (backwards) -> - Marks.markPosition() + Marks.setPreviousPosition() query = getFindModeQuery backwards findModeQueryHasResults = @@ -1017,7 +1017,7 @@ findModeRestoreSelection = (range = findModeInitialRange) -> # Enters find mode. Returns the new find-mode instance. window.enterFindMode = (options = {}) -> - Marks.markPosition() + Marks.setPreviousPosition() # Save the selection, so performFindInPlace can restore it. findModeSaveSelection() findModeQuery = rawQuery: "" -- cgit v1.2.3 From bc4f3ecac81fd8f174b8c3ad92a0998ada8f7992 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 4 Jun 2015 15:14:10 +0100 Subject: Global marks; focus and only scroll in the main frame. --- content_scripts/vimium_frontend.coffee | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index f644ea35..dc083e6c 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -147,7 +147,7 @@ initializePreDomReady = -> focusFrame: (request) -> if (frameId == request.frameId) then focusThisFrame request refreshCompletionKeys: refreshCompletionKeys getScrollPosition: -> scrollX: window.scrollX, scrollY: window.scrollY - setScrollPosition: (request) -> setScrollPosition request.scrollX, request.scrollY + setScrollPosition: setScrollPosition executePageCommand: executePageCommand currentKeyQueue: (request) -> keyQueue = request.keyQueue @@ -264,11 +264,15 @@ executePageCommand = (request) -> refreshCompletionKeys(request) -setScrollPosition = (scrollX, scrollY) -> - if (scrollX > 0 || scrollY > 0) - DomUtils.documentReady -> - Marks.setPreviousPosition() - window.scrollTo scrollX, scrollY +# Set the scroll position (but only in the main frame). Some pages (like Facebook) get confused if you set +# the scroll position in all frames. +setScrollPosition = ({ scrollX, scrollY }) -> + if DomUtils.isTopFrame() + if scrollX > 0 or scrollY > 0 + DomUtils.documentReady -> + window.focus() + Marks.setPreviousPosition() + window.scrollTo scrollX, scrollY # # Called from the backend in order to change frame focus. -- cgit v1.2.3 From 9600d258cbadd80568e37637974172e7755ca28c Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 4 Jun 2015 16:07:57 +0100 Subject: Global marks; only handle messages in main frame. On sites with several frames (e.g. Facebook), if we allow all of the frames to handle the setScrollPosition and showHudForDuration messages, then the focus ends up in an arbitrary frame. And, on Facebook, say, Vimium ends up broken until the focus is returned to the main frame. So, we only handle these messages in the main frame. --- content_scripts/vimium_frontend.coffee | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index dc083e6c..033bb2b3 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -142,7 +142,7 @@ initializePreDomReady = -> window.removeEventListener "focus", onFocus requestHandlers = - showHUDforDuration: (request) -> HUD.showForDuration request.text, request.duration + showHUDforDuration: handleShowHUDforDuration toggleHelpDialog: (request) -> toggleHelpDialog(request.dialogHtml, request.frameId) focusFrame: (request) -> if (frameId == request.frameId) then focusThisFrame request refreshCompletionKeys: refreshCompletionKeys @@ -264,13 +264,16 @@ executePageCommand = (request) -> refreshCompletionKeys(request) -# Set the scroll position (but only in the main frame). Some pages (like Facebook) get confused if you set -# the scroll position in all frames. +handleShowHUDforDuration = ({ text, duration }) -> + if DomUtils.isTopFrame() + DomUtils.documentReady -> HUD.showForDuration text, duration + setScrollPosition = ({ scrollX, scrollY }) -> if DomUtils.isTopFrame() - if scrollX > 0 or scrollY > 0 - DomUtils.documentReady -> - window.focus() + DomUtils.documentReady -> + window.focus() + document.body.focus() + if 0 < scrollX or 0 < scrollY Marks.setPreviousPosition() window.scrollTo scrollX, scrollY -- cgit v1.2.3 From 89c3ab075994de9b11952784eb5752da445df576 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 4 Jun 2015 16:36:00 +0100 Subject: Unwind passing key and registry entry for marks. As suggested by @mrmr1993 in #1716. --- content_scripts/vimium_frontend.coffee | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 033bb2b3..3055ecea 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -255,9 +255,7 @@ executePageCommand = (request) -> # All other commands are handled in their frame (but only if Vimium is enabled). return unless frameId == request.frameId and isEnabledForUrl - if commandType == "Marks" - Utils.invokeCommandString request.command, [request.registryEntry] - else if request.registryEntry.passCountToFunction + if request.registryEntry.passCountToFunction Utils.invokeCommandString(request.command, [request.count]) else Utils.invokeCommandString(request.command) for i in [0...request.count] -- cgit v1.2.3