@samitouri / QOS-React-2 / commits / 07299828c9

Pressing next forces search to select

Dan committed Apr 9, 2019 at 00:06 UTC 07299828c9e0d9050e6a8c63ed129b16a4d4bf0d
1 file changed +18 -3
src/devtools/views/Components/TreeContext.js
+18 -3
@@ -202,17 +202,25 @@ function reduceSearchState(store: Store, state: State, action: Action): State {
202 const prevSearchText = searchText;
203 const numPrevSearchResults = searchResults.length;
204
205 + // We track explicitly whether search was requested because
206 + // we might want to search even if search index didn't change.
207 + // For example, if you press "next result" on a search with a single
208 + // result but a different current selection, we'll set this to true.
209 + let didRequestSearch = false;
210 +
211 // Search isn't supported when the owner's tree is active.
212 if (ownerStack.length === 0) {
213 switch (type) {
214 case 'GO_TO_NEXT_SEARCH_RESULT':
215 if (numPrevSearchResults > 0) {
216 + didRequestSearch = true;
217 searchIndex =
218 searchIndex + 1 < numPrevSearchResults ? searchIndex + 1 : 0;
219 }
220 break;
221 case 'GO_TO_PREVIOUS_SEARCH_RESULT':
222 if (numPrevSearchResults > 0) {
223 + didRequestSearch = true;
224 searchIndex =
225 ((searchIndex: any): number) > 0
226 ? ((searchIndex: any): number) - 1
@@ -313,10 +321,17 @@ function reduceSearchState(store: Store, state: State, action: Action): State {
321 }
322
323 // Changes in search index or typing should override the selected element.
316 - const didAddToSearchText =
324 + if (searchIndex !== prevSearchIndex) {
325 + didRequestSearch = true;
326 + }
327 + if (
328 + // Did the user type more?
329 searchText.length > prevSearchText.length &&
318 - searchText.indexOf(prevSearchText) === 0;
319 - if (searchIndex !== prevSearchIndex || didAddToSearchText) {
330 + searchText.indexOf(prevSearchText) === 0
331 + ) {
332 + didRequestSearch = true;
333 + }
334 + if (didRequestSearch) {
335 if (searchIndex === null) {
336 selectedElementIndex = null;
337 selectedElementID = null;