Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ctrlnumber.js to ignore pinned tabs #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jasht1
Copy link

@jasht1 jasht1 commented Dec 6, 2023

resolves #5 by ignoring pinned tabs by default

Project proposal

2023-12-03 @ 18:24
I want to get better at programming, that means being able to write code that solves problems. Adding to a plugin I use provides;

  • a project to work on
  • a motivation to finish that project
  • evidence of my work
  • value to others

I'm thinking of improving the plugin firefox-ctrlnumber as its a simple one & I have a very simple idea of how I would improve it.
I would like it to ignore pinned tabs for which I sent a feature request but I would like it give it a go myself.

Improving firefox-ctrlnumber

2023-12-05 @ 16:32
From my experience most pinned tabs are not used for general browsing and users often already have unique shortcuts for the ones they need this is evidenced by the fact firefoxe's built in ctrl+tab ignores pinned tabs. Therefore ignoring pinned tabs is a sensible default.

The code

The main code of the extension is as follows:

browser.commands.onCommand.addListener(async function(command) {
    let idx = command.slice(-1) % 9 - 1;
    const tabs = await browser.tabs.query({ currentWindow: true, hidden: false});
    if (tabs.length <= idx) {
        idx = tabs.length - 1
    }
    const tab = tabs.slice(idx);
    if (tab.length) {
        browser.tabs.update(tab[0].id, { active: true });
    }
});

From initial inspection it would seem all I need to do is add a modifier to the query in line 3,

browser.tabs.query({ currentWindow: true, hidden: false});

The documentation for tabs.quiery is very clear and lists one of the optional properties as:
pinned Optional
boolean. Whether the tabs are pinned.
so I add , pinned: false like so:

browser.tabs.query({ currentWindow: true, hidden: false, pinned: false});

I assume it handles multiple queryObj as && as there already seems to be 2 in there separated by commas working just fine.
The full src/ctrlnumber.js would then be:

browser.commands.onCommand.addListener(async function(command) {
    let idx = command.slice(-1) % 9 - 1;
    const tabs = await browser.tabs.query({ currentWindow: true, hidden: false});
    if (tabs.length <= idx) {
        idx = tabs.length - 1
    }
    const tab = tabs.slice(idx);
    if (tab.length) {
        browser.tabs.update(tab[0].id, { active: true });
    }
});

The next step is to figure out how to test & apply my solution...

Implementation

2023-12-05 @ 16:43
I have Mozilla's documentation very clear and helpful and very quickly found a page explaining how to implement your own extensions.

  1. open about:debugging#/runtime/this-firefox
  2. click "load temporary Add-on..."
    The extension will be installed & enabled until you restart Firefox.

I cloned the Git repo & made the previously described amendment, added it as a temporary add-on and it worked as expected.

Further improvement's

2023-12-06 @ 04:20
From here a basic preferences page could be added allowing users to change which tabs are ignored.

@jasht1 jasht1 marked this pull request as ready for review December 6, 2023 04:30
@peteygao
Copy link

This smells like some sort of homework requirement your professor tasked you with. "Contribute to an open source project for bonus points" 🤮.

From my experience most pinned tabs are not used for general browsing and users often already have unique shortcuts for the ones they need this is evidenced by the fact firefoxe's built in ctrl+tab ignores pinned tabs

This is patently false. Firefox absolutely respects ctrl + tab hotkeys to cycle through pinned tabs!

Also, do enlighten me on the "users often already have unique shortcuts for the ones they need"? If not via alt+1,2,3 (or ctrl+1,2,3 with this extension), what kind of "unique shortcuts" are you referring to when accessing pinned tabs?

From here a basic preferences page could be added allowing users to change which tabs are ignored.

IF you want this feature, make it an option. You'll have to roll up your sleeves and put in more elbow grease by actually making an options page (which doesn't exist right now), and then add this as a toggleable option: skip enumerating pinned tabs.

But for the love of all things holy, do not make this the default behaviour!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to ignore pinned tabs #feature_request
2 participants