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

[Feature] Tab renaming #4979

Draft
wants to merge 12 commits into
base: dev
Choose a base branch
from
Draft

Conversation

jso8910
Copy link
Contributor

@jso8910 jso8910 commented Feb 5, 2025

This is a pull request to implement tab renaming. It isn't yet complete. It works by adding a button to the right click context menu which then replaces the tab name with an input field to rename the tab. It requires one string to be added in the l10n repo (I haven't made that PR yet).

This pull request is not yet complete, as the tab name does not persist when the page reloads, loads another URL, or the browser restarts. I'm willing to take suggestions for how to do that (or contributions from other maintainers). I see files like ZenPinnedTabsStorage.mjs and wonder if that's a way to do it? Not quite sure. Or modifying the part of the browser engine that changes the title of a tab and stopping it from changing it if some attribute indicating the tab has been renamed is set as well as changing the part of the tab title which is saved to persist a session.

Also, I created a new file in the zen-components folder. I figured there wasn't any other place for this code to fit, but if I'm wrong, I'll refactor.

Pinging @mauro-balades to get feedback/help on the rest of this.

@devxan
Copy link

devxan commented Feb 5, 2025

What about this?

to dev, why not add a special folder to bookmark and use it for store tab data that user can also rename tab or add folder or sync it, make ui to combine tab and the bookmark that store in special folder to make it look like using normal tab.
for example.
/ Bookmark Menu / ZEN-TAB / WORKSPACE-1 / <all tab here, store as bookmark >
/ Bookmark Menu / ZEN-TAB / WORKSPACE-2 /< user dir >/ <all tab here, store as bookmark >

@jso8910
Copy link
Contributor Author

jso8910 commented Feb 5, 2025

That feels like it's a complete overhauling of the tabs system.... which is a bit beyond my skill level, familiarity with the code, or what I should be doing.

@devxan
Copy link

devxan commented Feb 5, 2025

I personally thought that would only apply to pinned tabs, but I can understand that that could still be crazy hard to make.

@Anthonyy232
Copy link

If this and the bookmark menu is in direct conflict, would it not be better to wait and see how the tab system will work going forward? Folders are coming for sure, so there's bound to be some change

@mauro-balades
Copy link
Member

Instead of overflowing the context menu, how about double clicking on pinned tabs only?

@Anoms12
Copy link

Anoms12 commented Feb 5, 2025

Thank you so much for this PR! I was going to make it but I cannot get the browser to build.

@mauro-balades
Copy link
Member

This pull request is not yet complete, as the tab name does not persist when the page reloads, loads another URL, or the browser restarts. I'm willing to take suggestions for how to do that (or contributions from other maintainers). I see files like ZenPinnedTabsStorage.mjs and wonder if that's a way to do it? Not quite sure. Or modifying the part of the browser engine that changes the title of a tab and stopping it from changing it if some attribute indicating the tab has been renamed is set as well as changing the part of the tab title which is saved to persist a session.

By just changing tabLabel.textContent = ... already saves on session store iirc. I can help you with this commit if you'd like. But please move this inside gZenVerticalTabsManager

@jso8910
Copy link
Contributor Author

jso8910 commented Feb 5, 2025

@mauro-balades by tabLabel.textContent = ... do you literally mean the HTML element that contains the text of the tab label? Or is it a javascript object. Because I tried changing the <label> element and it didn't persist. And neither does changing gBrowser.tabs[i].label.

And either way, this wouldn't stop the page title changing from changing the renamed title. I feel like this renaming should override any reloads, page navigation, etc.

@jso8910
Copy link
Contributor Author

jso8910 commented Feb 6, 2025

I found a good solution for persisting tab renames in the same session. Still not sure about persisting them across sessions. Here's an example with some dummy values.

let newName = "asdf";
let tab = gBrowser.tabs[5];
let observer = new MutationObserver((mutations) => {
  mutations.forEach((mutation) => {
    if (tab.label !== newName) {
      tab.label = newName;
    }
  })
})
observer.observe(tab, {attributeFilter: ["label"]})

I think you would want to add an attribute to each tab that is tab.renamedLabel which is undefined or null (not sure about JS-isms... which is ideal?) by default and then each pinned tab would have a listener like this (which would not do anything if it is null).

@jso8910
Copy link
Contributor Author

jso8910 commented Feb 7, 2025

@mauro-balades implemented your suggested changes. Now uses zen-has-static-label as an attribute. When you implement freezing the tab label based on that attribute, just make sure that browser.contentTitle (the contentTitle attribute in the browser object for the tab) is still able to change, because that's what's used for resetting the tab label.

I realized we never discussed what we should do to not only persist the fact that a tab is renamed, but also persist the renamed title (which currently doesn't restore on restart, as you'll see when you test the PR). Should I add something to the session store to store that?

@mauro-balades
Copy link
Member

mauro-balades commented Feb 9, 2025

I found a good solution for persisting tab renames in the same session. Still not sure about persisting them across sessions. Here's an example with some dummy values.

let newName = "asdf";
let tab = gBrowser.tabs[5];
let observer = new MutationObserver((mutations) => {
  mutations.forEach((mutation) => {
    if (tab.label !== newName) {
      tab.label = newName;
    }
  })
})
observer.observe(tab, {attributeFilter: ["label"]})

I think you would want to add an attribute to each tab that is tab.renamedLabel which is undefined or null (not sure about JS-isms... which is ideal?) by default and then each pinned tab would have a listener like this (which would not do anything if it is null).

@jso8910, add a patch here to simply return if we have the attribute. And make sure to do a git pull

src/browser/base/content/ZenUIManager.mjs Outdated Show resolved Hide resolved
src/browser/base/content/ZenUIManager.mjs Outdated Show resolved Hide resolved
src/browser/base/content/ZenUIManager.mjs Outdated Show resolved Hide resolved
src/browser/base/content/ZenUIManager.mjs Outdated Show resolved Hide resolved
src/browser/base/content/ZenUIManager.mjs Outdated Show resolved Hide resolved
src/browser/base/content/ZenUIManager.mjs Outdated Show resolved Hide resolved
src/browser/base/content/ZenUIManager.mjs Outdated Show resolved Hide resolved
src/browser/base/content/ZenUIManager.mjs Outdated Show resolved Hide resolved
src/browser/base/content/ZenUIManager.mjs Outdated Show resolved Hide resolved
src/browser/base/content/ZenUIManager.mjs Outdated Show resolved Hide resolved
src/browser/base/content/ZenUIManager.mjs Outdated Show resolved Hide resolved
src/browser/base/content/ZenUIManager.mjs Outdated Show resolved Hide resolved
@mauro-balades
Copy link
Member

Have fun!

@kakato10
Copy link

Will the custom tab name be matched in url bar suggestions?

@mauro-balades
Copy link
Member

Last thing remaning @jso8910 is that they shoudnt be able to be renamed if:

  1. the option zen.tabs.rename-tabs is false
  2. we have browser.tabs.closeTabByDblclick on true
  3. we are in single toolbar mode

@jso8910
Copy link
Contributor Author

jso8910 commented Feb 10, 2025

That's not quite the last thing remaining. The renamed tab name still isn't saved after restart. Currently, if a tab is renamed and then the initial focused tab after restart, it'll be named "New tab" and if it's renamed but not the initial focused tab after restart, its name is blank

@mauro-balades
Copy link
Member

That's due to the pinned tab manager, I already told u I can handle that part

… css files, changed listener to blur, refactored code
@mauro-balades
Copy link
Member

Please do let me know when it's ready for review. Also, there seems to be some git conflicts

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

Successfully merging this pull request may close these issues.

7 participants