Rollback event handling changes for the mouse (#6396)

Fixes #6385

Partial rollback of #6364

It turns out that preventing default for mouse events is a bad idea in general. It shouldn't affect other fixed bugs because (afaik) all of them were caused by keyboard events.

We're still preventing default for keyboard events.
This commit is contained in:
Ilya Bogdanov 2023-04-26 15:26:51 +03:00 committed by GitHub
parent 3d045a7ceb
commit 72f83c2dd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -54,7 +54,6 @@ where JsEvent: AsRef<web::MouseEvent>
{
/// Constructor.
pub fn new(js_event: JsEvent, shape: Shape) -> Self {
js_event.as_ref().prevent_default();
let js_event = Some(js_event);
let event_type = default();
Self { js_event, shape, event_type }
@ -175,6 +174,11 @@ where JsEvent: AsRef<web::MouseEvent>
self.js_event.as_ref().map(|t| t.as_ref().ctrl_key()).unwrap_or_default()
}
/// Prevent the default action of the event.
pub fn prevent_default(&self) {
self.js_event.as_ref().map(|t| t.as_ref().prevent_default());
}
/// Convert the event to a different type. No checks will be performed during this action.
pub fn unchecked_convert_to<NewEventType: IsEvent>(
self,
@ -225,13 +229,6 @@ define_events! {
// - https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseover_event
// - https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseup_event
// - https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event
//
// ## Preventing default
//
// To avoid triggerring any builtin bevavior of the browser, we call [`preventDefault`] on all
// mouse events.
//
// [`preventDefault`]: https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault
/// The [`Down`] event is fired at an element when a button on a pointing device (such as a
/// mouse or trackpad) is pressed while the pointer is inside the element.

View File

@ -239,6 +239,10 @@ impl NavigatorEvents {
let listener = self.mouse_manager.on_wheel.add(move |event: &mouse::Wheel| {
if let Some(data) = data.upgrade() {
if event.ctrl_key() {
// Prevent zoom event to be handed to the browser. This avoids browser scaling
// being applied to the whole IDE, thus we need to do this always when ctrl is
// pressed.
event.prevent_default();
let position = data.mouse_position();
let zoom_speed = data.zoom_speed();
let movement = Vector2::new(event.delta_x() as f32, -event.delta_y() as f32);