diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-04-16 14:30:11 +0200 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-04-16 14:30:11 +0200 |
| commit | d3961768ec42bb95654d4feafb61f09be3945f36 (patch) | |
| tree | fac261657decc313c338b23aadbbeb5d6adc3196 /src | |
| parent | 979cfc1ff20f6e0a83e97b884c220a1cb5065ca9 (diff) | |
add alt-X for trimming non full lines
Diffstat (limited to 'src')
| -rw-r--r-- | src/normal.cc | 1 | ||||
| -rw-r--r-- | src/selectors.cc | 16 | ||||
| -rw-r--r-- | src/selectors.hh | 1 |
3 files changed, 18 insertions, 0 deletions
diff --git a/src/normal.cc b/src/normal.cc index 3897c0fc..b41561e3 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -759,6 +759,7 @@ KeyMap keymap = { { Key::Modifiers::None, 'x' }, repeated(select<SelectMode::Replace>(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>(trim_partial_lines) }, { { Key::Modifiers::None, 'm' }, select<SelectMode::Replace>(select_matching) }, { { Key::Modifiers::None, 'M' }, select<SelectMode::Extend>(select_matching) }, diff --git a/src/selectors.cc b/src/selectors.cc index f62e5a78..5a8fcc07 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -379,6 +379,22 @@ Selection select_whole_lines(const Selection& selection) 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) { const Buffer& buffer = selection.first().buffer(); diff --git a/src/selectors.hh b/src/selectors.hh index 9c87c73c..6bc85627 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -29,6 +29,7 @@ template<bool punctuation_is_word> Selection select_whole_word(const Selection& selection, bool inner); Selection select_whole_lines(const Selection& selection); Selection select_whole_buffer(const Selection& selection); +Selection trim_partial_lines(const Selection& selection); template<bool forward> Selection select_next_match(const Selection& selection, const Regex& regex); |
