summaryrefslogtreecommitdiff
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
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
-rw-r--r--doc/pages/keys.asciidoc6
-rw-r--r--src/input_handler.cc2
-rw-r--r--src/normal.cc18
-rw-r--r--src/selection.cc2
-rw-r--r--test/regression/0-crash-on-pipe-with-selection-access/cmd2
-rw-r--r--test/regression/1504-assertion-on-incorrect-pipe-use/cmd2
6 files changed, 27 insertions, 5 deletions
diff --git a/doc/pages/keys.asciidoc b/doc/pages/keys.asciidoc
index 5bdb7a03..1398ee75 100644
--- a/doc/pages/keys.asciidoc
+++ b/doc/pages/keys.asciidoc
@@ -286,6 +286,12 @@ Yanking (copying) and pasting use the *"* register by default (See <<registers#,
*<a-_>*::
merge contiguous selections together (works across lines as well)
+*<+>*, *<plus>*::
+ duplicate each selection (generating overlapping selections)
+
+*<a-+>*, *<a-plus>*::
+ merge overlapping selections
+
*>*, *<gt>*::
indent selected lines
diff --git a/src/input_handler.cc b/src/input_handler.cc
index a287b2db..e2c1bb17 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -1555,8 +1555,6 @@ private:
kak_assert(false); // invalid for interactive insert
break;
}
- if (mode != InsertMode::Append and mode != InsertMode::Replace)
- selections.sort_and_merge_overlapping();
selections.check_invariant();
buffer.check_invariant();
}
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>>>} },
diff --git a/src/selection.cc b/src/selection.cc
index 4c908efb..350b3acc 100644
--- a/src/selection.cc
+++ b/src/selection.cc
@@ -48,7 +48,7 @@ void SelectionList::set(Vector<Selection> list, size_t main)
m_selections = std::move(list);
m_main = main;
m_timestamp = m_buffer->timestamp();
- sort_and_merge_overlapping();
+ sort();
check_invariant();
}
diff --git a/test/regression/0-crash-on-pipe-with-selection-access/cmd b/test/regression/0-crash-on-pipe-with-selection-access/cmd
index be5c4524..18090d7e 100644
--- a/test/regression/0-crash-on-pipe-with-selection-access/cmd
+++ b/test/regression/0-crash-on-pipe-with-selection-access/cmd
@@ -1 +1 @@
-%<a-s>|[ $kak_selection = "bar" ] && echo "yes"<ret>
+%<a-s>|[ $kak_selection = "bar" ] && echo "yes"<ret><a-+>
diff --git a/test/regression/1504-assertion-on-incorrect-pipe-use/cmd b/test/regression/1504-assertion-on-incorrect-pipe-use/cmd
index 5c38e31d..9ac6cd2d 100644
--- a/test/regression/1504-assertion-on-incorrect-pipe-use/cmd
+++ b/test/regression/1504-assertion-on-incorrect-pipe-use/cmd
@@ -1 +1 @@
-2o<esc>|echo>&2<ret>
+2o<esc>|echo>&2<ret><a-+>