diff options
| author | Maxime Coste <mawww@kakoune.org> | 2021-10-10 10:28:34 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2021-10-10 11:02:09 +1100 |
| commit | 689553c2e9b953a9d3822528d4ad858af95fb6a2 (patch) | |
| tree | 1415eb0f4a733f278caf2c717340859f269c0989 /src/selection.cc | |
| parent | b609adc84c1bb3251d3e410a3555aa9f94cc769f (diff) | |
Split InsertMode into InsertMode and PasteMode
They are quite different use cases, and this allow moving InsertMode
to input_handler.hh which is what uses it.
This also cleans up the code as we can get rid of get_insert_pos and
rely more on SelectionList::for_each.
Diffstat (limited to 'src/selection.cc')
| -rw-r--r-- | src/selection.cc | 37 |
1 files changed, 2 insertions, 35 deletions
diff --git a/src/selection.cc b/src/selection.cc index 27a40156..d408ddfd 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -351,29 +351,6 @@ void SelectionList::sort_and_merge_overlapping() merge_overlapping(); } -BufferCoord get_insert_pos(const Buffer& buffer, const Selection& sel, - InsertMode mode) -{ - switch (mode) - { - case InsertMode::Insert: - return sel.min(); - case InsertMode::InsertCursor: - return sel.cursor(); - case InsertMode::Append: - return buffer.char_next(sel.max()); - case InsertMode::InsertAtLineBegin: - return sel.min().line; - case InsertMode::AppendAtLineEnd: - return {sel.max().line, buffer[sel.max().line].length() - 1}; - case InsertMode::InsertAtNextLineBegin: - return std::min(buffer.line_count(), sel.max().line+1); - default: - kak_assert(false); - return {}; - } -} - static void fix_overflowing_selections(Vector<Selection>& selections, const Buffer& buffer) { @@ -385,16 +362,6 @@ static void fix_overflowing_selections(Vector<Selection>& selections, } } -void SelectionList::insert(ConstArrayView<String> strings, InsertMode mode) -{ - if (strings.empty()) - return; - - for_each([&](size_t index, Selection& sel) { - Kakoune::insert(*m_buffer, sel, strings[std::min(strings.size()-1, index)], mode); - }); -} - void SelectionList::for_each(ApplyFunc func) { update(); @@ -432,9 +399,9 @@ void replace(Buffer& buffer, Selection& sel, StringView content) max = range.end > range.begin ? buffer.char_prev(range.end) : range.begin; } -void insert(Buffer& buffer, Selection& sel, StringView content, InsertMode mode) +void insert(Buffer& buffer, Selection& sel, BufferCoord pos, StringView content) { - auto range = buffer.insert(get_insert_pos(buffer, sel, mode), content); + auto range = buffer.insert(pos, content); sel.anchor() = buffer.clamp(update_insert(sel.anchor(), range.begin, range.end)); sel.cursor() = buffer.clamp(update_insert(sel.cursor(), range.begin, range.end)); } |
