@samitouri / QOS-React-2 / commits / 3eca0bbe61

Use heuristic suggested by @sophiebits

Dan Abramov committed Apr 10, 2019 at 15:08 UTC 3eca0bbe6144dcb2d542766e323bf3c6f005cd08
1 file changed +11 -7
src/devtools/views/Components/TreeContext.js
+11 -7
@@ -320,16 +320,20 @@ function reduceSearchState(store: Store, state: State, action: Action): State {
320 }
321 }
322
323 - // Changes in search index or typing should override the selected element.
323 if (searchIndex !== prevSearchIndex) {
324 + // The user intentionally navigated between search results
325 didRequestSearch = true;
326 }
327 - if (
328 - // Did the user type more?
329 - searchText.length > prevSearchText.length &&
330 - searchText.indexOf(prevSearchText) === 0
331 - ) {
332 - didRequestSearch = true;
327 + if (searchText !== prevSearchText) {
328 + if (searchResults.indexOf(selectedElementID) === -1) {
329 + // Only move the selection if the new query
330 + // doesn't match the current selection anymore.
331 + didRequestSearch = true;
332 + } else {
333 + // Selected item still matches the new search query.
334 + // Adjust the index to reflect its position in new results.
335 + searchIndex = searchResults.indexOf(selectedElementID);
336 + }
337 }
338 if (didRequestSearch) {
339 if (searchIndex === null) {