Adds incTab to increment tab, fix JS modulo

This commit is contained in:
Oliver Blanthorn 2017-02-14 12:13:25 +00:00
parent 53a2317181
commit 76b1247998
2 changed files with 19 additions and 4 deletions

View file

@ -57,14 +57,14 @@ displayTab = (tab_id) ->
# the real thing.
browser.browserAction.onClicked.addListener(handleBrowserAction)
nextTab = () ->
incTab = (inc) ->
browser.windows.getCurrent().then(
(window) ->
browser.tabs.query({windowId:window.id}).then(
(tabs) ->
active = (tab for tab in tabs when tab.active)[0]
nextIndex = (active.index + 1) % tabs.length
desiredTab = (tab for tab in tabs when tab.index == nextIndex)[0]
activeTab = (tab for tab in tabs when tab.active)[0]
desiredIndex = (activeTab.index + inc).mod(tabs.length)
desiredTab = (tab for tab in tabs when tab.index == desiredIndex)[0]
setTab(desiredTab.id)
).catch(console.error)
).catch(console.error)
@ -77,5 +77,9 @@ tabByIndex = (index) ->
desiredTab = tab for tab in tabs when tab.index == desIndex
)
Number.prototype.mod = (n) ->
((this%n)+n)%n
# Javascript doens't understand maths
# Lots of people use myFunc: ()-> \\ rather than \\ myFunc = () -> \\ do we care?
console.log("Loaded Tridactyl")

View file

@ -56,3 +56,14 @@ Tridactyl (like Pentadactyl, but worse, last cuturally relevant in 2005 like Sal
# Features we need less?
autocmds?
macros?
# Vimium notes
Uses descriptors a lot - what even are they?
Loading into firefox doesn't give any errors / doesn't seem to expose any functions?
# Other stuff
Would be nice to have self-writing documentation, for autocmd use etc?
History seems to be window.history.go(), presumably in a content script?