From c2f751983db330749e3a44d37160a2ecb14961c4 Mon Sep 17 00:00:00 2001 From: Greg Tatum Date: Mon, 28 Mar 2022 19:08:49 +0000 Subject: [PATCH] Bug 1758730 - Ensure no errors or warning show on search engine prefs; r=Standard8 The live language reloading triggers code that will run that assumes the view is visible, when in fact it may not be on the dom. This fixes that. In addition it fixes the error where the engine tries to update after it has been removed. Differential Revision: https://phabricator.services.mozilla.com/D141685 --- browser/components/preferences/search.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/browser/components/preferences/search.js b/browser/components/preferences/search.js index f7798f0d6c9d..72bf41802c45 100644 --- a/browser/components/preferences/search.js +++ b/browser/components/preferences/search.js @@ -484,10 +484,17 @@ var gSearchPane = { remove(aEngine) { let index = gEngineView._engineStore.removeEngine(aEngine); + if (!gEngineView.tree) { + // Only update the selection if it's visible in the UI. + return; + } + gEngineView.rowCountChanged(index, -1); gEngineView.invalidate(); + gEngineView.selection.select(Math.min(index, gEngineView.rowCount - 1)); gEngineView.ensureRowIsVisible(gEngineView.currentIndex); + document.getElementById("engineList").focus(); }, @@ -652,12 +659,9 @@ EngineStore.prototype = { let engineToUpdate = this._engines.findIndex( e => e.originalEngine == newEngine ); - if (engineToUpdate == -1) { - console.error("Could not find engine to update"); - return; + if (engineToUpdate != -1) { + this.engines[engineToUpdate] = this._cloneEngine(newEngine); } - - this.engines[engineToUpdate] = this._cloneEngine(newEngine); }, moveEngine(aEngine, aNewIndex) {