πͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(search-bar): always land on a trailing space when commiting the value (#14346)
Nikita Kabardin84a0a32f8cd9
diff --git a/web/src/features/search-bar/README.md b/web/src/features/search-bar/README.mdindex 145d2f17a9..9d7d44d41f 100644--- a/web/src/features/search-bar/README.md+++ b/web/src/features/search-bar/README.md@@ -171,8 +171,22 @@ committedText ββresetToβββΆ store.draft ββ(type/pick/remove)ββ- `components/`:- `SearchComposer.tsx` β the stateful contenteditable CONTROLLER: browserowns selection, mutations flow through `beforeinput`, undo/redo/caret/- autocomplete state. Picking a value advances to "append next"; ArrowRight- at the end of the query exits the last token. Paste inserts cleaned text+ autocomplete state. **Trailing space is the "start the next filter"+ affordance, applied uniformly.** The RESTING draft carries a trailing space+ when non-empty: it is baked into the URLβdraft derivation+ (`useEventsSearchBar`'s `restingDraft`, also returned by `commit`), so it is+ present from the first paint. That is why clicking past the text β or landing+ after a commit β never has to MUTATE the draft to insert it (which flickered+ the caret from inside the last pill to after a freshly-added space); the+ caret just lands after the already-present space. Completing a filter at the+ end of the query β a pick-at-end (value or ready-to-run suggestion),+ ArrowRight-at-end, a click past the text, or Enter that commits with the+ caret at the end β leaves the caret AFTER that trailing space (outside the+ last pill), reopening field suggestions. (The space is trimmed on commit, so+ it never reaches the filter state; the commit echo's `resetTo` no-ops because+ it's AST-equal to the committed form.) Picks that still need input β a bare+ `field:` key, a `metadata.`/`scores.` prefix, an open `tags:(` group β and+ mid-query edits keep the caret in place instead. Paste inserts cleaned text(line-breaks/tabs β spaces) into the draft, which auto-tokenizes like typedtext β there is no special structured-vs-raw paste branch. Editing avalue works by placing the caret in it (click/arrow): the value-stagediff --git a/web/src/features/search-bar/components/EventsSearchBarRow.tsx b/web/src/features/search-bar/components/EventsSearchBarRow.tsxindex d11fb3d368..d4524e8f17 100644--- a/web/src/features/search-bar/components/EventsSearchBarRow.tsx+++ b/web/src/features/search-bar/components/EventsSearchBarRow.tsx@@ -17,7 +17,7 @@ export function EventsSearchBarRow({}: {projectId: string;store: SearchBarStore;- commit: () => boolean;+ commit: () => string | null;observed: ObservedOptions | undefined;}) {return (diff --git a/web/src/features/search-bar/components/SearchComposer.tsx b/web/src/features/search-bar/components/SearchComposer.tsxindex d521e7de75..dd121f9405 100644--- a/web/src/features/search-bar/components/SearchComposer.tsx+++ b/web/src/features/search-bar/components/SearchComposer.tsx@@ -42,6 +42,7 @@ import {useSearchBarStoreApi,useSearchBarCommit,} from "@/src/features/search-bar/store/SearchBarStoreProvider";+import { draftsSemanticallyEqual } from "@/src/features/search-bar/store/searchBarStore";import { AutocompletePopover } from "@/src/features/search-bar/components/AutocompletePopover";import {ComposerTokens,@@ -59,7 +60,8 @@ const LISTBOX_ID = "search-bar-listbox";const WORD_JOINER_RE = new RegExp(WORD_JOINER, "g");// Stable empty recents reference so the plan memo doesn't churn when recents-// are intentionally suppressed (popover closed or append mode).+// are intentionally suppressed (popover closed, or a non-empty draft β recents+// show only on an empty bar; see the recents memo).const NO_RECENTS: string[] = [];// Surrogate-pair guards: a non-BMP codepoint (emoji, supplementary CJK) is two@@ -301,7 +303,6 @@ export function SearchComposer({);const [autocompleteOpen, setAutocompleteOpen] = React.useState(false);- const [appendIntent, setAppendIntent] = React.useState(false);const [highlightedOptionId, setHighlightedOptionId] = React.useState<string | null>(null);@@ -328,23 +329,26 @@ export function SearchComposer({[observed],);- // Read recents only while the popover is open (avoids a synchronous- // localStorage read on every keystroke/selection render), and not in append- // mode β a recent is a complete query, not a token to append, so showing- // them there would let a pick silently replace the in-progress draft.+ // Recents are a COMPLETE saved query: picking one REPLACES the whole draft+ // (pickOption's recent branch). Only offer them on a truly empty bar, where+ // there's nothing to clobber β NOT at a trailing-space landing after the user+ // has built up filters, where a stray pick would silently wipe them. Gating+ // on an empty draft also keeps the synchronous localStorage read off the+ // keystroke path (a non-empty draft returns the stable NO_RECENTS reference,+ // so the plan memo doesn't churn).const recents = React.useMemo(() =>- autocompleteOpen && !appendIntent+ autocompleteOpen && draft.trim().length === 0? getRecentSearches(projectId): NO_RECENTS,- [autocompleteOpen, appendIntent, projectId],+ [autocompleteOpen, draft, projectId],);const plan: CompletionPlan | null =autocompleteOpen && selectionCollapsed? planInputCompletions({- input: appendIntent ? "" : draft,- caret: appendIntent ? 0 : Math.min(caret, draft.length),+ input: draft,+ caret: Math.min(caret, draft.length),observed,recents,currentQueryText: draft,@@ -519,15 +523,11 @@ export function SearchComposer({setSelectionSnapshot((prev) =>prev.start === next.start && prev.end === next.end ? prev : next,);- // Moving the caret away from the end abandons "new entry" intent.- if (next.start !== next.end || next.end !== draftRef.current.length) {- setAppendIntent(false);- }};document.addEventListener("selectionchange", onSelectionChange);return () =>document.removeEventListener("selectionchange", onSelectionChange);- }, [draftRef]);+ }, []);// Safety net for mutations that bypass beforeinput (IME composition,// browser quirks): re-read the DOM and reproject. Skipped mid-composition@@ -550,43 +550,24 @@ export function SearchComposer({const from = Math.min(offsets.start, offsets.end);const to = Math.max(offsets.start, offsets.end);const current = draftRef.current;- const shouldAppend =- appendIntent &&- insert.length > 0 &&- from === to &&- from === current.length;- const prefix =- shouldAppend &&- current.trim().length > 0 &&- !/\s$/.test(current) &&- !/^\s/.test(insert)- ? " "- : "";- const next = replaceRange(current, from, to, prefix + insert);- // Append intent is one-shot: any edit consumes it.- setAppendIntent(false);+ const next = replaceRange(current, from, to, insert);// Plain single-character typing at a collapsed caret coalesces into one// undo step; spaces and replacements start a fresh step.- const coalesce =- insert.length === 1 &&- !/\s/.test(insert) &&- prefix === "" &&- from === to;+ const coalesce = insert.length === 1 && !/\s/.test(insert) && from === to;setDraftWithSelection(next,- from + prefix.length + insert.length,+ from + insert.length,undefined,coalesce ? "coalesce" : "push",);openAutocompleteAfterEdit();},- [appendIntent, draftRef, openAutocompleteAfterEdit, setDraftWithSelection],+ [draftRef, openAutocompleteAfterEdit, setDraftWithSelection],);const applyTextDeletion = React.useCallback((range: { from: number; to: number }) => {if (range.from === range.to) return;- setAppendIntent(false);setDraftWithSelection(replaceRange(draftRef.current, range.from, range.to, ""),range.from,@@ -678,30 +659,66 @@ export function SearchComposer({return () => root.removeEventListener("beforeinput", onBeforeInput);}, [applyTextDeletion, applyTextInsert, draftRef, redoRef, undoRef]);- const commit = React.useCallback(() => {- const root = rootRef.current;- const actions = storeApi.getState().actions;- // Sync any DOM-only edit (IME, browser quirk) into the store before- // committing. Compare against the live store draft, not a render snapshot,- // and rely on zustand's synchronous set so the commit reads the new value.- if (root !== null) {- const text = textFromRoot(root);- if (text !== storeApi.getState().draft) actions.setDraft(text);- }- // The container validates, lowers, and writes the filter state; on failure- // it reveals the invalid draft. A successful commit re-derives the- // committed text and the resetTo effect canonicalizes the draft.- const ok = commitToFilterState();- if (ok) {- setAppendIntent(false);- setAutocompleteOpen(false);+ const commit = React.useCallback(+ (advanceToTrailingSpace = false) => {+ const root = rootRef.current;+ const actions = storeApi.getState().actions;+ // Sync any DOM-only edit (IME, browser quirk) into the store before+ // committing. Compare against the live store draft, not a render snapshot,+ // and rely on zustand's synchronous set so the commit reads the new value.+ let caretAtEnd = false;+ if (root !== null) {+ const text = textFromRoot(root);+ const sel = selectionOffsets(root);+ caretAtEnd =+ sel.start === sel.end && sel.end === text.length && text.length > 0;+ if (text !== storeApi.getState().draft) actions.setDraft(text);+ }+ // The container validates, lowers, and writes the filter state; on failure+ // it reveals the invalid draft and returns null. On success it returns the+ // CANONICAL committed text in its RESTING form (trailing space when+ // non-empty) β the same text the resetTo effect re-derives.+ const committedText = commitToFilterState();+ if (committedText === null) return;setHighlightedOptionId(null);// Close the undo-coalesce window at the commit boundary, mirroring undo()/// redo()/the external-draft sync. Otherwise a post-commit keystroke keeps// coalescing across the commit, so Cmd+Z jumps past the natural break.historyRef.current.coalesce = null;- }- }, [storeApi, commitToFilterState]);+ if (advanceToTrailingSpace && caretAtEnd) {+ // Enter committed at the END of the query: land on the resting trailing+ // space OUTSIDE the last block, field suggestions open β same as a+ // pick-at-end / ArrowRight-at-end. Prefer the user's TYPED form (keeps a+ // typed alias like `env:` instead of expanding it to `environment:`) when+ // it is semantically identical to the committed text. When the commit+ // RESTRUCTURED the query (e.g. reordered free text after filters) the+ // typed form differs, so use the canonical committed text. Either way the+ // text we set is AST-/string-equal to what resetTo re-derives, so the+ // echo no-ops and the caret stays at the end. Both already carry the+ // resting trailing space. Mid-query commits and blur keep the caret put.+ const typed = storeApi.getState().draft;+ const typedSpaced = /\s$/.test(typed) ? typed : `${typed} `;+ const restingText = draftsSemanticallyEqual(+ typedSpaced,+ committedText,+ scoreTypes,+ )+ ? typedSpaced+ : committedText;+ // Skip the write when the draft is already the resting text (e.g. Enter+ // on a query that already ends in a space) β otherwise it pushes a no-op+ // undo entry and the first Cmd+Z does nothing. Mirrors the no-op guards+ // in the ArrowRight-at-end and click-past-end handlers.+ if (restingText !== typed) {+ setDraftWithSelection(restingText, restingText.length);+ }+ setAutocompleteOpen(true);+ } else {+ setAutocompleteOpen(false);+ }+ },+ [storeApi, commitToFilterState, setDraftWithSelection, scoreTypes],+ );// Structured edits (autocomplete picks, chip removal) apply immediately, but// a pick can leave the draft mid-completion (e.g. "level:" after a field@@ -718,7 +735,13 @@ export function SearchComposer({const currentPlan = planRef.current;if (currentPlan === null) return;if (option.kind === "recent") {- setDraftWithSelection(option.query, option.query.length);+ // Land in the RESTING (trailing-space) form like every other commit+ // landing, so a later click past the text doesn't have to mutate the+ // draft (= the caret flicker this PR removed). A recent is stored+ // canonical/trimmed, so one space never doubles.+ const resting =+ option.query.length === 0 ? option.query : `${option.query} `;+ setDraftWithSelection(resting, resting.length);// A recent is a COMPLETE query the user explicitly picked, so it gets// the same Enter/blur reveal semantics: commit if valid, otherwise// reveal the red invalid state instead of silently no-op'ing (e.g. a@@ -726,7 +749,6 @@ export function SearchComposer({const state = storeApi.getState();if (state.draftValid) commitToFilterState();else state.actions.revealInvalid();- setAppendIntent(false);setAutocompleteOpen(false);return;}@@ -751,28 +773,9 @@ export function SearchComposer({// bare prefix would splice in front of it (`meta:foo` -> broken// `metadata.:foo`). Consume the whole term so the user re-picks the key// from observed options instead.- if (!appendIntent && option.fieldId.endsWith(".") && colonFollows) {+ if (option.fieldId.endsWith(".") && colonFollows) {replaceTo = termAt(current, currentPlan.from)?.to ?? currentPlan.to;}- // Re-picking the same field that's already the last token: collapse to- // a no-op instead of double-appending (`β¦ level:` + pick `level` would- // give `β¦ level: level:`). The matched suffix must sit at a TOKEN- // boundary (start-of-draft or after whitespace) β a bare `endsWith`- // false-fires when the field name is a raw suffix of a longer key- // (`metadata.level:` + pick `level`), silently discarding the pick.- const trimmed = current.trimEnd();- if (- appendIntent &&- trimmed.endsWith(insert) &&- (trimmed.length === insert.length ||- /\s/.test(trimmed[trimmed.length - insert.length - 1] ?? " "))- ) {- setDraftWithSelection(current, trimmed.length);- setAppendIntent(false);- setAutocompleteOpen(true);- setHighlightedOptionId(null);- return;- }} else if (option.kind === "value") {insert = serializeValue(option.value);keepOpen = currentPlan.keepOpenOnPick ?? false;@@ -800,9 +803,7 @@ export function SearchComposer({// for the next filter, instead of leaving the caret inside the pill where// typing would edit what was just picked. Picks that invite more input (a// bare `field:` key, a `metadata.` prefix, an open `tags:(` group), grouped- // value entry, and mid-query edits (non-whitespace follows) stay put. This- // reuses the space-ending-insert path rather than the deferred appendIntent- // that rendered the caret inside the pill with no space.+ // value entry, and mid-query edits (non-whitespace follows) stay put.const grouped = currentPlan.keepOpenOnPick ?? false;const invitesMoreInput =option.kind === "field" || // a `field:` key always needs a value next@@ -816,22 +817,13 @@ export function SearchComposer({if (completesFilterAtEnd) {insert += " ";// Consume any existing trailing whitespace so the space never doubles.- if (!appendIntent) replaceTo = current.length;+ replaceTo = current.length;keepOpen = true;}- const prefix =- appendIntent && current.trim().length > 0 && !/\s$/.test(current)- ? " "- : "";- const next = appendIntent- ? `${current}${prefix}${insert}`- : replaceRange(current, replaceFrom, replaceTo, insert);- const caretAt = appendIntent- ? current.length + prefix.length + insert.length- : replaceFrom + insert.length;+ const next = replaceRange(current, replaceFrom, replaceTo, insert);+ const caretAt = replaceFrom + insert.length;setDraftWithSelection(next, caretAt);- setAppendIntent(false);setAutocompleteOpen(keepOpen);setHighlightedOptionId(null);// Apply when the pick produced a valid query; a partial draft (e.g. a@@ -844,7 +836,6 @@ export function SearchComposer({}},[- appendIntent,draftRef,planRef,setDraftWithSelection,@@ -860,7 +851,6 @@ export function SearchComposer({storeApi.getState().actions.removeChipSpan(segment.from, segment.to);commitStructuredEdit();setHoveredTokenId(null);- setAppendIntent(false);setAutocompleteOpen(false);setHighlightedOptionId(null);},@@ -931,16 +921,14 @@ export function SearchComposer({} else {setSelectionRange(root, target, target);}- setAppendIntent(false);return;}// ArrowRight at the very end of the query inserts a trailing space to start- // a NEW token β matching the muscle-memory of typing a space at the end.- // (The old behavior set appendIntent and nudged the caret past the trailing- // joiner, which read as a dead keypress.) Skip when- // the draft already ends in whitespace so a repeat press doesn't pile up- // spaces. The trailing space is trimmed on commit.+ // a NEW token β matching the muscle-memory of typing a space at the end, and+ // the same fresh-token landing as a click past the end or a pick-at-end.+ // Skip when the draft already ends in whitespace so a repeat press doesn't+ // pile up spaces. The trailing space is trimmed on commit.if (event.key === "ArrowRight" &&!event.shiftKey &&@@ -955,7 +943,6 @@ export function SearchComposer({event.preventDefault();const next = `${draft} `;setDraftWithSelection(next, next.length);- setAppendIntent(false);setAutocompleteOpen(true);setHighlightedOptionId(null);return;@@ -1006,7 +993,6 @@ export function SearchComposer({if (target === end) return; // at an edge β native no-opevent.preventDefault();setSelectionRange(root, target, target);- setAppendIntent(false);return;}@@ -1023,14 +1009,16 @@ export function SearchComposer({pickOption(option);return;}- commit();+ // No suggestion to take: commit the query. When the caret is at the end,+ // land on a fresh trailing space so the next filter starts outside the+ // last block (matches a pick-at-end / ArrowRight-at-end).+ commit(true);return;}if (event.key === "Escape") {if (autocompleteOpen) {event.preventDefault();- setAppendIntent(false);setAutocompleteOpen(false);}return;@@ -1123,7 +1111,6 @@ export function SearchComposer({const onBlur = () => {setEditorFocused(false);commit();- setAppendIntent(false);setAutocompleteOpen(false);};@@ -1138,15 +1125,27 @@ export function SearchComposer({if (root === null) return;const { start, end } = selectionOffsets(root);if (start !== end) return; // drag selection β selection is for editing, not suggesting- const append =+ const pastEnd =draft.length > 0 && isPastTextEnd(root, event.clientX, event.clientY);- if (append && end !== draft.length) {- // The browser put the caret on the nearest character of a wrapped line;- // a past-end click still means append at the very end.- setSelectionRange(root, draft.length, draft.length);- setSelectionSnapshot({ start: draft.length, end: draft.length });+ if (pastEnd) {+ // A click in the empty space past the text means "start a new entry":+ // land on a trailing space OUTSIDE the last block (adding one if the query+ // doesn't already end in whitespace), with field suggestions open β the+ // same fresh-token landing as ArrowRight-at-end and a pick-at-end. Without+ // the physical space the browser drops the caret inside the last pill, so+ // typing would edit what's there. The space is trimmed on commit.+ if (/\s$/.test(draft)) {+ setSelectionRange(root, draft.length, draft.length);+ setSelectionSnapshot({ start: draft.length, end: draft.length });+ } else {+ const next = `${draft} `;+ setDraftWithSelection(next, next.length);+ }+ setAutocompleteOpen(true);+ setHighlightedOptionId(null);+ return;}- if (!append && end < draft.length && /\s/.test(draft[end] ?? "")) {+ if (end < draft.length && /\s/.test(draft[end] ?? "")) {// Additive gap affordance: a click in the whitespace BETWEEN tokens// (geometrically past the previous token's right edge, not on the token// or its padding) nudges the collapsed caret across the whitespace run,@@ -1176,7 +1175,6 @@ export function SearchComposer({setSelectionSnapshot({ start: next, end: next });}}- setAppendIntent(append);setAutocompleteOpen(true);setHighlightedOptionId(null);};diff --git a/web/src/features/search-bar/hooks/useEventsSearchBar.ts b/web/src/features/search-bar/hooks/useEventsSearchBar.tsindex 0b46171279..8aefd11ac5 100644--- a/web/src/features/search-bar/hooks/useEventsSearchBar.ts+++ b/web/src/features/search-bar/hooks/useEventsSearchBar.ts@@ -36,6 +36,20 @@ function sameScopes(a: TracingSearchType[], b: TracingSearchType[]): boolean {return a.every((s) => bs.has(s));}+/**+ * The resting draft carries a trailing space when non-empty β the "ready for the+ * next filter" affordance. Baking it into the DERIVED committed text (and the+ * value `commit` returns) means it is present from the first paint, so clicking+ * past the text β or landing after a commit β never has to MUTATE the draft to+ * insert it. Mutating on click flickered the caret from inside the last pill to+ * after a freshly-inserted space. It is trimmed on the next commit (planCommit)+ * and ignored by resetTo's AST compare, so it never reaches the filter state and+ * never loops.+ */+function restingDraft(text: string): string {+ return text.length === 0 ? text : `${text} `;+}+/** Column + key identity, so keyed filters (metadata.<k>, scores.<k>) on the* same column don't collide while plain columns dedupe by column alone. */function filterIdentity(f: FilterState[number]): string {@@ -64,7 +78,7 @@ export function useEventsSearchBar({setFilterState: (filters: FilterState) => void;setSearchQuery: (query: string | null) => void;setSearchType: (type: TracingSearchType[]) => void;-}): { store: SearchBarStore; commit: () => boolean } {+}): { store: SearchBarStore; commit: () => string | null } {// Latest observed options, read inside commit and by the store's draft// validation so both route `scores.<name>` by the same observed score type.const observedRef = useRef(observed);@@ -83,7 +97,7 @@ export function useEventsSearchBar({() => filterStateToQueryText(filterState, { searchQuery, searchType }),[filterState, searchQuery, searchType],);- const committedText = derived.text;+ const committedText = restingDraft(derived.text);const skippedFiltersRef = useRef(derived.skippedFilters);skippedFiltersRef.current = derived.skippedFilters;@@ -116,14 +130,14 @@ export function useEventsSearchBar({const searchTypeRef = useRef(searchType);searchTypeRef.current = searchType;- const commit = useCallback((): boolean => {+ const commit = useCallback((): string | null => {const result = planCommit(store.getState().draft,scoreTypeContextFromObserved(observedRef.current),);if (result.status === "invalid") {store.getState().actions.revealInvalid();- return false;+ return null;}const { setFilterState, setSearchQuery, setSearchType } = applyRef.current;// Re-attach the filters the grammar can't represent so the commit never@@ -134,9 +148,9 @@ export function useEventsSearchBar({const preserved = skippedFiltersRef.current.filter((f) => !producedKeys.has(filterIdentity(f)),);- setFilterState(- preserved.length > 0 ? [...result.filters, ...preserved] : result.filters,- );+ const committedFilters =+ preserved.length > 0 ? [...result.filters, ...preserved] : result.filters;+ setFilterState(committedFilters);setSearchQuery(result.searchQuery);// Only write searchType when it actually changed. planCommit coerces a// draft with no scope token to the default (`["id","content"]` β ids+names@@ -149,7 +163,17 @@ export function useEventsSearchBar({if (result.canonical.length > 0) {recordRecentSearch(projectId, result.canonical);}- return true;+ // Return the CANONICAL committed text in its RESTING form (trailing space) β+ // exactly what the resetTo effect re-derives on the next render (same+ // filters + searchQuery/searchType). The composer drops the caret after it,+ // so the echo string-compares equal and the space survives even when the+ // commit reorders the query (e.g. `refund level:ERROR` β `level:ERROR refund`).+ return restingDraft(+ filterStateToQueryText(committedFilters, {+ searchQuery: result.searchQuery,+ searchType: result.searchType,+ }).text,+ );}, [store, projectId]);return { store, commit };diff --git a/web/src/features/search-bar/store/SearchBarStoreProvider.tsx b/web/src/features/search-bar/store/SearchBarStoreProvider.tsxindex 3f565f3781..22666db3bd 100644--- a/web/src/features/search-bar/store/SearchBarStoreProvider.tsx+++ b/web/src/features/search-bar/store/SearchBarStoreProvider.tsx@@ -9,8 +9,9 @@ import {type SearchBarContextValue = {store: SearchBarStore;/** Apply the current draft to the table's filter state (single source of- * truth). Returns false and reveals diagnostics when the draft is invalid. */- commit: () => boolean;+ * truth). Returns the canonical committed text on success, or null (and+ * reveals diagnostics) when the draft is invalid. */+ commit: () => string | null;};const SearchBarContext = createContext<SearchBarContextValue | null>(null);@@ -22,7 +23,7 @@ export function SearchBarStoreProvider({}: {children: ReactNode;store: SearchBarStore;- commit: () => boolean;+ commit: () => string | null;}) {const value = useMemo(() => ({ store, commit }), [store, commit]);return (@@ -50,6 +51,6 @@ export function useSearchBarStore<TValue>(return useStore(useSearchBarContext().store, selector);}-export function useSearchBarCommit(): () => boolean {+export function useSearchBarCommit(): () => string | null {return useSearchBarContext().commit;}diff --git a/web/src/features/search-bar/store/searchBarStore.ts b/web/src/features/search-bar/store/searchBarStore.tsindex 1c1210514f..f7706ef188 100644--- a/web/src/features/search-bar/store/searchBarStore.ts+++ b/web/src/features/search-bar/store/searchBarStore.ts@@ -19,6 +19,28 @@ import { parse, type Diagnostic } from "../lib/langQ";import { scoreTypeContextEqual } from "../lib/observed-options";import { validateQuery } from "../lib/validate";+/**+ * True when two query texts are SEMANTICALLY identical β same AST after folding+ * derived negation β so they differ only in rawKey/alias casing (`env`β+ * `environment`), value format (`2.0`β`2`, `TRUE`β`true`), the exact operator+ * (`level:=ERROR`β`level:ERROR`), folded negation (`-latency:>2`β`latency:<=2`),+ * or trailing whitespace. The shared parity check used by BOTH `resetTo` (keep+ * the user's typed form on a commit echo) and the composer's commit-advance+ * (decide whether the typed draft can stand, or the canonical must be used so+ * the resetTo echo still no-ops and the caret stays put). Keeping it in one+ * place stops those two decisions from drifting.+ */+export function draftsSemanticallyEqual(+ a: string,+ b: string,+ scoreTypes?: ScoreTypeContext,+): boolean {+ return astEquals(+ foldDerivedNegation(parse(a).ast, scoreTypes),+ foldDerivedNegation(parse(b).ast, scoreTypes),+ );+}+export type SearchBarStoreState = {/** Live editing buffer. */draft: string;@@ -112,13 +134,7 @@ export function createSearchBarStore(// Number-normalize numeric (not categorical) score values. It preserves// structure/order, so free-text canonicalization is kept.const scoreTypes = resolveScoreTypes?.();- if (- astEquals(- foldDerivedNegation(parse(committedText).ast, scoreTypes),- foldDerivedNegation(parse(draft).ast, scoreTypes),- )- )- return;+ if (draftsSemanticallyEqual(committedText, draft, scoreTypes)) return;writeDraft(committedText);},removeChipSpan: (from, to) => {