diff options
author | Moonchild <moonchild@palemoon.org> | 2022-05-10 21:03:53 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2022-05-10 21:03:53 +0000 |
commit | 517aec31118aa1e52168b02a1e4a6f2aa32d0031 (patch) | |
tree | 5ee4ce514f56c7d8a24ec879eb01dca71b11fb26 /toolkit/components | |
parent | 930ddd693be251c86ee904dafbaef38234b692c0 (diff) | |
download | uxp-517aec31118aa1e52168b02a1e4a6f2aa32d0031.tar.gz |
Issue #1509 - Invalidate previous result when datalist is changed.
Even if `<datalist>` is dynamically changed, the autocomplete controller still
uses the previous search result. If changed, we have to ignore the previous
result that may now be invalid.
Also, even if `<datalist>` is changed, we have to keep the selected index
(See Mozilla Bug 595069), so we cannot use `ResetInternalState` in this
situation because it resets the selected index.
This resolves #1509.
Diffstat (limited to 'toolkit/components')
4 files changed, 31 insertions, 5 deletions
diff --git a/toolkit/components/autocomplete/nsAutoCompleteController.cpp b/toolkit/components/autocomplete/nsAutoCompleteController.cpp index 9ca382fe5e..4ca35715a9 100644 --- a/toolkit/components/autocomplete/nsAutoCompleteController.cpp +++ b/toolkit/components/autocomplete/nsAutoCompleteController.cpp @@ -1183,11 +1183,16 @@ nsAutoCompleteController::BeforeSearches() mSearchStatus = nsIAutoCompleteController::STATUS_SEARCHING; mDefaultIndexCompleted = false; - // The first search result will clear mResults array, though we should pass - // the previous result to each search to allow them to reuse it. So we - // temporarily cache current results till AfterSearches(). - if (!mResultCache.AppendObjects(mResults)) { - return NS_ERROR_OUT_OF_MEMORY; + bool invalidatePreviousResult = false; + mInput->GetInvalidatePreviousResult(&invalidatePreviousResult); + + if (!invalidatePreviousResult) { + // ClearResults will clear the mResults array, but we should pass the + // previous result to each search to allow reusing it. So we temporarily + // cache the current results until AfterSearches(). + if (!mResultCache.AppendObjects(mResults)) { + return NS_ERROR_OUT_OF_MEMORY; + } } mSearchesOngoing = mSearches.Length(); diff --git a/toolkit/components/autocomplete/nsIAutoCompleteInput.idl b/toolkit/components/autocomplete/nsIAutoCompleteInput.idl index 26a75ea776..8b7e7cc882 100644 --- a/toolkit/components/autocomplete/nsIAutoCompleteInput.idl +++ b/toolkit/components/autocomplete/nsIAutoCompleteInput.idl @@ -178,4 +178,11 @@ interface nsIAutoCompleteInput : nsISupports * The userContextId of the current browser. */ readonly attribute unsigned long userContextId; + + /** + * Indicates whether the previous result should be invalidated due to dynamic + * list updates. If search content is updated, we shouldn't use the previous + * search result. + */ + readonly attribute boolean invalidatePreviousResult; }; diff --git a/toolkit/components/satchel/nsFormFillController.cpp b/toolkit/components/satchel/nsFormFillController.cpp index bebc60f521..a89c138fab 100644 --- a/toolkit/components/satchel/nsFormFillController.cpp +++ b/toolkit/components/satchel/nsFormFillController.cpp @@ -670,6 +670,13 @@ nsFormFillController::GetUserContextId(uint32_t* aUserContextId) return NS_OK; } +NS_IMETHODIMP +nsFormFillController::GetInvalidatePreviousResult( + bool* aInvalidatePreviousResult) { + *aInvalidatePreviousResult = mInvalidatePreviousResult; + return NS_OK; +} + //////////////////////////////////////////////////////////////////////// //// nsIAutoCompleteSearch @@ -807,6 +814,8 @@ void nsFormFillController::RevalidateDataList() return; } + // We cannot use previous result since any items in search target are updated. + mInvalidatePreviousResult = true; controller->StartSearch(mLastSearchString); return; } @@ -817,6 +826,8 @@ void nsFormFillController::RevalidateDataList() nsCOMPtr<nsIAutoCompleteResult> result; + // We cannot use previous result since any items in search target are updated. + mInvalidatePreviousResult = true; rv = inputListAutoComplete->AutoCompleteSearch(mLastSearchString, mFocusedInput, getter_AddRefs(result)); @@ -864,6 +875,8 @@ nsFormFillController::OnSearchCompletion(nsIAutoCompleteResult *aResult) NS_IMETHODIMP nsFormFillController::HandleEvent(nsIDOMEvent* aEvent) { + mInvalidatePreviousResult = false; + nsAutoString type; aEvent->GetType(type); diff --git a/toolkit/components/satchel/nsFormFillController.h b/toolkit/components/satchel/nsFormFillController.h index 27fb1edbd9..b11835d1de 100644 --- a/toolkit/components/satchel/nsFormFillController.h +++ b/toolkit/components/satchel/nsFormFillController.h @@ -120,6 +120,7 @@ protected: bool mCompleteSelectedIndex; bool mForceComplete; bool mSuppressOnInput; + bool mInvalidatePreviousResult = false; }; #endif // __nsFormFillController__ |