aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/marks.coffee18
-rw-r--r--content_scripts/marks.coffee7
2 files changed, 20 insertions, 5 deletions
diff --git a/background_scripts/marks.coffee b/background_scripts/marks.coffee
index 3a5af130..6e5f08ba 100644
--- a/background_scripts/marks.coffee
+++ b/background_scripts/marks.coffee
@@ -11,15 +11,27 @@ Marks =
# tabId can be considered valid.
create: (req, sender) ->
chrome.storage.local.get "vimiumSecret", (items) =>
- item = {}
- item[@getLocationKey req.markName] =
+ markInfo =
vimiumSecret: items.vimiumSecret
markName: req.markName
url: @getBaseUrl sender.tab.url
tabId: sender.tab.id
scrollX: req.scrollX
scrollY: req.scrollY
- chrome.storage.sync.set item
+
+ if markInfo.scrollX? and markInfo.scrollY?
+ @saveMark markInfo
+ else
+ # The front-end frame hasn't provided the scroll position (because it's not the top frame within its
+ # tab). We need to ask the top frame what its scroll position is. (With the frame Id set to 0, below,
+ # the request will only be handled by the top frame within the tab.)
+ chrome.tabs.sendMessage sender.tab.id, name: "getScrollPosition", frameId: 0, (response) =>
+ @saveMark extend markInfo, scrollX: response.scrollX, scrollY: response.scrollY
+
+ saveMark: (markInfo) ->
+ item = {}
+ item[@getLocationKey markInfo.markName] = markInfo
+ chrome.storage.sync.set item
# Goto a global mark. We try to find the original tab. If we can't find that, then we try to find another
# tab with the original URL, and use that. And if we can't find such an existing tab, then we create a new
diff --git a/content_scripts/marks.coffee b/content_scripts/marks.coffee
index 3b5814da..f569e1ea 100644
--- a/content_scripts/marks.coffee
+++ b/content_scripts/marks.coffee
@@ -36,11 +36,14 @@ Marks =
# characters.
@exit =>
if event.shiftKey
+ # We record the current scroll position, but only if this is the top frame within the tab.
+ # Otherwise, we'll fetch the scroll position of the top frame from the background page later.
+ [ scrollX, scrollY ] = [ window.scrollX, window.scrollY ] if DomUtils.isTopFrame()
chrome.runtime.sendMessage
handler: 'createMark'
markName: keyChar
- scrollX: window.scrollX
- scrollY: window.scrollY
+ scrollX: scrollX
+ scrollY: scrollY
, => @showMessage "Created global mark", keyChar
else
localStorage[@getLocationKey keyChar] = @getMarkString()