Merge branch 'main' into run-worktrees

This commit is contained in:
2026-11-10 16:06:40 +00:00
5 changed files with 121 additions and 2 deletions
@@ -126,6 +126,7 @@ class ChatComposerBar extends StatefulWidget {
this.commands,
this.paste,
this.pasteTarget = true,
this.ownsPasteWhenFocused = false,
this.backgroundTasks,
this.runShell,
this.placeholder = chatComposerPlaceholder,
@@ -165,6 +166,11 @@ class ChatComposerBar extends StatefulWidget {
/// True only for the active visible pane.
final bool pasteTarget;
/// While its field has the keyboard this composer takes a paste (files
/// too) even when it is not [pasteTarget], and the paste target leaves it
/// alone: a floating chat over the tiled ones.
final bool ownsPasteWhenFocused;
final Widget? backgroundTasks;
/// Runs a `!` draft's command in the chat's folder (never a prompt);
@@ -237,6 +243,10 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
);
widget.composer.addListener(_syncDraft);
ChatComposerPasteFocus.register(_focus);
ChatComposerPasteFocus.setOwnsFocusedPaste(
_focus,
widget.ownsPasteWhenFocused,
);
FocusManager.instance.addEarlyKeyEventHandler(_nativePasteKey);
_listenForPaste();
unawaited(widget.composer.loadDraft());
@@ -264,6 +274,12 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
_seenAccepted = widget.composer.composerSendsAccepted;
_syncDraft();
}
if (oldWidget.ownsPasteWhenFocused != widget.ownsPasteWhenFocused) {
ChatComposerPasteFocus.setOwnsFocusedPaste(
_focus,
widget.ownsPasteWhenFocused,
);
}
if (oldWidget.composer != widget.composer ||
oldWidget.paste != widget.paste ||
oldWidget.pasteTarget != widget.pasteTarget) {
@@ -301,7 +317,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
/// default behaviour, so an inactive pane is never allowed to swallow it.
bool _canAcceptPaste() =>
mounted &&
widget.pasteTarget &&
(widget.ownsPasteWhenFocused && _focus.hasFocus ||
widget.pasteTarget &&
!ChatComposerPasteFocus.otherOwnerHasFocus(_focus)) &&
_composerIsCurrent() &&
!ChatComposerPasteFocus.anotherEditableHasFocus &&
!widget.composer.sending;
@@ -9,13 +9,28 @@ abstract final class ChatComposerPasteFocus {
static final Set<FocusNode> _inputs = {};
static void register(FocusNode focus) => _composers.add(focus);
static void unregister(FocusNode focus) => _composers.remove(focus);
static void unregister(FocusNode focus) {
_composers.remove(focus);
_owners.remove(focus);
}
/// An input that is not an [EditableText] (a shell command's terminal)
/// registers its focus here: a paste while it has focus is its own.
static void registerInput(FocusNode focus) => _inputs.add(focus);
static void unregisterInput(FocusNode focus) => _inputs.remove(focus);
/// Composers that own a paste while they have the keyboard, even when they
/// are not the paste target (a floating chat's).
static final Set<FocusNode> _owners = {};
static void setOwnsFocusedPaste(FocusNode focus, bool owns) =>
owns ? _owners.add(focus) : _owners.remove(focus);
/// Whether a composer other than [mine] owns the paste now: it has the
/// keyboard and owns a focused paste, so [mine] must not take it.
static bool otherOwnerHasFocus(FocusNode mine) =>
_owners.any((focus) => !identical(focus, mine) && focus.hasFocus);
static bool get anotherEditableHasFocus {
final primary = FocusManager.instance.primaryFocus;
if (primary == null || _composers.any((focus) => focus.hasFocus)) {
@@ -120,6 +120,7 @@ class ChatThreadView extends StatefulWidget {
this.showBackButton,
this.useNativeBack = false,
this.pasteTarget = true,
this.ownsPasteWhenFocused = false,
});
final ApiGateway gateway;
@@ -132,6 +133,9 @@ class ChatThreadView extends StatefulWidget {
final bool useNativeBack;
final bool pasteTarget;
/// See [ChatComposerBar.ownsPasteWhenFocused].
final bool ownsPasteWhenFocused;
/// Sets the chat's shared colour (a palette name, null for none) from the
/// information sheet; null leaves the sheet without the Colour choice.
final ValueChanged<String?>? onColorSelected;
@@ -1116,6 +1120,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
),
chatColor: chatSessionColor(widget.session),
pasteTarget: widget.pasteTarget,
ownsPasteWhenFocused: widget.ownsPasteWhenFocused,
runShell: _shellRuns.start,
backgroundTasks: ChatBackgroundTasks(
key: ValueKey('chat-background-tasks-${widget.sessionId}'),
+3
View File
@@ -512,6 +512,9 @@ class _ChatScreenState extends State<ChatScreen>
pasteTarget:
_workspaceVisible &&
(pane == null || pane.id == _workspace.activePaneId),
// A floating chat is never the active pane, so its composer takes a
// paste while it has the keyboard.
ownsPasteWhenFocused: pane != null && _workspace.isFloating(pane.id),
showBackButton: pane == null
? null
: _page.open || !showsListBesideDetail(context),
@@ -164,4 +164,82 @@ void main() {
expect(text!(), isFalse);
await done(tester);
});
testWidgets('a focused floating composer keeps its paste; the active pane '
'takes it again once nothing floats has the keyboard', (tester) async {
await tester.pumpWidget(
materialHost(
Column(
mainAxisSize: MainAxisSize.min,
children: [
ChatComposerBar(
key: const ValueKey('bar-inactive'),
composer: inactive,
running: false,
pasteTarget: false,
ownsPasteWhenFocused: true,
),
ChatComposerBar(
key: const ValueKey('bar-active'),
composer: active,
running: false,
),
],
),
),
);
await tester.pumpAndSettle();
await tester.showKeyboard(_field('inactive'));
await paste(tester);
expect(inactive.draft, 'controlled paste');
expect(active.draft, isEmpty);
expect(reads, 1);
FocusManager.instance.primaryFocus?.unfocus();
await tester.pump();
await paste(tester);
expect(active.draft, 'controlled paste');
await done(tester);
});
testWidgets('a focused floating composer takes pasted files', (
tester,
) async {
final accepts = <String, ChatPasteCanAccept>{};
ChatClipboardPaste source(String id) => ChatClipboardPaste(
subscribe: (onFiles, canAccept, onError, onText, canAcceptText) {
accepts[id] = canAccept;
return () {};
},
);
await tester.pumpWidget(
materialHost(
Column(
mainAxisSize: MainAxisSize.min,
children: [
ChatComposerBar(
key: const ValueKey('bar-inactive'),
composer: inactive,
running: false,
pasteTarget: false,
ownsPasteWhenFocused: true,
paste: source('float'),
),
ChatComposerBar(
key: const ValueKey('bar-active'),
composer: active,
running: false,
paste: source('tiled'),
),
],
),
),
);
await tester.pumpAndSettle();
expect(accepts['float']!(), isFalse);
expect(accepts['tiled']!(), isTrue);
await tester.showKeyboard(_field('inactive'));
expect(accepts['float']!(), isTrue);
expect(accepts['tiled']!(), isFalse);
await done(tester);
});
}