fix: inspector Escape deletes bound text#50
Merged
Conversation
BareDOM's x-search-field wraps an `<input type="search">`. Browsers treat Escape on type=search as a clear gesture — they wipe the value AND fire an `input` event, which BareDOM forwards as `x-search-field-input` with value="". Every inspector text widget that commits on input then writes "" back to the doc, silently erasing the user's text on every accidental Esc press inside an attribute editor, layout field, name field, css-var, seed cell, bind picker, or add-action form. Wrap every inspector x-search-field through a single `search-field` helper that attaches a keydown listener and preventDefaults Escape, so the browser never clears the input and the bogus commit never happens. render-field's generic widget creation routes through it when widget-tag is :x-search-field, so any future field spec that reuses the dispatcher inherits the fix. The palette's filter input is left unchanged: there, clearing on Escape is the desired UX (it's a filter, not a binding). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Pressing Escape inside any inspector text input silently erased the bound doc value. Affects every `x-search-field` widget in the inspector: attribute editors, layout fields (`:width` / `:height` / `:padding` / `:margin` / free-coord), name field, CSS-var editors, seed cells, field / action bind pickers, the add-action form, and the `:text` pseudo-property editor for x-typography / x-button. The CLAUDE.md smoke test for the inline-edit / inspector flow failed on this — clearest repro: select an x-typography in the SaaS template, type into the inspector text input, hit Esc → element becomes empty.
Root cause
BareDOM's `x-search-field` wraps an `` inside its shadow DOM (see baredom-2.9.0 `baredom/components/x_search_field/x_search_field.cljs`). Browsers handle Escape on `type="search"` as a clear gesture: they wipe the value and fire a native `input` event. BareDOM's input handler forwards that as `x-search-field-input` with `value=""`. The inspector's commit-on-input wiring then writes `""` back to the doc via `ops/set-text` (or `ops/set-attr` for attribute-mode text), erasing the user's text — every time, on any Esc press inside any of those inputs.
Fix
A single `search-field` helper at the top of `bareforge.ui.inspector` wraps `u/el :x-search-field` and attaches a `keydown` listener that `preventDefault`s Escape. Browser never clears, bogus commit never fires. All 12 inspector creation sites route through it; `render-field`'s generic widget dispatcher uses it when `widget-tag` is `:x-search-field`, so any future field spec that reuses the dispatcher inherits the fix automatically.
The palette filter input (`bareforge.ui.palette`) is intentionally untouched — it's a filter, not a binding, and clear-on-Escape is desired UX there.
Test plan
🤖 Generated with Claude Code