[DRAFT] Fix text search unable to find last file in folder (#4039) #4097
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WIP: currently not working, needs some more investigation
Bug: The alphanumeric text search could not find the last file in any folder. When typing the first letters of the last file's name (e.g., 'X' for 'Xylophone'), it would not appear in search results.
Root cause: In predictExtendedText(), when searching for a prefix like 'X', the code appends
~to createX~and uses binary search to find where this would be inserted. For the last file, this correctly returnsindex == numElements. However, the conditioni >= numElementsincorrectly treated this valid case as 'not found'.Fix: Changed the condition from
i >= numElementstoi > numElementsat line 1412. This allows the valid case where i == numElements, which occurs when the last item matches the search prefix. The subsequenti--then correctly selects the last file.Also fixed a similar bounds check issue in setFileByFullPath() at line 506, changing from
i > numElementstoi >= numElementsfor proper validation of exact file searches.Fixes #4039