From 266d1c37d0d970a7eff747f5e6a5773a3cea39d8 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 17 Mar 2022 21:10:00 +1100 Subject: [PATCH] Select pasted text on paste This is more consistent with the recently changed ! and behaviour --- rc/filetype/c-family.kak | 2 +- src/normal.cc | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/rc/filetype/c-family.kak b/rc/filetype/c-family.kak index f56d9db2a5..7ef1c97576 100644 --- a/rc/filetype/c-family.kak +++ b/rc/filetype/c-family.kak @@ -390,7 +390,7 @@ define-command -hidden c-family-insert-include-guards %{ evaluate-commands %sh{ case "${kak_opt_c_include_guard_style}" in ifdef) - echo 'execute-keys ggi%ggI/xs^.*/dxs\.c_A_INCLUDEDggxyppI#ifndefjI#definejI#endif//O' + echo 'execute-keys gg"%PI/xs^.*/dxs\.r_A_INCLUDEDxyPPI#ifndefjI#definejI#endif//O' ;; pragma) echo 'execute-keys ggi#pragmaonce' diff --git a/src/normal.cc b/src/normal.cc index 51027529b7..e68db583c7 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -683,10 +683,13 @@ void paste(Context& context, NormalParams params) ScopedEdition edition(context); context.selections().for_each([&](size_t index, Selection& sel) { auto& str = strings[std::min(strings.size()-1, index)]; - if (mode == PasteMode::Replace) - replace(buffer, sel, str); - else - insert(buffer, sel, paste_pos(buffer, sel, mode, linewise), str); + auto& min = sel.min(); + auto& max = sel.max(); + BufferRange range = (mode == PasteMode::Replace) ? + buffer.replace(min, buffer.char_next(max), str) + : buffer.insert(paste_pos(buffer, sel, mode, linewise), str); + min = range.begin; + max = range.end > range.begin ? buffer.char_prev(range.end) : range.begin; }); }