diff options
| author | mrmr1993 | 2014-11-23 11:53:22 +0000 |
|---|---|---|
| committer | mrmr1993 | 2014-11-23 11:57:47 +0000 |
| commit | 176ea28aecc446be0c9788e6a59677fa94c51fee (patch) | |
| tree | cf3111acc887210b1f7ab75b0302a69ece91073e | |
| parent | 70cb13bfbd39eba5f2ca06bba35ea5a69dd16fc8 (diff) | |
| download | vimium-176ea28aecc446be0c9788e6a59677fa94c51fee.tar.bz2 | |
Monitor a tab's frames as a list with the current frame at its head
| -rw-r--r-- | background_scripts/main.coffee | 51 | ||||
| -rw-r--r-- | lib/utils.coffee | 7 |
2 files changed, 25 insertions, 33 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 4dd12420..9b9d4bc2 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -284,14 +284,8 @@ BackgroundCommands = moveTabRight: (count) -> moveTab(null, count) nextFrame: (count) -> chrome.tabs.getSelected(null, (tab) -> - frames = framesForTab[tab.id].frames - currIndex = frames.frameIndex or getCurrFrameIndex(frames) - - # TODO: Skip the "top" frame (which doesn't actually have a <frame> tag), - # since it exists only to contain the other frames. - frames.frameIndex = newIndex = (currIndex + count) % frames.length - - chrome.tabs.sendMessage(tab.id, { name: "focusFrame", frameId: frames[newIndex].id, highlight: true })) + frames = framesForTab[tab.id] = framesForTab[tab.id].rotate(count) + chrome.tabs.sendMessage(tab.id, { name: "focusFrame", frameId: frames[0].id, highlight: true })) closeTabsOnLeft: -> removeTabsRelative "before" closeTabsOnRight: -> removeTabsRelative "after" @@ -603,39 +597,30 @@ openOptionsPageInNewTab = -> chrome.tabs.create({ url: chrome.runtime.getURL("pages/options.html"), index: tab.index + 1 })) registerFrame = (request, sender) -> - unless framesForTab[sender.tab.id] - framesForTab[sender.tab.id] = { frames: [] } - - if (request.is_top) - focusedFrame = request.frameId - framesForTab[sender.tab.id].frames.frameIndex = getCurrFrameIndex(framesForTab[sender.tab.id]) - - framesForTab[sender.tab.id].frames.push({ id: request.frameId }) + frames = framesForTab[sender.tab.id] ?= [] + if request.is_top + frames.unshift id: request.frameId + else + frames.push id: request.frameId unregisterFrame = (request, sender) -> - return unless framesForTab[sender.tab.id] + frames = framesForTab[sender.tab.id] + return unless frames? if request.is_top # The whole tab is closing, so we can drop the frames list. updateOpenTabs(sender.tab) - return - - frames = framesForTab[sender.tab.id].frames - - for index, tabDetails of frames - if (tabDetails.id == request.frameId) - frames.splice(index, 1) - - frames.frameIndex-- if frames.frameIndex >= index # Adjust index if it is shifted. - nextFrame(0) if frames.frameIndex == index # Focus another frame if the closed one was focused. - return + else + index = getFrameIndex frames, request.frameId + frames.splice index, 1 + nextFrame 0 handleFrameFocused = (request, sender) -> - focusedFrame = request.frameId - framesForTab[sender.tab.id].frames.frameIndex = getCurrFrameIndex(framesForTab[sender.tab.id]) + index = getFrameIndex framesForTab[sender.tab.id], request.frameId + framesForTab[sender.tab.id] = frames.rotate index -getCurrFrameIndex = (frames) -> - for i in [0...frames.length] - return i if frames[i].id == focusedFrame +getFrameIndex = (frames, frameId) -> + for frameDetails, index in frames + return index if frameDetails.id == frameId frames.length + 1 # Port handler mapping diff --git a/lib/utils.coffee b/lib/utils.coffee index b7f8731a..428112c8 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -147,6 +147,13 @@ Array.copy = (array) -> Array.prototype.slice.call(array, 0) String::startsWith = (str) -> @indexOf(str) == 0 +Array::rotate = (count) -> + return this if @length == 0 + count = count % @length + count = count + @length if count < 0 + Array::push.apply(this, @splice(0, count)) + this + globalRoot = window ? global globalRoot.extend = (hash1, hash2) -> for key of hash2 |
