Add C and alt-C for 'copy selection to next/previous line'
This commit is contained in:
parent
5339f94eb8
commit
622919bafd
|
@ -334,6 +334,9 @@ _alt-k_ allows you to enter a regex and keep only the selections that
|
|||
contains a match for this regex. using _alt-K_ you can keep the selections
|
||||
not containing a match.
|
||||
|
||||
_C_ copies the current selection to the next line (or lines if a count is given)
|
||||
_alt-C_ does the same to previous lines.
|
||||
|
||||
_$_ allows you to enter a shell command and pipe each selections to it.
|
||||
Selections whose shell command returns 0 will be kept, other will be dropped.
|
||||
|
||||
|
|
|
@ -971,6 +971,30 @@ void scroll(Context& context, NormalParams)
|
|||
window.set_position(position);
|
||||
}
|
||||
|
||||
template<Direction direction>
|
||||
void copy_selections_on_next_lines(Context& context, NormalParams params)
|
||||
{
|
||||
auto& selections = context.selections();
|
||||
auto& buffer = context.buffer();
|
||||
Vector<Selection> result;
|
||||
for (auto& sel : selections)
|
||||
{
|
||||
auto anchor = sel.anchor();
|
||||
auto cursor = sel.cursor();
|
||||
result.push_back(std::move(sel));
|
||||
for (int i = 0; i < std::max(params.count, 1); ++i)
|
||||
{
|
||||
LineCount offset = (direction == Forward ? 1 : -1) * (i + 1);
|
||||
ByteCoord new_anchor{anchor.line + offset, anchor.column};
|
||||
ByteCoordAndTarget new_cursor{cursor.line + offset, cursor.column, cursor.target};
|
||||
if (buffer.is_valid(new_anchor) and buffer.is_valid(new_cursor))
|
||||
result.emplace_back(new_anchor, new_cursor);
|
||||
}
|
||||
}
|
||||
selections = std::move(result);
|
||||
selections.sort_and_merge_overlapping();
|
||||
}
|
||||
|
||||
void rotate_selections(Context& context, NormalParams params)
|
||||
{
|
||||
context.selections().rotate_main(params.count != 0 ? params.count : 1);
|
||||
|
@ -1466,6 +1490,9 @@ KeyMap keymap =
|
|||
{ '@', { "convert tabs to spaces in selections", tabs_to_spaces } },
|
||||
{ alt('@'), { "convert spaces to tabs in selections", spaces_to_tabs } },
|
||||
|
||||
{ 'C', { "copy selection on next lines", copy_selections_on_next_lines<Forward> } },
|
||||
{ alt('C'), { "copy selection on previous lines", copy_selections_on_next_lines<Backward> } },
|
||||
|
||||
{ ',', { "user mappings", exec_user_mappings } },
|
||||
|
||||
{ Key::Left, { "move left", move<CharCount, Backward> } },
|
||||
|
|
Loading…
Reference in New Issue
Block a user