Merge: a mouse click on a chat link opens it despite small pointer drift

This commit is contained in:
2026-11-03 18:36:10 +00:00
4 changed files with 176 additions and 2 deletions
@@ -7,6 +7,25 @@ import '../../../../ui/adaptive/host.dart';
import 'chat_link_browser_menu.dart';
import 'chat_links.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
/// claims the press as a selection drag once the pointer moves
/// [kPrecisePointerPanSlop] (2 px), so an ordinary click with a little hand or
/// trackpad movement opened nothing. The click still cancels past the tap
/// slop, and a selection drag that starts on plain text still crosses links.
/// Touch, stylus and secondary presses keep competing in the arena, so a long
/// press still selects and offers Copy link.
class _LinkTapRecognizer extends TapGestureRecognizer {
@override
void addAllowedPointer(PointerDownEvent event) {
super.addAllowedPointer(event);
if (event.kind == PointerDeviceKind.mouse &&
event.buttons == kPrimaryMouseButton) {
resolve(GestureDisposition.accepted);
}
}
}
/// The link spans of one selectable text block, and the selection area that
/// hosts them. A tap opens the link. A long press (or a native right-click)
/// shows the selection menu with "Copy link" added; on the web, where the
@@ -24,7 +43,7 @@ class ChatLinkSpans {
static bool? debugOwnsSecondaryClick;
final VoidCallback onChanged;
final Map<String, TapGestureRecognizer> _recognizers = {};
final Map<String, _LinkTapRecognizer> _recognizers = {};
final ContextMenuController _linkMenu = ContextMenuController();
String? _hovered;
String? _pressed;
@@ -45,7 +64,7 @@ class ChatLinkSpans {
final uri = chatLinkUri(target);
if (uri == null) return TextSpan(children: label);
final url = uri.toString();
final recognizer = _recognizers.putIfAbsent(url, TapGestureRecognizer.new)
final recognizer = _recognizers.putIfAbsent(url, _LinkTapRecognizer.new)
..onTapDown = (_) {
_pressed = url;
}