From be2a44dab99dd3bbde6325607ed4e8b044cf382b Mon Sep 17 00:00:00 2001 From: "mr. M" Date: Mon, 10 Feb 2025 22:16:50 +0100 Subject: [PATCH] Added a timeout before the newtab url bar can clear it's content --- src/browser/app/profile/zen-browser.js | 3 ++- src/browser/base/content/ZenUIManager.mjs | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/browser/app/profile/zen-browser.js b/src/browser/app/profile/zen-browser.js index 6e78ff8e7..a61533e60 100644 --- a/src/browser/app/profile/zen-browser.js +++ b/src/browser/app/profile/zen-browser.js @@ -118,6 +118,7 @@ pref('zen.view.compact.animate-sidebar', true); pref('zen.urlbar.replace-newtab', true); pref('zen.urlbar.behavior', 'floating-on-type'); // default, floating-on-type, float +pref('zen.urlbar.wait-to-clear', 45000); // in ms (default 45s) #ifdef XP_MACOSX // Disable for macos in the meantime until @HarryHeres finds a solution for hight DPI screens @@ -167,7 +168,7 @@ pref('zen.tab-unloader.excluded-urls', "example.com,example.org"); pref('zen.pinned-tab-manager.debug', false); pref('zen.pinned-tab-manager.restore-pinned-tabs-to-pinned-url', false); -pref('zen.pinned-tab-manager.close-shortcut-behavior', 'switch'); +pref('zen.pinned-tab-manager.close-shortcut-behavior', 'unload-switch'); // TODO: Check this out! pref("browser.profiles.enabled", false); diff --git a/src/browser/base/content/ZenUIManager.mjs b/src/browser/base/content/ZenUIManager.mjs index f4462c0bd..4c58a6e90 100644 --- a/src/browser/base/content/ZenUIManager.mjs +++ b/src/browser/base/content/ZenUIManager.mjs @@ -8,6 +8,7 @@ var gZenUIManager = { document.addEventListener('popuphidden', this.onPopupHidden.bind(this)); XPCOMUtils.defineLazyPreferenceGetter(this, 'sidebarHeightThrottle', 'zen.view.sidebar-height-throttle', 500); XPCOMUtils.defineLazyPreferenceGetter(this, 'contentElementSeparation', 'zen.theme.content-element-separation', 0); + XPCOMUtils.defineLazyPreferenceGetter(this, 'urlbarWaitToClear', 'zen.urlbar.wait-to-clear', 0); ChromeUtils.defineLazyGetter(this, 'motion', () => { return ChromeUtils.importESModule('chrome://browser/content/zen-vendor/motion.min.mjs', { global: 'current' }); @@ -149,11 +150,15 @@ var gZenUIManager = { _prevUrlbarLabel: null, _lastSearch: '', + _clearTimeout: null, handleNewTab(werePassedURL, searchClipboard, where) { const shouldOpenURLBar = Services.prefs.getBoolPref('zen.urlbar.replace-newtab') && !werePassedURL && !searchClipboard && where === 'tab'; if (shouldOpenURLBar) { + if (this._clearTimeout) { + clearTimeout(this._clearTimeout); + } this._prevUrlbarLabel = gURLBar._untrimmedValue; gURLBar._zenHandleUrlbarClose = this.handleUrlbarClose.bind(this); gURLBar.setAttribute('zen-newtab', true); @@ -164,14 +169,21 @@ var gZenUIManager = { return false; }, + clearUrlbarData() { + this._prevUrlbarLabel = null; + this._lastSearch = ''; + }, + handleUrlbarClose(onSwitch) { gURLBar._zenHandleUrlbarClose = null; gURLBar.removeAttribute('zen-newtab'); if (onSwitch) { - this._prevUrlbarLabel = null; - this._lastSearch = ''; + this.clearUrlbarData(); } else { this._lastSearch = gURLBar._untrimmedValue; + this._clearTimeout = setTimeout(() => { + this.clearUrlbarData(); + }, this.urlbarWaitToClear); } gURLBar.setURI(this._prevUrlbarLabel, onSwitch, false, false, !onSwitch); gURLBar.handleRevert();