-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add search capabilities to Peripheral Inspector view #25
Closed
martin-fleck-at
wants to merge
2
commits into
eclipse-cdt-cloud:main
from
eclipsesource:issues/23_search
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2024 Arm Limited and others | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the MIT License as outlined in the LICENSE File | ||
********************************************************************************/ | ||
|
||
import { VSCodeButton } from '@vscode/webview-ui-toolkit/react'; | ||
import React from 'react'; | ||
import './search.css'; | ||
|
||
export interface SearchOverlayProps { | ||
onChange?: (text: string) => void; | ||
onShow?: () => void; | ||
onHide?: () => void; | ||
} | ||
|
||
export interface SearchOverlay { | ||
focus: () => void; | ||
value(): string; | ||
setValue: (value: string) => void; | ||
show: () => void; | ||
hide: () => void; | ||
} | ||
|
||
export const SearchOverlay = React.forwardRef<SearchOverlay, SearchOverlayProps>((props, ref) => { | ||
const [showSearch, setShowSearch] = React.useState(false); | ||
const searchTextRef = React.useRef<HTMLInputElement>(null); | ||
const previousFocusedElementRef = React.useRef<HTMLElement | null>(null); | ||
|
||
const show = () => { | ||
previousFocusedElementRef.current = document.activeElement as HTMLElement; | ||
setShowSearch(true); | ||
setTimeout(() => searchTextRef.current?.select(), 100); | ||
props.onShow?.(); | ||
}; | ||
|
||
const hide = () => { | ||
setShowSearch(false); | ||
props.onHide?.(); | ||
if (previousFocusedElementRef.current) { | ||
previousFocusedElementRef.current.focus(); | ||
} | ||
}; | ||
|
||
const onTextChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const value = e.target.value; | ||
props.onChange?.(value); | ||
}; | ||
|
||
const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => { | ||
if (e.ctrlKey && e.key === 'f') { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
show(); | ||
} else if (e.key === 'Escape') { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
hide(); | ||
} | ||
}; | ||
|
||
const onFocus = (e: React.FocusEvent<HTMLInputElement>) => { | ||
if (e.relatedTarget) { | ||
previousFocusedElementRef.current = e.relatedTarget as HTMLElement; | ||
} | ||
}; | ||
|
||
React.useImperativeHandle(ref, () => ({ | ||
focus: () => searchTextRef.current?.focus(), | ||
value: () => searchTextRef.current?.value ?? '', | ||
setValue: (newValue: string) => { | ||
if (searchTextRef.current) { | ||
searchTextRef.current.value = newValue; | ||
} | ||
}, | ||
show: () => show(), | ||
hide: () => hide() | ||
})); | ||
|
||
return (<div className={showSearch ? 'search-overlay visible' : 'search-overlay'} onKeyDown={onKeyDown}> | ||
<input ref={searchTextRef} onChange={onTextChange} onFocus={onFocus} placeholder="Find" className="search-input" /> | ||
<VSCodeButton title='Close (Escape)' appearance='icon' aria-label='Close (Escape)'><span className='codicon codicon-close' onClick={() => hide()} /></VSCodeButton> | ||
</div> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2024 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the MIT License as outlined in the LICENSE File | ||
********************************************************************************/ | ||
|
||
.search-overlay { | ||
position: fixed; | ||
top: -33px; | ||
opacity: 0; | ||
right: 5px; | ||
background-color: var(--vscode-editorWidget-background); | ||
box-shadow: 0 0 4px 1px var(--vscode-widget-shadow); | ||
color: var(--vscode-editorWidget-foreground); | ||
border-bottom: 1px solid var(--vscode-widget-border); | ||
border-bottom-left-radius: 4px; | ||
border-bottom-right-radius: 4px; | ||
border-left: 1px solid var(--vscode-widget-border); | ||
border-right: 1px solid var(--vscode-widget-border); | ||
box-sizing: border-box; | ||
height: 33px; | ||
line-height: 19px; | ||
overflow: hidden; | ||
padding: 4px; | ||
z-index: 35; | ||
display: flex; | ||
flex-direction: row; | ||
gap: 5px; | ||
|
||
-webkit-transition: all 0.2s ease; | ||
-moz-transition: all 0.2s ease; | ||
-ms-transition: all 0.2s ease; | ||
-o-transition: all 0.2s ease; | ||
transition: all 0.2s ease; | ||
} | ||
|
||
.search-overlay.visible { | ||
top: 5px; | ||
opacity: 1; | ||
} | ||
|
||
.search-overlay .search-input { | ||
color: var(--vscode-input-foreground); | ||
background-color: var(--vscode-input-background); | ||
outline: none; | ||
scrollbar-width: none; | ||
border: none; | ||
box-sizing: border-box; | ||
display: inline-block; | ||
font-family: inherit; | ||
font-size: inherit; | ||
height: 100%; | ||
line-height: inherit; | ||
resize: none; | ||
width: 100%; | ||
padding: 4px 6px; | ||
margin: 0; | ||
} | ||
|
||
.search-overlay input.search-input:focus { | ||
outline: 1px solid var(--vscode-focusBorder) | ||
} | ||
|
||
|
||
.search-input::placeholder { | ||
color: var(--vscode-input-placeholderForeground); | ||
} | ||
|
||
.search-input::-moz-placeholder { | ||
color: var(--vscode-input-placeholderForeground); | ||
} | ||
|
||
.search-input:-ms-input-placeholder { | ||
color: var(--vscode-input-placeholderForeground); | ||
} | ||
|
||
.search-input:-webkit-input-placeholder { | ||
color: var(--vscode-input-placeholderForeground); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: expanding the properties here is inconsistent with other components in this repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I prefer deconstructing properties as it makes the code more readable in my opinion. I agree, however, that we should stay consistent and for the purpose of this PR I changed it back to accessing props directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates, @martin-fleck-at !
Thanks for fixing the find box behavior. I still do see a minimal jump of the box by one or two pixels to the left if the scrollbar disappears. That is on Windows. Not overly concerned about that one though.
I can confirm the progress line is gone. Thanks!
I checked again the last item in the list. I have to rephrase the report:
I does find registers by names even if they are invisible due to collapsed groups. However, for bit fields, the behavior is as described.
An example is for the NXP FRDM-K32L3A6 board/SVD file (Cortex-M4):
CoreDebug
->DHCSR_Read
. You can see for exampleC_HALT
.C_HALT
. You can see it appearing in the filtered tree.I don't know exactly what's involved to change this. Probably worth to address in a separate PR. If fixable with the chosen GUI library.