3029295b1f
Give Cmd/Ctrl+E to the active chat Files panel while preserving terminal behavior, and move Center Stage to the shifted chord. Update shortcut documentation and regression coverage for the new bindings.
116 lines
3.6 KiB
Dart
116 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import '../../../shell/windows/window_entry.dart';
|
|
import '../../../ui/adaptive/window_margins.dart';
|
|
import '../../../ui/input/keyboard_owner.dart';
|
|
import '../chat_pane_content.dart';
|
|
import '../workspace/chat_center_stage_controller.dart';
|
|
import '../workspace/chat_pane_commands.dart';
|
|
import 'chat_window_tabs.dart';
|
|
import 'chat_windows.dart';
|
|
|
|
/// A floating window's chat: the same live view as a tiled pane (see
|
|
/// [buildChatPaneContent]), with what a window decides. Before the server
|
|
/// has been reached it says so instead of reading a chat.
|
|
class ChatWindowContent extends StatefulWidget {
|
|
const ChatWindowContent({
|
|
super.key,
|
|
required this.windows,
|
|
required this.entry,
|
|
});
|
|
|
|
final ChatWindows windows;
|
|
final WindowEntry entry;
|
|
|
|
@override
|
|
State<ChatWindowContent> createState() => _ChatWindowContentState();
|
|
}
|
|
|
|
class _ChatWindowContentState extends State<ChatWindowContent> {
|
|
final _paneCommands = ChatPaneCommands();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
FocusManager.instance.addEarlyKeyEventHandler(_key);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
FocusManager.instance.removeEarlyKeyEventHandler(_key);
|
|
_paneCommands.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
KeyEventResult _key(KeyEvent event) {
|
|
final scope = keyboardWindow();
|
|
final keyboard = HardwareKeyboard.instance;
|
|
if (scope?.entry.id != widget.entry.id ||
|
|
!chatFilesShortcut(event, keyboard) ||
|
|
primaryFocusIsTypingSurface()) {
|
|
return KeyEventResult.ignored;
|
|
}
|
|
if (event is KeyDownEvent) {
|
|
_paneCommands.request(widget.entry.contentId, ChatPaneCommand.files);
|
|
}
|
|
return KeyEventResult.handled;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final runtime = widget.windows.runtime;
|
|
final sessionId = widget.entry.contentId;
|
|
return ListenableBuilder(
|
|
listenable: Listenable.merge([
|
|
runtime,
|
|
runtime.syncToken,
|
|
widget.windows.readiness,
|
|
]),
|
|
builder: (context, _) {
|
|
// A chat is drawn once: the tiling wins, and this window closes.
|
|
if (widget.windows.tiling?.holds(sessionId) ?? false) {
|
|
WidgetsBinding.instance.addPostFrameCallback(
|
|
(_) => widget.windows.manager.close(widget.entry.id),
|
|
);
|
|
return const SizedBox.shrink();
|
|
}
|
|
if (!widget.windows.ready) {
|
|
return Center(
|
|
child: Text(
|
|
'Connecting…',
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
),
|
|
);
|
|
}
|
|
// A small window keeps the compact bar insets.
|
|
return WindowMargins.compact(
|
|
child: buildChatPaneContent(
|
|
runtime: runtime,
|
|
sessionId: sessionId,
|
|
placement: ChatPanePlacement(
|
|
syncToken: runtime.syncToken.value,
|
|
onBack: () {},
|
|
showBackButton: false,
|
|
// Never the active pane: its composer takes a paste while it
|
|
// has the keyboard.
|
|
ownsPasteWhenFocused: true,
|
|
paneCommands: _paneCommands,
|
|
onComposerFocus: () => runtime.composerFocus.request(sessionId),
|
|
onNewSession: (previousId, session, notice) =>
|
|
widget.windows.startedNewSession(
|
|
widget.entry.id,
|
|
previousId,
|
|
session,
|
|
notice,
|
|
),
|
|
onSessionClosed: () =>
|
|
widget.windows.sessionClosed(widget.entry.id),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|