-
Notifications
You must be signed in to change notification settings - Fork 121
Fix #1081, switch to next/previous window #1129
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few style notes. Also it looks you need to run npm run format
to put everything in the normal style.
extension/intents/window/window.js
Outdated
if ( direction === "next" ) { | ||
targetIndex = Math.floor((currentWindowIndex + 1) % len); | ||
} else { | ||
targetIndex = Math.floor((currentWindowIndex - 1 + len) % len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Math.floor
won't be necessary here, everything is an integer so it should stay an integer.
extension/intents/window/window.js
Outdated
const len = windowArray.length; | ||
// find currentWindowId postion in array | ||
const currentWindowIndex = windowArray.findIndex((window) => (window.id === currentWindowId)); | ||
let targetIndex = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be initialized to anything, since it will definitely be reset below.
// error handle for | ||
function onError(error) { | ||
// console.log(`Error: ${error}`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There doesn't need to be any error handler, if there's an error in .run()
the intentRunner will catch it.
extension/intents/window/window.js
Outdated
let direction = "next"; | ||
if ( context.parameters ) { | ||
direction = context.parameters.direction; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will definitely be set, so you can just do let direction = context.parameters.direction
without the if.
extension/intents/window/window.js
Outdated
await browser.windows.update(targetWindowId, {focused: true}); | ||
} catch (err) { | ||
onError(err); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the entire try/catch, and the comments all match the code so they aren't really necessary either.
extension/intents/window/window.toml
Outdated
description = "Switch the current window" | ||
match = """ | ||
switch to next window [direction=next] | ||
switch to previous window [direction=back] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd do the phrase something like:
match = """
(switch | activate | focus) (the | to |) next window [direction=next]
(switch | activate | focus) (the | to |) (previous | last) window [direction=back]
"""
Looking good, thank you for your contribution! |
No description provided.