diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-02-17 15:54:53 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-02-17 09:24:05 +0100 |
| commit | b3c5c6fe82127d636c72ba662319ad9da548e329 (patch) | |
| tree | d6774e397440c612627a0a7aae6bb8f3e2c85199 /src/mainwindow.cpp | |
| parent | b82ecad5462eec767e2e3216e9e96dfebf04f1cc (diff) | |
| download | kristall-b3c5c6fe82127d636c72ba662319ad9da548e329.tar.gz | |
Fix: remove N-L from tab title. Also limit tab title length
0) when visiting for example, https://lists.orbitalfox.eu/archives/gemini/2020/000304.html the page title was getting a newline character in it (for some reason). This has now been fixed.
1) the tab title is now limited to 45 characters, until the string is chopped and an ellipsis (...) is appended. This limit was added to prevent pages with enormous titles from clogging up the tab bar. For this reason, the limit is quite high - users browing Gemini don't usually have that many tabs open (compared to the web), so i think we can get away with this high number.
Diffstat (limited to 'src/mainwindow.cpp')
| -rw-r--r-- | src/mainwindow.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d2623eb..3008c0b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -356,19 +356,30 @@ void MainWindow::on_history_view_doubleClicked(const QModelIndex &index) void MainWindow::on_tab_titleChanged(const QString &title) { - auto * tab = qobject_cast<BrowserTab*>(sender()); - if(tab != nullptr) { - int index = this->ui->browser_tabs->indexOf(tab); - assert(index >= 0); + auto * tab = qobject_cast<BrowserTab*>(sender()); + if(tab != nullptr) { + int index = this->ui->browser_tabs->indexOf(tab); + assert(index >= 0); - QString escapedTitle = title; - this->ui->browser_tabs->setTabText(index, escapedTitle.replace("&", "&&")); + QString escapedTitle = title; - if (tab == this->curTab()) - { + // Set the window title to full title + if (tab == this->curTab()) + { updateWindowTitle(); - } - } + } + + // Shorten lengthy titles for tab bar (45 chars max for now - we assume + // that Gemini surfers don't usually have loads of tabs open, so the + // limit is fairly high) + const int MAX_TITLE_LEN = 45; + if (escapedTitle.length() > MAX_TITLE_LEN) + { + escapedTitle = escapedTitle.mid(0, MAX_TITLE_LEN - 3).trimmed() + "..."; + } + + this->ui->browser_tabs->setTabText(index, escapedTitle.replace("&", "&&")); + } } void MainWindow::on_tab_locationChanged(const QUrl &url) |
