feat: select first command argument on autocomplete completion#8046
Open
dclstn wants to merge 1 commit into
Open
feat: select first command argument on autocomplete completion#8046dclstn wants to merge 1 commit into
dclstn wants to merge 1 commit into
Conversation
When completing a chatbot command that takes arguments, insert the first
argument placeholder (e.g. `!shoutout [user]`) and select it so the next
keystroke replaces it. Commands without arguments keep the previous behavior
(`!command ` with the caret at the end).
`twitch.setChatInputValue` gains an optional `selection` ({start, end}) arg.
For a range selection the value and selection are applied through Slate
(select-all -> insertText -> select range), because the controlled value
setters update the editor asynchronously and selecting right after would land
the range on stale/empty content, producing an invalid selection that corrupts
typing. Slate's onChange keeps Twitch's value in sync. Collapsed-caret callers
are unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
dclstn
commented
Jun 10, 2026
| return; | ||
| } | ||
|
|
||
| // TODO: remove setSelectionRange branch after legacy slate is gone |
Collaborator
Author
There was a problem hiding this comment.
Am I safe to remove this legacy selection range?
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.
What
When completing a chatbot command that takes arguments via the command autocomplete, the first argument placeholder is now inserted and selected, so the next keystroke replaces it.
!shoutout→ completes to!shoutout [user]with[user]selected → typing immediately overwrites it.!commandwith the caret at the end.Only the first argument is inserted (commands can have several —
[user]/[word]/[phrase]); the placeholder text is reused fromArgumentDisplayTextByArgumentTypeso it stays consistent with the autocomplete row subtitle. Twitch only for now.How
twitch.setChatInputValue(text, shouldFocus, selection?)gains an optionalselection({start, end}character offsets intotext). When a range is requested, it's applied through Slate rather than the controlled value setters.This matters because Twitch's chat input is a controlled Slate editor whose value prop reaches
editor.childrenasynchronously. Setting the value and then selecting[start, end)immediately lands the range on stale (usually empty) content — an invalid selection that corrupts the next keystrokes (e.g. inserting newlines). A raw DOM selection doesn't work either: the controlled re-render collapses it back to a caret.So for the range case we drive everything through Slate synchronously —
select-all → insertText(text) → select(range)— which populates the content before selecting and keeps Twitch's value in sync viaonChange. Collapsed-caret callers (emote menu, tab completion, mod cards, no-arg commands) are unchanged.Testing
Verified live on
twitch.tv/popout/<channel>/chat: after completion the input shows!shoutout [user]as a single block with a valid selection over[user], and a keystroke replaces it cleanly (!shoutout x) with no extra blocks/newlines.🤖 Generated with Claude Code