diff options
| author | Frank LENORMAND <lenormf@gmail.com> | 2018-12-18 18:22:50 +0300 |
|---|---|---|
| committer | Frank LENORMAND <lenormf@gmail.com> | 2018-12-20 14:32:18 +0300 |
| commit | b1f5639d8cbc9b0a8525e1fcc76a4000f7852ded (patch) | |
| tree | 0f9bdbe27e1359f0655cf31ab01dc1695578f715 /src/input_handler.cc | |
| parent | cb798fa369cbf58e8373c1c3afc10995835eb367 (diff) | |
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
Diffstat (limited to 'src/input_handler.cc')
| -rw-r--r-- | src/input_handler.cc | 18 |
1 files changed, 15 insertions, 3 deletions
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; |
