From b1f5639d8cbc9b0a8525e1fcc76a4000f7852ded Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Tue, 18 Dec 2018 18:22:50 +0300 Subject: src: Add support for right click events The current implementation treats left mouse button clicks as a generic "mouse press" modifier, this commit extends the list of modifiers by adding a "right mouse click" one. The proper way to implement this would be to ship the coordinates of mouse key press events in each `Key` object, and pass whichever button was clicked as a codepoint value (instead of coordinates currently), but this would require more work. This commit allows: * right clicks to set the cursor of the main selection * control-right clicks to merge all the selections, and then set its cursor Fixes #843 --- src/input_handler.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/input_handler.cc') diff --git a/src/input_handler.cc b/src/input_handler.cc index ade87d04..0d9710dd 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -92,9 +92,20 @@ struct MouseHandler Buffer& buffer = context.buffer(); BufferCoord cursor; auto& selections = context.selections(); - switch ((Key::Modifiers)(key.modifiers & Key::Modifiers::MouseEvent)) + const auto key_modifier = (Key::Modifiers)(key.modifiers & Key::Modifiers::MouseEvent); + switch (key_modifier) { - case Key::Modifiers::MousePress: + case Key::Modifiers::MousePressRight: + m_dragging = false; + cursor = context.window().buffer_coord(key.coord()); + if (key.modifiers & Key::Modifiers::Control) + selections = {{selections.begin()->anchor(), cursor}}; + else + selections.main() = {selections.main().anchor(), cursor}; + selections.sort_and_merge_overlapping(); + return true; + + case Key::Modifiers::MousePressLeft: m_dragging = true; m_anchor = context.window().buffer_coord(key.coord()); if (not (key.modifiers & Key::Modifiers::Control)) @@ -108,7 +119,8 @@ struct MouseHandler } return true; - case Key::Modifiers::MouseRelease: + case Key::Modifiers::MouseReleaseLeft: + case Key::Modifiers::MouseReleaseRight: if (not m_dragging) return true; m_dragging = false; -- cgit v1.2.3