diff options
| author | Maxime Coste <mawww@kakoune.org> | 2020-06-28 19:48:55 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2020-06-28 19:48:55 +1000 |
| commit | d3374e7e5f7af9f4fdf33200f91847b3cddf9e67 (patch) | |
| tree | 8a70ba5491447a5dfb7b565be242757ab470042f /src/input_handler.cc | |
| parent | fc3e5ea419aa79c7adf38a9252586d867b3eb19b (diff) | |
Refactor mouse press/release handling to support 3 buttons
Change button to be an additional parameter instead of having separate
events for left/right buttons.
Fixes #3471
Diffstat (limited to 'src/input_handler.cc')
| -rw-r--r-- | src/input_handler.cc | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc index 2773c482..f13c513e 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -92,35 +92,40 @@ struct MouseHandler Buffer& buffer = context.buffer(); BufferCoord cursor; auto& selections = context.selections(); - constexpr auto modifiers = Key::Modifiers::Control | Key::Modifiers::Alt | Key::Modifiers::Shift; + constexpr auto modifiers = Key::Modifiers::Control | Key::Modifiers::Alt | Key::Modifiers::Shift | Key::Modifiers::MouseButtonMask; switch ((key.modifiers & ~modifiers).value) { - 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)) - context.selections_write_only() = { buffer, m_anchor}; - else + case Key::Modifiers::MousePress: + switch (key.mouse_button()) { - size_t main = selections.size(); - selections.push_back({m_anchor}); - selections.set_main_index(main); + case Key::MouseButton::Right: + 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::MouseButton::Left: + m_dragging = true; + m_anchor = context.window().buffer_coord(key.coord()); + if (not (key.modifiers & Key::Modifiers::Control)) + context.selections_write_only() = { buffer, m_anchor}; + else + { + size_t main = selections.size(); + selections.push_back({m_anchor}); + selections.set_main_index(main); + selections.sort_and_merge_overlapping(); + } + return true; + + default: return true; } - return true; - case Key::Modifiers::MouseReleaseLeft: - case Key::Modifiers::MouseReleaseRight: + case Key::Modifiers::MouseRelease: if (not m_dragging) return true; m_dragging = false; |
