From 3a5b45a2fa5824c91b9a06882da745dbdb46cd7c Mon Sep 17 00:00:00 2001 From: fufesou Date: Wed, 30 Sep 2026 23:35:41 +0800 Subject: [PATCH] fix: align shortcut availability with platform support - Hide unsupported mobile and web shortcut actions - Enable mobile scaling and Android voice call shortcuts - Use openMonitorInTheSameTab() for display switching - Preserve cursor position when switching displays on desktop and web Signed-off-by: fufesou --- .../keyboard_shortcuts/shortcut_actions.dart | 1 + .../keyboard_shortcuts/shortcut_utils.dart | 3 ++ flutter/lib/models/shortcut_model.dart | 39 +++++++++++-------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/flutter/lib/common/widgets/keyboard_shortcuts/shortcut_actions.dart b/flutter/lib/common/widgets/keyboard_shortcuts/shortcut_actions.dart index 0e6b98e83..88d82fb91 100644 --- a/flutter/lib/common/widgets/keyboard_shortcuts/shortcut_actions.dart +++ b/flutter/lib/common/widgets/keyboard_shortcuts/shortcut_actions.dart @@ -220,6 +220,7 @@ List filterKeyboardShortcutActionGroupsForPlatform( ShortcutPlatformCapabilities cap, ) { bool allowed(String id) { + if (cap.excludedActions.contains(id)) return false; if (!cap.includeFullscreenShortcut && id == kShortcutActionToggleFullscreen) { return false; diff --git a/flutter/lib/common/widgets/keyboard_shortcuts/shortcut_utils.dart b/flutter/lib/common/widgets/keyboard_shortcuts/shortcut_utils.dart index 2e618b4fa..c27573029 100644 --- a/flutter/lib/common/widgets/keyboard_shortcuts/shortcut_utils.dart +++ b/flutter/lib/common/widgets/keyboard_shortcuts/shortcut_utils.dart @@ -120,6 +120,7 @@ class ShortcutPlatformCapabilities { final bool includePinToolbarShortcut; final bool includeViewModeShortcut; final bool includeVoiceCallShortcut; + final Set excludedActions; const ShortcutPlatformCapabilities({ required this.includeFullscreenShortcut, @@ -134,6 +135,7 @@ class ShortcutPlatformCapabilities { required this.includePinToolbarShortcut, required this.includeViewModeShortcut, required this.includeVoiceCallShortcut, + this.excludedActions = const {}, }); } @@ -144,6 +146,7 @@ List> filterDefaultBindingsForPlatform( final filtered = >[]; for (final binding in shortcutBindingMapsFrom(bindings)) { final action = binding['action'] as String?; + if (cap.excludedActions.contains(action)) continue; // Compact Apple keyboards can label Backspace as Delete, making this // default ambiguous. Using Backspace also conflicts with Finder's // "Empty Trash without confirmation" shortcut on macOS. diff --git a/flutter/lib/models/shortcut_model.dart b/flutter/lib/models/shortcut_model.dart index 992fb0af7..82576c836 100644 --- a/flutter/lib/models/shortcut_model.dart +++ b/flutter/lib/models/shortcut_model.dart @@ -181,7 +181,7 @@ class ShortcutModel { /// action belongs to. /// /// Capability rationale: - /// * Fullscreen / Toolbar / Pin / View Mode: rendered wherever the + /// * Fullscreen / Toolbar / Pin: rendered wherever the /// desktop layout applies (native desktop + Web). Native mobile is /// permanently full-screen and doesn't have a desktop-style toolbar. /// * Screenshot / Switch Sides: native desktop only. The Web bridge @@ -195,8 +195,9 @@ class ShortcutModel { /// `recordingModel.toggle()`; Web has no implementation. /// * Reset Canvas: only the mobile toolbar builds the menu entry /// (`isDefaultConn && isMobile` in `toolbarControls`). - /// * Voice Call: Web bridge throws `UnimplementedError` for both - /// `sessionRequestVoiceCall` and `sessionCloseVoiceCall`. + /// * Voice Call: iOS has no audio capture implementation; Web bridge throws + /// `UnimplementedError` for both `sessionRequestVoiceCall` and + /// `sessionCloseVoiceCall`. static ShortcutPlatformCapabilities currentPlatformCapabilities() { final desktopLayout = isDesktop || isWeb; return ShortcutPlatformCapabilities( @@ -211,8 +212,21 @@ class ShortcutModel { includeRecordingShortcut: !isWeb && !isIOS, includeResetCanvasShortcut: isMobile, includePinToolbarShortcut: desktopLayout, - includeViewModeShortcut: desktopLayout, - includeVoiceCallShortcut: !isWeb, + includeViewModeShortcut: true, + includeVoiceCallShortcut: !isWeb && !isIOS, + excludedActions: Set.unmodifiable({ + if (!isDesktop) ...[ + kShortcutActionSwitchDisplayAll, + kShortcutActionToggleEnableFileCopyPaste, + ], + if (isMobile) ...[ + kShortcutActionKeyboardModeLegacy, + kShortcutActionKeyboardModeMap, + kShortcutActionKeyboardModeTranslate, + kShortcutActionToggleShowMyCursor, + kShortcutActionToggleZoomCursor, + ], + }), ); } } @@ -320,16 +334,7 @@ void registerSessionShortcutActions( } else { next = ((current + delta) % count + count) % count; } - bind.sessionSwitchDisplay( - isDesktop: isDesktop, - sessionId: sessionId, - value: Int32List.fromList([next]), - ); - if (pi.isSupportMultiUiSession) { - // On multi-ui-session peers no switch-display message is sent back, so - // update the local state directly (mirrors `model.dart` handling). - ffi.ffiModel.switchToNewDisplay(next, sessionId, ffi.id); - } + openMonitorInTheSameTab(next, ffi, pi, updateCursorPos: isMobile); } ffi.shortcutModel.register(kShortcutActionSwitchDisplayNext, () { @@ -421,8 +426,8 @@ void registerSessionShortcutActions( // Toggle Voice Call — start when idle, hang up when active. Mirrors the // toolbar's `_VoiceCallMenu` state-driven button. Web bridge throws // UnimplementedError on both sessionRequestVoiceCall and - // sessionCloseVoiceCall, so we don't register on web. - if (!isWeb) { + // sessionCloseVoiceCall; iOS has no audio capture implementation. + if (!isWeb && !isIOS) { ffi.shortcutModel.register(kShortcutActionToggleVoiceCall, () { final status = ffi.chatModel.voiceCallStatus.value; if (status == VoiceCallStatus.connected ||