Fix web transcript cross-message selection

This commit is contained in:
2026-11-05 16:34:58 +00:00
parent 3a9ba55277
commit 9e7140449f
10 changed files with 929 additions and 117 deletions
@@ -6,6 +6,7 @@ import 'package:flutter/services.dart';
import '../../../../ui/adaptive/host.dart';
import 'chat_link_browser_menu.dart';
import 'chat_links.dart';
import 'chat_transcript_selection.dart';
/// A link's tap recognizer. A primary mouse press on a link belongs to the
/// link, as a press on a web page's anchor does: otherwise the selection area
@@ -67,6 +68,7 @@ class ChatLinkSpans {
final recognizer = _recognizers.putIfAbsent(url, _LinkTapRecognizer.new)
..onTapDown = (_) {
_pressed = url;
ChatTranscriptSelectionScope.maybeOf(context)?.menuLink = url;
}
..onTap = () {
_pressed = null;
@@ -98,14 +100,20 @@ class ChatLinkSpans {
/// has no `MaterialLocalizations`, which `SelectionArea` asserts on, so one
/// English default localization scope is added there for its context menu.
Widget selectionArea(BuildContext context, Widget child) {
final transcriptSelection = ChatTranscriptSelectionScope.maybeOf(context);
final area = Listener(
onPointerDown: (event) {
_menuLink = event.buttons == kSecondaryMouseButton ? _hovered : null;
transcriptSelection?.menuLink = _menuLink;
_pressed = null;
},
child: SelectionArea(contextMenuBuilder: _selectionMenu, child: child),
child: transcriptSelection == null
? SelectionArea(contextMenuBuilder: _selectionMenu, child: child)
: child,
);
if (!usesCupertinoHost(context)) return area;
if (transcriptSelection != null || !usesCupertinoHost(context)) {
return area;
}
return Localizations(
locale: Localizations.maybeLocaleOf(context) ?? const Locale('en'),
delegates: const [