Make linewise bracketed paste match P behavior
This is experimental. Testing will reveal if this is the desired behavior.
This commit is contained in:
parent
b2cf74bb4a
commit
1990a764e3
|
@ -77,13 +77,17 @@ void InputMode::paste(StringView content)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Buffer& buffer = context().buffer();
|
Buffer& buffer = context().buffer();
|
||||||
|
const bool linewise = not content.empty() and content.back() == '\n';
|
||||||
ScopedEdition edition{context()};
|
ScopedEdition edition{context()};
|
||||||
ScopedSelectionEdition selection_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) {
|
(size_t index, Selection& sel) {
|
||||||
BufferRange range = buffer.insert(sel.min(), content);
|
auto& min = sel.min();
|
||||||
sel.min() = range.begin;
|
auto& max = sel.max();
|
||||||
sel.max() = range.end > range.begin ? buffer.char_prev(range.end) : range.begin;
|
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);
|
}, false);
|
||||||
}
|
}
|
||||||
catch (Kakoune::runtime_error& error)
|
catch (Kakoune::runtime_error& error)
|
||||||
|
|
|
@ -657,13 +657,6 @@ void change(Context& context, NormalParams params)
|
||||||
enter_insert_mode<InsertMode::Replace>(context, params);
|
enter_insert_mode<InsertMode::Replace>(context, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class PasteMode
|
|
||||||
{
|
|
||||||
Append,
|
|
||||||
Insert,
|
|
||||||
Replace
|
|
||||||
};
|
|
||||||
|
|
||||||
BufferCoord paste_pos(Buffer& buffer, BufferCoord min, BufferCoord max, PasteMode mode, bool linewise)
|
BufferCoord paste_pos(Buffer& buffer, BufferCoord min, BufferCoord max, PasteMode mode, bool linewise)
|
||||||
{
|
{
|
||||||
switch (mode)
|
switch (mode)
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class Buffer;
|
||||||
class Context;
|
class Context;
|
||||||
|
|
||||||
struct no_selections_remaining : runtime_error
|
struct no_selections_remaining : runtime_error
|
||||||
|
@ -40,6 +41,15 @@ struct KeyInfo
|
||||||
String build_autoinfo_for_mapping(const Context& context, KeymapMode mode,
|
String build_autoinfo_for_mapping(const Context& context, KeymapMode mode,
|
||||||
ConstArrayView<KeyInfo> built_ins);
|
ConstArrayView<KeyInfo> built_ins);
|
||||||
|
|
||||||
|
enum class PasteMode
|
||||||
|
{
|
||||||
|
Append,
|
||||||
|
Insert,
|
||||||
|
Replace
|
||||||
|
};
|
||||||
|
|
||||||
|
BufferCoord paste_pos(Buffer& buffer, BufferCoord min, BufferCoord max, PasteMode mode, bool linewise);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // normal_hh_INCLUDED
|
#endif // normal_hh_INCLUDED
|
||||||
|
|
Loading…
Reference in New Issue
Block a user