Slight code refactor for paste handling
This commit is contained in:
parent
76c58aa022
commit
968e573d80
|
@ -550,14 +550,15 @@ void change(Context& context, NormalParams params)
|
||||||
enter_insert_mode<InsertMode::Replace>(context, params);
|
enter_insert_mode<InsertMode::Replace>(context, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr InsertMode adapt_for_linewise(InsertMode mode)
|
InsertMode adapt_for_linewise(InsertMode mode)
|
||||||
{
|
{
|
||||||
return ((mode == InsertMode::Append) ?
|
switch (mode)
|
||||||
InsertMode::InsertAtNextLineBegin :
|
{
|
||||||
((mode == InsertMode::Insert) ?
|
case InsertMode::Append: return InsertMode::InsertAtNextLineBegin;
|
||||||
InsertMode::InsertAtLineBegin :
|
case InsertMode::Insert: return InsertMode::InsertAtLineBegin;
|
||||||
((mode == InsertMode::Replace) ?
|
case InsertMode::Replace: return InsertMode::Replace;
|
||||||
InsertMode::Replace : InsertMode::Insert)));
|
default: return InsertMode::Insert;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<InsertMode mode>
|
template<InsertMode mode>
|
||||||
|
@ -565,15 +566,11 @@ void paste(Context& context, NormalParams params)
|
||||||
{
|
{
|
||||||
const char reg = params.reg ? params.reg : '"';
|
const char reg = params.reg ? params.reg : '"';
|
||||||
auto strings = RegisterManager::instance()[reg].values(context);
|
auto strings = RegisterManager::instance()[reg].values(context);
|
||||||
InsertMode effective_mode = mode;
|
const bool linewise = contains_that(strings, [](StringView str) {
|
||||||
for (auto& str : strings)
|
return not str.empty() and str.back() == '\n';
|
||||||
{
|
});
|
||||||
if (not str.empty() and str.back() == '\n')
|
const auto effective_mode = linewise ? adapt_for_linewise(mode) : mode;
|
||||||
{
|
|
||||||
effective_mode = adapt_for_linewise(mode);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ScopedEdition edition(context);
|
ScopedEdition edition(context);
|
||||||
context.selections().insert(strings, effective_mode);
|
context.selections().insert(strings, effective_mode);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user