Giter Site home page Giter Site logo

Comments (2)

brrd avatar brrd commented on June 7, 2024

We won't add this feature because I think this is out of the scope of electron-tabs, which is intended to be generic and "KISS" lib.

Why not accessing title element with tab.spans.title, as we do in :

const span = this.spans.title;

By the way, be aware that contenteditable does not filter out HTML elements, so pasting a h1 or several paragraphs in the tab would lead to a broken display. I guess you do want raw text, so you probably need to use window.prompt instead. Untested example:

 function tab_init(tab) {
    const tabTitle = tab.spans.title;
    tab.setTitle("Page " + tabGroup.newTabId);
    tabTitle.addEventListener("click", function() {
        const newTitle = window.prompt("Please type the new title");
        tab.setTitle(newTitle);
    });
  }

from electron-tabs.

tennis-aa avatar tennis-aa commented on June 7, 2024

Thank you for the quick reply. tab.spans.title is exactly what I was looking for.

I have a few comments if anybody else is looking for this functionality.

window.prompt is not supported by electron, so you would have to write your own prompt function (electron/electron#472).

What I ended up using is the following:

function tab_init(tab) {
  tab.setTitle("Page " + tabGroup.newTabId);
  let tab_title = tab.spans.title;
  tab.element.addEventListener("click", function() {
    tab_title.setAttribute("contenteditable", true);
  });
  tab_title.addEventListener("blur", function() {
    tab_title.setAttribute("contenteditable", false);
    if (tab_title.textContent == "") tab_title.textContent = "No title";
    tab_title.textContent = tab_title.textContent;
  });
}

contenteditable does not filter out pasted html elements, so I am filtering it out myself (tab_title.textContent = tab_title.textContent;).

I am not calling tab.setTitle() because it modifies the innerHTML of the title span so html code would be rendered.

from electron-tabs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.