diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-03-27 22:33:58 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-03-27 22:33:58 +1100 |
| commit | 1f6c2b87ff7f81ff7b13f4e83f818fa3935f7a4d (patch) | |
| tree | c575ea84589fc88238d07e70d1bc7980ceb7222b | |
| parent | e8093a12a0c9230535af20117133e53a4ffe87f6 (diff) | |
Support count in <a-s> to split on groups of n lines
Fixes #1966
| -rw-r--r-- | src/normal.cc | 15 | ||||
| -rw-r--r-- | test/normal/split-multiple-lines/cmd | 1 | ||||
| -rw-r--r-- | test/normal/split-multiple-lines/in | 5 | ||||
| -rw-r--r-- | test/normal/split-multiple-lines/selections | 6 |
4 files changed, 22 insertions, 5 deletions
diff --git a/src/normal.cc b/src/normal.cc index eb21ffb8..07b1b5b1 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -936,8 +936,9 @@ void split_regex(Context& context, NormalParams params) }); } -void split_lines(Context& context, NormalParams) +void split_lines(Context& context, NormalParams params) { + const LineCount count{params.count == 0 ? 1 : params.count}; auto& selections = context.selections(); auto& buffer = context.buffer(); Vector<Selection> res; @@ -950,10 +951,14 @@ void split_lines(Context& context, NormalParams) } auto min = sel.min(); auto max = sel.max(); - res.push_back(keep_direction({min, {min.line, buffer[min.line].length()-1}}, sel)); - for (auto line = min.line+1; line < max.line; ++line) - res.push_back(keep_direction({line, {line, buffer[line].length()-1}}, sel)); - res.push_back(keep_direction({max.line, max}, sel)); + for (auto line = min.line; line <= max.line; line += count) + { + auto last_line = std::min(line + count - 1, buffer.line_count() - 1); + res.push_back(keep_direction({ + std::max<BufferCoord>(min, line), + std::min<BufferCoord>(max, {last_line, buffer[last_line].length() - 1}) + }, sel)); + } } selections = std::move(res); } diff --git a/test/normal/split-multiple-lines/cmd b/test/normal/split-multiple-lines/cmd new file mode 100644 index 00000000..f041eac0 --- /dev/null +++ b/test/normal/split-multiple-lines/cmd @@ -0,0 +1 @@ +%2<a-s> diff --git a/test/normal/split-multiple-lines/in b/test/normal/split-multiple-lines/in new file mode 100644 index 00000000..94c99a32 --- /dev/null +++ b/test/normal/split-multiple-lines/in @@ -0,0 +1,5 @@ +line 1 +line 2 +line 3 +line 4 +line 5 diff --git a/test/normal/split-multiple-lines/selections b/test/normal/split-multiple-lines/selections new file mode 100644 index 00000000..4df657f3 --- /dev/null +++ b/test/normal/split-multiple-lines/selections @@ -0,0 +1,6 @@ +line 1 +line 2 +:line 3 +line 4 +:line 5 + |
