Chat perf: path-free running border, keystroke- and delta-quiet composer, spinners that do not relayout their list

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 01:21:19 +00:00
parent 2889d59119
commit 7b045e5aab
13 changed files with 534 additions and 60 deletions
@@ -268,7 +268,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
focus: _focus,
canRestore: _composerIsCurrent,
);
_composerShown = _composerShownOf(widget.composer);
widget.composer.addListener(_syncDraft);
widget.composer.addListener(_onComposerChanged);
ChatComposerPasteFocus.register(_focus);
ChatComposerPasteFocus.setOwnsFocusedPaste(
_focus,
@@ -296,8 +298,13 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
void didUpdateWidget(covariant ChatComposerBar oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.composer != widget.composer) {
oldWidget.composer.removeListener(_syncDraft);
widget.composer.addListener(_syncDraft);
oldWidget.composer
..removeListener(_syncDraft)
..removeListener(_onComposerChanged);
widget.composer
..addListener(_syncDraft)
..addListener(_onComposerChanged);
_composerShown = _composerShownOf(widget.composer);
_seenAccepted = widget.composer.composerSendsAccepted;
_syncDraft();
}
@@ -436,6 +443,34 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
);
}
/// What the bar shows from the composer: everything [build] reads from it,
/// with the draft reduced to what the controls show of it. A keystroke
/// changes only the draft, which the field already shows itself, so typing
/// rebuilds the bar only when one of these changes (the first character
/// enables Send, `!` switches to the shell, a `/` command filters the
/// palette).
late Object _composerShown;
static Object _composerShownOf(ChatComposerController composer) {
final draft = composer.draft;
return (
composer.sending,
composer.queued,
composer.error,
composer.draftError,
chatDraftIsShell(draft),
draft.trim().isEmpty,
chatCommandQuery(draft) == null ? null : draft,
);
}
void _onComposerChanged() {
if (!mounted) return;
final shown = _composerShownOf(widget.composer);
if (shown == _composerShown) return;
setState(() => _composerShown = shown);
}
/// Whether a send completes the palette's highlighted row instead of running
/// the draft. A draft that already names a whole command (`/stop`) runs on
/// the first send; only a partial word is completed first.
@@ -468,11 +503,21 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
void _onDraftEdited(String value) {
_requestHarnessCommands(value);
final suggestions = chatCommandSuggestions(value, _harness.commands);
setState(() {
_paletteClosedFor = null;
_dismissCommandReport();
if (_selectedCommand >= suggestions.length) _selectedCommand = 0;
});
final resetHighlight =
_selectedCommand != 0 && _selectedCommand >= suggestions.length;
// Plain typing changes none of this: the bar is left alone, and the
// draft below rebuilds it only if what it shows changes.
if (_paletteClosedFor != null ||
_commandNotice != null ||
_commandOffer != null ||
_commandFailed ||
resetHighlight) {
setState(() {
_paletteClosedFor = null;
_dismissCommandReport();
if (resetHighlight) _selectedCommand = 0;
});
}
unawaited(widget.composer.setDraft(value));
_revealCaretLine(value);
}
@@ -890,7 +935,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
_stopListeningForPaste();
FocusManager.instance.removeEarlyKeyEventHandler(_nativePasteKey);
ChatComposerPasteFocus.unregister(_focus);
widget.composer.removeListener(_syncDraft);
widget.composer
..removeListener(_syncDraft)
..removeListener(_onComposerChanged);
_focusRestorer.dispose();
_focusRequests.dispose();
_text.dispose();
@@ -901,9 +948,8 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: widget.composer,
builder: (context, _) {
return Builder(
builder: (context) {
final composer = widget.composer;
final error = composer.error ?? composer.draftError;
final commands = _paletteCommands();