From 097d0386b133f779f4c3622d2a745d64e1e32fc8 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 12 Apr 2019 18:59:15 +0100 Subject: [PATCH] Track search navigation in DOM --- src/devtools/views/Components/Element.js | 4 +- src/devtools/views/Components/SearchInput.js | 32 ++++++++++---- src/devtools/views/Components/Tree.js | 45 ++++++++++++++------ 3 files changed, 57 insertions(+), 24 deletions(-) diff --git a/src/devtools/views/Components/Element.js b/src/devtools/views/Components/Element.js index 6bc9bfeb7e..1d3ac200a9 100644 --- a/src/devtools/views/Components/Element.js +++ b/src/devtools/views/Components/Element.js @@ -44,7 +44,7 @@ export default function ElementView({ data, index, style }: Props) { const { lastScrolledIDRef, treeFocused, - isNavigatingWithKeyboard, + isUsingKeyboardOrSearch, onElementMouseEnter, } = data; const id = element === null ? null : element.id; @@ -122,7 +122,7 @@ export default function ElementView({ data, index, style }: Props) { className = treeFocused ? styles.SelectedElement : styles.InactiveSelectedElement; - } else if (isHovered && !isNavigatingWithKeyboard) { + } else if (isHovered && !isUsingKeyboardOrSearch) { className = styles.HoveredElement; } diff --git a/src/devtools/views/Components/SearchInput.js b/src/devtools/views/Components/SearchInput.js index 51d0e58d3b..dc4069e384 100644 --- a/src/devtools/views/Components/SearchInput.js +++ b/src/devtools/views/Components/SearchInput.js @@ -8,9 +8,12 @@ import Icon from '../Icon'; import styles from './SearchInput.css'; -type Props = {||}; +type Props = {| + onSearchInteraction: () => void, +|}; export default function SearchInput(props: Props) { + const { onSearchInteraction } = props; const { goToNextSearchResult, goToPreviousSearchResult, @@ -25,13 +28,17 @@ export default function SearchInput(props: Props) { const inputRef = useRef(null); const handleTextChange = useCallback( - ({ currentTarget }) => setSearchText(currentTarget.value), - [setSearchText] + ({ currentTarget }) => { + setSearchText(currentTarget.value); + onSearchInteraction(); + }, + [setSearchText, onSearchInteraction] ); const resetSearch = useCallback(() => { setSearchText(''); - }, [setSearchText]); + onSearchInteraction(); + }, [setSearchText, onSearchInteraction]); const handleKeyDown = useCallback( event => { @@ -39,26 +46,29 @@ export default function SearchInput(props: Props) { switch (event.key) { case 'ArrowDown': selectNextElementInTree(); + onSearchInteraction(); event.preventDefault(); break; case 'ArrowUp': selectPreviousElementInTree(); + onSearchInteraction(); event.preventDefault(); break; default: break; } }, - [selectNextElementInTree, selectPreviousElementInTree] + [selectNextElementInTree, selectPreviousElementInTree, onSearchInteraction] ); const handleInputKeyPress = useCallback( ({ key }) => { if (key === 'Enter') { goToNextSearchResult(); + onSearchInteraction(); } }, - [goToNextSearchResult] + [goToNextSearchResult, onSearchInteraction] ); // Auto-focus search input @@ -109,7 +119,10 @@ export default function SearchInput(props: Props) {