add alt-X for trimming non full lines
This commit is contained in:
parent
979cfc1ff2
commit
d3961768ec
|
@ -59,6 +59,8 @@ Basic Movement
|
||||||
* _x_: select line on which selection end lies (or next line when end lies on
|
* _x_: select line on which selection end lies (or next line when end lies on
|
||||||
an end-of-line)
|
an end-of-line)
|
||||||
* _alt-x_: expand selections to contain full lines (including end-of-lines)
|
* _alt-x_: expand selections to contain full lines (including end-of-lines)
|
||||||
|
* _alt-X_: trim selections to only contain full lines (not including last
|
||||||
|
end-of-line)
|
||||||
|
|
||||||
* _%_: select whole buffer
|
* _%_: select whole buffer
|
||||||
|
|
||||||
|
|
|
@ -759,6 +759,7 @@ KeyMap keymap =
|
||||||
{ { Key::Modifiers::None, 'x' }, repeated(select<SelectMode::Replace>(select_line)) },
|
{ { Key::Modifiers::None, 'x' }, repeated(select<SelectMode::Replace>(select_line)) },
|
||||||
{ { Key::Modifiers::None, 'X' }, repeated(select<SelectMode::Extend>(select_line)) },
|
{ { Key::Modifiers::None, 'X' }, repeated(select<SelectMode::Extend>(select_line)) },
|
||||||
{ { Key::Modifiers::Alt, 'x' }, select<SelectMode::Replace>(select_whole_lines) },
|
{ { Key::Modifiers::Alt, 'x' }, select<SelectMode::Replace>(select_whole_lines) },
|
||||||
|
{ { Key::Modifiers::Alt, 'X' }, select<SelectMode::Replace>(trim_partial_lines) },
|
||||||
|
|
||||||
{ { Key::Modifiers::None, 'm' }, select<SelectMode::Replace>(select_matching) },
|
{ { Key::Modifiers::None, 'm' }, select<SelectMode::Replace>(select_matching) },
|
||||||
{ { Key::Modifiers::None, 'M' }, select<SelectMode::Extend>(select_matching) },
|
{ { Key::Modifiers::None, 'M' }, select<SelectMode::Extend>(select_matching) },
|
||||||
|
|
|
@ -379,6 +379,22 @@ Selection select_whole_lines(const Selection& selection)
|
||||||
return Selection(first, last);
|
return Selection(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Selection trim_partial_lines(const Selection& selection)
|
||||||
|
{
|
||||||
|
// same as select_whole_lines
|
||||||
|
BufferIterator first = selection.first();
|
||||||
|
BufferIterator last = selection.last();
|
||||||
|
BufferIterator& to_line_start = first <= last ? first : last;
|
||||||
|
BufferIterator& to_line_end = first <= last ? last : first;
|
||||||
|
|
||||||
|
while (not is_begin(to_line_start) and *(to_line_start-1) != '\n')
|
||||||
|
++to_line_start;
|
||||||
|
while (*(to_line_end+1) != '\n' and to_line_end != to_line_start)
|
||||||
|
--to_line_end;
|
||||||
|
|
||||||
|
return Selection(first, last);
|
||||||
|
}
|
||||||
|
|
||||||
Selection select_whole_buffer(const Selection& selection)
|
Selection select_whole_buffer(const Selection& selection)
|
||||||
{
|
{
|
||||||
const Buffer& buffer = selection.first().buffer();
|
const Buffer& buffer = selection.first().buffer();
|
||||||
|
|
|
@ -29,6 +29,7 @@ template<bool punctuation_is_word>
|
||||||
Selection select_whole_word(const Selection& selection, bool inner);
|
Selection select_whole_word(const Selection& selection, bool inner);
|
||||||
Selection select_whole_lines(const Selection& selection);
|
Selection select_whole_lines(const Selection& selection);
|
||||||
Selection select_whole_buffer(const Selection& selection);
|
Selection select_whole_buffer(const Selection& selection);
|
||||||
|
Selection trim_partial_lines(const Selection& selection);
|
||||||
|
|
||||||
template<bool forward>
|
template<bool forward>
|
||||||
Selection select_next_match(const Selection& selection, const Regex& regex);
|
Selection select_next_match(const Selection& selection, const Regex& regex);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user