[BUG] Mods: Input shows empty after Enter and ignores its redrawn value
Version: 2.1.295, macOS, terminal.
What happens
A mod draws an Input whose value comes from its own state. onSubmit receives the text, the mod stores it, and the hook redraws the field with that text as value. The field still shows empty. The next keystroke sends onInput with only that character, so the stored text is overwritten.
What the docs say
plugins/mods/interface.md: "value is the text the field holds when it's drawn, and the user's typing replaces it until your hook draws the field again." So the redraw should show the submitted text.
Repro
const text = atom({ plugin: 'demo', key: 'text' } as const, '')
on('ui.render', { component: 'Pane', requestId: 'demo' }, async ($, e) => {
const { Input } = $.ui.resolve(e)
const value = await read($, text)
return <Input key="field" value={value}
onInput={v => update($, text, () => v)}
onSubmit={v => update($, text, () => v)} />
})
- Open the pane. Type
asdf. Press Enter. - onSubmit gets "asdf". The hook redraws with value="asdf" (checked with $.ui.log). The field shows empty.
- Type
x. onInput gets "x", not "asdfx".
Likely cause
In the terminal field, submit() sets the kept text to "" once the ui.input chain answers. textNow reads the kept text before the value prop (kept ?? saved ?? value). "" is not nullish, so the drawn value never shows.
Workaround
Drawing the field under a new key after each submit shows the value, but the field flickers.
Also seen: a multi-line paste puts newlines into a one-line Input.