diff options
| author | Johannes Altmanninger <aclopte@gmail.com> | 2023-03-09 21:21:29 +0100 |
|---|---|---|
| committer | Johannes Altmanninger <aclopte@gmail.com> | 2023-03-11 16:21:57 +0100 |
| commit | 1990a764e3d2ffa77931068f876cd49f76bd43f9 (patch) | |
| tree | 050b5ef8a116ced85ccb9476cb3c4b0ece311293 /src/input_handler.cc | |
| parent | b2cf74bb4a8286c5a191c54e947c0b2c9bb7cf96 (diff) | |
Make linewise bracketed paste match P behavior
This is experimental. Testing will reveal if this is the desired
behavior.
Diffstat (limited to 'src/input_handler.cc')
| -rw-r--r-- | src/input_handler.cc | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc index a24ddfa2..877517e2 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -77,13 +77,17 @@ void InputMode::paste(StringView content) try { Buffer& buffer = context().buffer(); + const bool linewise = not content.empty() and content.back() == '\n'; ScopedEdition edition{context()}; ScopedSelectionEdition selection_edition{context()}; - context().selections().for_each([&buffer, content=std::move(content)] + context().selections().for_each([&buffer, content=std::move(content), linewise] (size_t index, Selection& sel) { - BufferRange range = buffer.insert(sel.min(), content); - sel.min() = range.begin; - sel.max() = range.end > range.begin ? buffer.char_prev(range.end) : range.begin; + auto& min = sel.min(); + auto& max = sel.max(); + BufferRange range = + buffer.insert(paste_pos(buffer, min, max, PasteMode::Insert, linewise), content); + min = range.begin; + max = range.end > range.begin ? buffer.char_prev(range.end) : range.begin; }, false); } catch (Kakoune::runtime_error& error) |
