Fix terminal font chooser filtering (#6121)
This commit is contained in:
@@ -82,6 +82,35 @@ describe('FontAutocomplete', () => {
|
||||
).toBe('JetBrains Mono')
|
||||
})
|
||||
|
||||
it('shows the full list on focus when the committed font has multiple matching suggestions', async () => {
|
||||
function Harness(): ReactNode {
|
||||
const [value, setValue] = useState('Cascadia Mono')
|
||||
return (
|
||||
<FontAutocomplete
|
||||
value={value}
|
||||
suggestions={['Arial', 'Cascadia Code', 'Cascadia Mono', 'Cascadia Mono PL', 'Consolas']}
|
||||
onChange={setValue}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
await act(async () => {
|
||||
root.render(<Harness />)
|
||||
})
|
||||
|
||||
await act(async () => {
|
||||
getInput().focus()
|
||||
})
|
||||
|
||||
expect(getOptionLabels()).toEqual([
|
||||
'Arial',
|
||||
'Cascadia Code',
|
||||
'Cascadia Mono',
|
||||
'Cascadia Mono PL',
|
||||
'Consolas'
|
||||
])
|
||||
})
|
||||
|
||||
it('keeps typed searches filtered even after the value updates', async () => {
|
||||
function Harness(): ReactNode {
|
||||
const [value, setValue] = useState('Geist')
|
||||
|
||||
@@ -630,12 +630,10 @@ export function FontAutocomplete({
|
||||
() => filterFontSuggestions(suggestions, query),
|
||||
[suggestions, query]
|
||||
)
|
||||
// Why: a committed font fills the input, but typed searches can also mirror
|
||||
// into `value`; only expand exact matches outside an active search session.
|
||||
// Why: the committed font fills the input, but opening the chooser should
|
||||
// still reveal every installed font instead of only fonts sharing that name.
|
||||
const visibleSuggestions =
|
||||
!isFilteringQuery && normalizedQuery === normalizedValue && filteredSuggestions.length <= 1
|
||||
? suggestions
|
||||
: filteredSuggestions
|
||||
!isFilteringQuery && normalizedQuery === normalizedValue ? suggestions : filteredSuggestions
|
||||
|
||||
// Why: sync the highlighted index during render rather than via useEffect so
|
||||
// the correct item is highlighted on the very first paint after open/filter
|
||||
|
||||
Reference in New Issue
Block a user