Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/web_ui/lib/src/engine/text_editing/text_editing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ abstract class DefaultTextEditingStrategy implements TextEditingStrategy {
domElement.focus();
}
}));

preventDefaultForMouseEvents();
}

@override
Expand Down Expand Up @@ -488,6 +490,25 @@ abstract class DefaultTextEditingStrategy implements TextEditingStrategy {
// Re-focuses after setting editing state.
domElement.focus();
}

/// Prevent default behavior for mouse down, up and move.
///
/// When normal mouse events are not prevented, in desktop browsers, mouse
/// selection conflicts with selection sent from the framework, which creates
/// flickering during selection by mouse.
void preventDefaultForMouseEvents() {
_subscriptions.add(domElement.onMouseDown.listen((_) {
_.preventDefault();
}));

_subscriptions.add(domElement.onMouseUp.listen((_) {
_.preventDefault();
}));

_subscriptions.add(domElement.onMouseMove.listen((_) {
_.preventDefault();
}));
}
}

/// IOS/Safari behaviour for text editing.
Expand Down Expand Up @@ -740,6 +761,8 @@ class FirefoxTextEditingStrategy extends GloballyPositionedTextEditingStrategy {
domElement.focus();
}
}));

preventDefaultForMouseEvents();
}
}

Expand Down