fix(new-workspace): stop UI flashing when typing ahead of search (#11436)
* fix(new-workspace): stop UI flashing when typing ahead of search Hold branch results while queries settle, show the spinner only on initial load, use stable cmdk values, and guard selections against stale rows. This prevents the highlight from jumping around when typing faster than the debounced search settles. * fix(new-workspace): keep dropdown visible while typing within settled qu Hold the last search results while the user extends or trims the query, only hiding them when the query diverges completely. This prevents the dropdown from flashing empty between debounced keystrokes and removes the guard that made provider rows unselectable during typing. * fix(new-workspace): align held provider results with live typing Cap prefix hold by length delta, hide GitHub/GitLab/Linear rows when the field is cleared ahead of debounce, and re-sync the cmdk arm when search settles so the highlight cannot lag the resolved selection.
This commit is contained in:
@@ -28,9 +28,14 @@ export function resolveSmartWorkspaceCommandValue({
|
||||
return currentValue
|
||||
}
|
||||
|
||||
// Why: freeze the arm while the live input is ahead of debounced search so the
|
||||
// highlight does not thrash to use-name / empty / first-row on every keystroke.
|
||||
if (isQueryStale) {
|
||||
if (rows.some((row) => row.value === currentValue)) {
|
||||
return currentValue
|
||||
}
|
||||
const typedTextRow = rows.find((row) => row.kind === 'use-name' || row.kind === 'create-branch')
|
||||
return typedTextRow?.value ?? ''
|
||||
return typedTextRow?.value ?? rows[0]?.value ?? ''
|
||||
}
|
||||
|
||||
if (sourceIntent === 'github') {
|
||||
|
||||
@@ -75,6 +75,29 @@ export function getBranchSearchRequest({
|
||||
return { repoId: selectedRepoId, query: trimmedQuery, limit }
|
||||
}
|
||||
|
||||
/**
|
||||
* Why: provider arrays lag the live input (200ms debounce). Keep them while the
|
||||
* user is still typing, but hide immediately when the field is cleared so prior
|
||||
* non-empty results cannot stay selectable until debounce catches up.
|
||||
*/
|
||||
export function getVisibleHeldProviderResults<T>({
|
||||
items,
|
||||
value,
|
||||
debouncedQuery
|
||||
}: {
|
||||
items: readonly T[]
|
||||
value: string
|
||||
debouncedQuery: string
|
||||
}): T[] {
|
||||
if (!isSmartWorkspaceSourceQueryWithinLimit(value)) {
|
||||
return []
|
||||
}
|
||||
if (value.trim() === '' && debouncedQuery.trim() !== '') {
|
||||
return []
|
||||
}
|
||||
return items.slice()
|
||||
}
|
||||
|
||||
export function getVisibleBranchResults({
|
||||
branches,
|
||||
mode,
|
||||
@@ -93,16 +116,51 @@ export function getVisibleBranchResults({
|
||||
if (!isSmartWorkspaceSourceQueryWithinLimit(value)) {
|
||||
return []
|
||||
}
|
||||
const currentQuery = value.trim()
|
||||
if (mode !== 'branches' && mode !== 'smart') {
|
||||
return []
|
||||
}
|
||||
if (!selectedRepoId || resultRepoId !== selectedRepoId || resultQuery !== currentQuery) {
|
||||
if (!selectedRepoId || resultRepoId !== selectedRepoId || resultQuery === null) {
|
||||
return []
|
||||
}
|
||||
const currentQuery = value.trim()
|
||||
// Why: hold the last settled list while the user extends/trims the query so the
|
||||
// dropdown does not blank between debounced keystrokes. Drop the hold when the
|
||||
// query diverges (e.g. "feat" → "bug") so unrelated rows do not linger.
|
||||
if (currentQuery === '') {
|
||||
return resultQuery === '' ? branches : []
|
||||
}
|
||||
if (!shouldHoldSourceResultsForQuery({ resultQuery, value: currentQuery })) {
|
||||
return []
|
||||
}
|
||||
return branches
|
||||
}
|
||||
|
||||
/** Max |live − settled| length while still treating a prefix as "still typing". */
|
||||
const SOURCE_RESULT_HOLD_MAX_DELTA = 4
|
||||
|
||||
/**
|
||||
* Why: prefix-only hold lets a settled "f" stick under "fix-unrelated-…" for the
|
||||
* whole next debounce. Cap the length delta so hold covers fast typing, not long
|
||||
* continuations of a short settled query.
|
||||
*/
|
||||
export function shouldHoldSourceResultsForQuery({
|
||||
resultQuery,
|
||||
value
|
||||
}: {
|
||||
resultQuery: string
|
||||
value: string
|
||||
}): boolean {
|
||||
const currentQueryKey = value.trim().toLowerCase()
|
||||
const resultQueryKey = resultQuery.trim().toLowerCase()
|
||||
if (resultQueryKey === currentQueryKey) {
|
||||
return true
|
||||
}
|
||||
if (!currentQueryKey.startsWith(resultQueryKey) && !resultQueryKey.startsWith(currentQueryKey)) {
|
||||
return false
|
||||
}
|
||||
return Math.abs(currentQueryKey.length - resultQueryKey.length) <= SOURCE_RESULT_HOLD_MAX_DELTA
|
||||
}
|
||||
|
||||
export function buildSmartWorkspaceSourceRows({
|
||||
branches,
|
||||
githubItems,
|
||||
@@ -130,7 +188,8 @@ export function buildSmartWorkspaceSourceRows({
|
||||
const trimmed = value.trim()
|
||||
const nextRows: SmartWorkspaceSourceRow[] = []
|
||||
if (trimmed && mode === 'smart') {
|
||||
nextRows.push({ kind: 'use-name', value: `use-name-${trimmed}`, name: trimmed })
|
||||
// Why: stable cmdk value — embedding the query remounted the row every keystroke.
|
||||
nextRows.push({ kind: 'use-name', value: 'use-name', name: trimmed })
|
||||
}
|
||||
if (mode === 'text') {
|
||||
return nextRows
|
||||
@@ -159,7 +218,7 @@ export function buildSmartWorkspaceSourceRows({
|
||||
(branch) => branch.refName === trimmed || branch.localBranchName === trimmed
|
||||
)
|
||||
if (trimmed && mode === 'branches' && !branchExactMatch) {
|
||||
nextRows.push({ kind: 'create-branch', value: `create-branch-${trimmed}`, name: trimmed })
|
||||
nextRows.push({ kind: 'create-branch', value: 'create-branch', name: trimmed })
|
||||
}
|
||||
nextRows.push(
|
||||
...branches.map((branch) => ({
|
||||
|
||||
Reference in New Issue
Block a user