Fix double-triggering of mouse bindings

The 2d9afb9b39 commit lead to mouse
actions being triggered on both press and release of mouse buttons.

This reverts the mouse binding behavior back to the previous state where
they are only triggered when the button is pressed, not when it's
released.

The `mouse_input` method's structure was overly complicated and did not
accurately represent the logic which should be implemented by it. This
is likely what caused the regression in 2d9afb9b39.

To prevent similar issues from popping up in the future, the method has
been cleaned up and the structure should now represent the logic
required more logically.
This commit is contained in:
Christian Duerr 2019-01-03 01:56:28 +00:00 committed by GitHub
parent 2d9afb9b39
commit f4fc9eb35a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 19 deletions

View File

@ -638,27 +638,19 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
}
pub fn mouse_input(&mut self, state: ElementState, button: MouseButton, modifiers: ModifiersState) {
let prev_state = match button {
MouseButton::Left => Some(mem::replace(&mut self.ctx.mouse_mut().left_button_state, state)),
MouseButton::Middle => Some(mem::replace(&mut self.ctx.mouse_mut().middle_button_state, state)),
MouseButton::Right => Some(mem::replace(&mut self.ctx.mouse_mut().right_button_state, state)),
// Can't properly report more than three buttons.
MouseButton::Other(_) => None,
};
self.process_mouse_bindings(modifiers, button);
if let Some(prev_state) = prev_state {
if prev_state != state {
match state {
ElementState::Pressed => self.on_mouse_press(button, modifiers),
ElementState::Released => self.on_mouse_release(button, modifiers),
};
}
match button {
MouseButton::Left => self.ctx.mouse_mut().left_button_state = state,
MouseButton::Middle => self.ctx.mouse_mut().middle_button_state = state,
MouseButton::Right => self.ctx.mouse_mut().right_button_state = state,
_ => (),
}
if let ElementState::Released = state {
return;
match state {
ElementState::Pressed => {
self.process_mouse_bindings(modifiers, button);
self.on_mouse_press(button, modifiers);
},
ElementState::Released => self.on_mouse_release(button, modifiers),
}
}