diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-01-03 01:56:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-03 01:56:28 +0000 |
commit | f4fc9eb35a02426dac33a19e2cb9ff182d745316 (patch) | |
tree | 829535192adfbcfa76f53193ef9f5f0bdbfdb54c | |
parent | 2d9afb9b395ea0cc71432613e0df104aefcf24c1 (diff) | |
download | alacritty-f4fc9eb35a02426dac33a19e2cb9ff182d745316.tar.gz alacritty-f4fc9eb35a02426dac33a19e2cb9ff182d745316.zip |
Fix double-triggering of mouse bindings
The 2d9afb9b395ea0cc71432613e0df104aefcf24c1 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 2d9afb9b395ea0cc71432613e0df104aefcf24c1.
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.
-rw-r--r-- | src/input.rs | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/src/input.rs b/src/input.rs index a4deed04..be5dc264 100644 --- a/src/input.rs +++ b/src/input.rs @@ -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), } } |