diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-10-13 22:59:02 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-10-13 22:59:02 +0100 |
| commit | e8dcdb6072f65e2bc598419ad285cafd4de9b820 (patch) | |
| tree | 8c5fab9e2fb324067279c57ec884633095cfe3d5 /src/input_handler.cc | |
| parent | cc2affea11781d4ad1e1b9d7a9c7d729064c2c10 (diff) | |
Support Ctrl + mouse dragging to add a new selection
Fixes #838
Diffstat (limited to 'src/input_handler.cc')
| -rw-r--r-- | src/input_handler.cc | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc index 462408f7..8c0ca802 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -75,12 +75,21 @@ struct MouseHandler Buffer& buffer = context.buffer(); BufferCoord cursor; - switch (key.modifiers) + auto& selections = context.selections(); + switch ((Key::Modifiers)(key.modifiers & Key::Modifiers::MouseEvent)) { case Key::Modifiers::MousePress: m_dragging = true; m_anchor = context.window().buffer_coord(key.coord()); - context.selections_write_only() = SelectionList{ buffer, m_anchor }; + 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; case Key::Modifiers::MouseRelease: @@ -88,16 +97,16 @@ struct MouseHandler return true; m_dragging = false; cursor = context.window().buffer_coord(key.coord()); - context.selections_write_only() = - SelectionList{ buffer, Selection{buffer.clamp(m_anchor), cursor} }; + selections.main() = {buffer.clamp(m_anchor), cursor}; + selections.sort_and_merge_overlapping(); return true; case Key::Modifiers::MousePos: if (not m_dragging) return true; cursor = context.window().buffer_coord(key.coord()); - context.selections_write_only() = - SelectionList{ buffer, Selection{buffer.clamp(m_anchor), cursor} }; + selections.main() = {buffer.clamp(m_anchor), cursor}; + selections.sort_and_merge_overlapping(); return true; case Key::Modifiers::MouseWheelDown: |
