summaryrefslogtreecommitdiff
path: root/src/normal.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2021-02-15 09:01:14 +1100
committerMaxime Coste <mawww@kakoune.org>2021-02-15 09:01:14 +1100
commitfa3aa3c1a34b80efc7680939c4c65496dc91a54f (patch)
tree805c8dae887f24a75ad13b1dbc9683646043ebde /src/normal.cc
parentdea44e4964e97d29b9a9ec493fec02b3d41e5345 (diff)
Add + key to duplicate selections and <a-+> to merge overlapping ones
This is an experiment and might get reverted if overlapping selections prove too cumbersome. Fixes #4041
Diffstat (limited to 'src/normal.cc')
-rw-r--r--src/normal.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/normal.cc b/src/normal.cc
index fba39d17..53ddfdf1 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -2146,6 +2146,22 @@ void merge_consecutive(Context& context, NormalParams params)
context.selections().merge_consecutive();
}
+void merge_overlapping(Context& context, NormalParams params)
+{
+ ensure_forward(context, params);
+ context.selections().merge_overlapping();
+}
+
+void duplicate_selections(Context& context, NormalParams params)
+{
+ SelectionList& sels = context.selections();
+ Vector<Selection> new_sels;
+ const int count = params.count ? params.count : 2;
+ for (const auto& sel : sels)
+ new_sels.insert(new_sels.end(), count, sel);
+ context.selections().set(std::move(new_sels), sels.main_index() * count);
+}
+
void force_redraw(Context& context, NormalParams)
{
if (context.has_client())
@@ -2258,6 +2274,8 @@ static constexpr HashMap<Key, NormalCmd, MemoryDomain::Undefined, KeymapBackend>
{ {alt(';')}, {"swap selections cursor and anchor", flip_selections} },
{ {alt(':')}, {"ensure selection cursor is after anchor", ensure_forward} },
{ {alt('_')}, {"merge consecutive selections", merge_consecutive} },
+ { {'+'}, {"duplicate each selection", duplicate_selections} },
+ { {alt('+')}, {"merge overlapping selections", merge_overlapping} },
{ {'w'}, {"select to next word start", repeated<&select<SelectMode::Replace, select_to_next_word<Word>>>} },
{ {'e'}, {"select to next word end", repeated<select<SelectMode::Replace, select_to_next_word_end<Word>>>} },