diff options
| author | Maxime Coste <mawww@kakoune.org> | 2023-08-13 03:33:32 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2023-08-14 22:50:22 +1000 |
| commit | 6942a4c0c9428a9e2ddb65de3969d2dcb5c5eb2f (patch) | |
| tree | fb1e95ea1f0adeff258a4f0147be64e42f0ff60b /src/normal.cc | |
| parent | 0a06d9acbdebf428f4945f0d1575c091a0619b1d (diff) | |
Change `+` command not to duplicate identical selections more than once
The current exponential behaviour does not seem that useful, it seems
more predictible that pressing `+` twice would end up with 3 copies
of the original selections instead of 4.
Fixes #4533
Diffstat (limited to 'src/normal.cc')
| -rw-r--r-- | src/normal.cc | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/normal.cc b/src/normal.cc index 27c1e47e..b16b9c37 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -2191,9 +2191,17 @@ void duplicate_selections(Context& context, NormalParams params) SelectionList& sels = context.selections(); Vector<Selection> new_sels; const int count = params.count ? params.count : 2; + BasicSelection last{BufferCoord{-1,-1}}; + size_t index = 0; + size_t main_index = 0; for (const auto& sel : sels) - new_sels.insert(new_sels.end(), count, sel); - context.selections().set(std::move(new_sels), sels.main_index() * count); + { + new_sels.insert(new_sels.end(), sel != last ? count : 1, sel); + last = sel; + if (index++ == sels.main_index()) + main_index = new_sels.size() - 1; + } + context.selections().set(std::move(new_sels), main_index); } void force_redraw(Context& context, NormalParams) |
