mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-03 14:28:39 +09:00
Restore typeAheadResult support in autocomplete
This commit is contained in:
parent
c887c0a5ee
commit
6106e49360
11 changed files with 273 additions and 52 deletions
|
|
@ -1637,58 +1637,72 @@ nsAutoCompleteController::ProcessResult(int32_t aSearchIndex, nsIAutoCompleteRes
|
|||
MOZ_ASSERT(mResults.Count() >= aSearchIndex + 1,
|
||||
"aSearchIndex should always be valid for mResults");
|
||||
|
||||
uint32_t oldRowCount = mRowCount;
|
||||
// If the search failed, increase the match count to include the error
|
||||
// description.
|
||||
if (searchResult == nsIAutoCompleteResult::RESULT_FAILURE) {
|
||||
nsAutoString error;
|
||||
aResult->GetErrorDescription(error);
|
||||
if (!error.IsEmpty()) {
|
||||
++mRowCount;
|
||||
if (mTree) {
|
||||
mTree->RowCountChanged(oldRowCount, 1);
|
||||
bool isTypeAheadResult = false;
|
||||
aResult->GetTypeAheadResult(&isTypeAheadResult);
|
||||
|
||||
if (!isTypeAheadResult) {
|
||||
uint32_t oldRowCount = mRowCount;
|
||||
// If the search failed, increase the match count to include the error
|
||||
// description.
|
||||
if (searchResult == nsIAutoCompleteResult::RESULT_FAILURE) {
|
||||
nsAutoString error;
|
||||
aResult->GetErrorDescription(error);
|
||||
if (!error.IsEmpty()) {
|
||||
++mRowCount;
|
||||
if (mTree) {
|
||||
mTree->RowCountChanged(oldRowCount, 1);
|
||||
}
|
||||
}
|
||||
} else if (searchResult == nsIAutoCompleteResult::RESULT_SUCCESS ||
|
||||
searchResult == nsIAutoCompleteResult::RESULT_SUCCESS_ONGOING) {
|
||||
// Increase the match count for all matches in this result.
|
||||
uint32_t totalMatchCount = 0;
|
||||
for (uint32_t i = 0; i < mResults.Length(); i++) {
|
||||
nsIAutoCompleteResult* result = mResults.SafeObjectAt(i);
|
||||
if (result) {
|
||||
// not all results implement this, so it can likely fail.
|
||||
bool typeAhead = false;
|
||||
result->GetTypeAheadResult(&typeAhead);
|
||||
if (!typeAhead) {
|
||||
uint32_t matchCount = 0;
|
||||
result->GetMatchCount(&matchCount);
|
||||
totalMatchCount += matchCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
uint32_t delta = totalMatchCount - oldRowCount;
|
||||
|
||||
mRowCount += delta;
|
||||
if (mTree) {
|
||||
mTree->RowCountChanged(oldRowCount, delta);
|
||||
}
|
||||
}
|
||||
|
||||
// Try to autocomplete the default index for this search.
|
||||
// Do this before invalidating so the binding knows about it.
|
||||
CompleteDefaultIndex(aSearchIndex);
|
||||
|
||||
// Refresh the popup view to display the new search results
|
||||
nsCOMPtr<nsIAutoCompletePopup> popup;
|
||||
input->GetPopup(getter_AddRefs(popup));
|
||||
NS_ENSURE_TRUE(popup != nullptr, NS_ERROR_FAILURE);
|
||||
popup->Invalidate(nsIAutoCompletePopup::INVALIDATE_REASON_NEW_RESULT);
|
||||
|
||||
uint32_t minResults;
|
||||
input->GetMinResultsForPopup(&minResults);
|
||||
|
||||
// Make sure the popup is open, if necessary, since we now have at least one
|
||||
// search result ready to display. Don't force the popup closed if we might
|
||||
// get results in the future to avoid unnecessarily canceling searches.
|
||||
if (mRowCount || !minResults) {
|
||||
OpenPopup();
|
||||
} else if (mSearchesOngoing == 0) {
|
||||
ClosePopup();
|
||||
}
|
||||
} else if (searchResult == nsIAutoCompleteResult::RESULT_SUCCESS ||
|
||||
searchResult == nsIAutoCompleteResult::RESULT_SUCCESS_ONGOING) {
|
||||
// Increase the match count for all matches in this result.
|
||||
uint32_t totalMatchCount = 0;
|
||||
for (uint32_t i = 0; i < mResults.Length(); i++) {
|
||||
nsIAutoCompleteResult* result = mResults.SafeObjectAt(i);
|
||||
if (result) {
|
||||
uint32_t matchCount = 0;
|
||||
result->GetMatchCount(&matchCount);
|
||||
totalMatchCount += matchCount;
|
||||
}
|
||||
}
|
||||
uint32_t delta = totalMatchCount - oldRowCount;
|
||||
|
||||
mRowCount += delta;
|
||||
if (mTree) {
|
||||
mTree->RowCountChanged(oldRowCount, delta);
|
||||
}
|
||||
}
|
||||
|
||||
// Try to autocomplete the default index for this search.
|
||||
// Do this before invalidating so the binding knows about it.
|
||||
CompleteDefaultIndex(aSearchIndex);
|
||||
|
||||
// Refresh the popup view to display the new search results
|
||||
nsCOMPtr<nsIAutoCompletePopup> popup;
|
||||
input->GetPopup(getter_AddRefs(popup));
|
||||
NS_ENSURE_TRUE(popup != nullptr, NS_ERROR_FAILURE);
|
||||
popup->Invalidate(nsIAutoCompletePopup::INVALIDATE_REASON_NEW_RESULT);
|
||||
|
||||
uint32_t minResults;
|
||||
input->GetMinResultsForPopup(&minResults);
|
||||
|
||||
// Make sure the popup is open, if necessary, since we now have at least one
|
||||
// search result ready to display. Don't force the popup closed if we might
|
||||
// get results in the future to avoid unnecessarily canceling searches.
|
||||
if (mRowCount || !minResults) {
|
||||
OpenPopup();
|
||||
} else if (mSearchesOngoing == 0) {
|
||||
ClosePopup();
|
||||
// Try to autocomplete the default index for this search.
|
||||
CompleteDefaultIndex(aSearchIndex);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
@ -2033,14 +2047,20 @@ nsAutoCompleteController::RowIndexToSearch(int32_t aRowIndex, int32_t *aSearchIn
|
|||
|
||||
uint32_t rowCount = 0;
|
||||
|
||||
uint16_t searchResult;
|
||||
result->GetSearchResult(&searchResult);
|
||||
// Skip past the result completely if it is marked as hidden
|
||||
bool isTypeAheadResult = false;
|
||||
result->GetTypeAheadResult(&isTypeAheadResult);
|
||||
|
||||
// Find out how many results were provided by the
|
||||
// current nsIAutoCompleteSearch.
|
||||
if (searchResult == nsIAutoCompleteResult::RESULT_SUCCESS ||
|
||||
searchResult == nsIAutoCompleteResult::RESULT_SUCCESS_ONGOING) {
|
||||
result->GetMatchCount(&rowCount);
|
||||
if (!isTypeAheadResult) {
|
||||
uint16_t searchResult;
|
||||
result->GetSearchResult(&searchResult);
|
||||
|
||||
// Find out how many results were provided by the
|
||||
// current nsIAutoCompleteSearch.
|
||||
if (searchResult == nsIAutoCompleteResult::RESULT_SUCCESS ||
|
||||
searchResult == nsIAutoCompleteResult::RESULT_SUCCESS_ONGOING) {
|
||||
result->GetMatchCount(&rowCount);
|
||||
}
|
||||
}
|
||||
|
||||
// If the given row index is within the results range
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue