diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-06-08 13:51:06 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-06-08 13:51:06 +0100 |
| commit | 66866aafd3941cb8fdd03343c46e0d9f94cd99fa (patch) | |
| tree | 6f0fda818884e7ce5d50284148ae1139f2770a3a /src | |
| parent | 942fc224af403de0a73511a4e6a5dfe4bfa53b91 (diff) | |
Change gl/gh to only move cursor, not selecting (<a-h>/<a-l>) are unchanged
That is more consistant with other goto commands (that just move the cursor)
Diffstat (limited to 'src')
| -rw-r--r-- | src/normal.cc | 16 | ||||
| -rw-r--r-- | src/selectors.cc | 22 | ||||
| -rw-r--r-- | src/selectors.hh | 25 |
3 files changed, 31 insertions, 32 deletions
diff --git a/src/normal.cc b/src/normal.cc index c584baac..75fb2b20 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -144,10 +144,10 @@ void goto_commands(Context& context, NormalParams params) select_coord<mode>(buffer, ByteCoord{0,0}, context.selections()); break; case 'l': - select<mode, select_to_eol>(context, {}); + select<mode, select_to_line_end<true>>(context, {}); break; case 'h': - select<mode, select_to_eol_reverse>(context, {}); + select<mode, select_to_line_begin<true>>(context, {}); break; case 'j': { @@ -1492,12 +1492,12 @@ static NormalCmdDesc cmds[] = { alt('E'), "extend to next WORD end", repeated<select<SelectMode::Extend, select_to_next_word_end<WORD>>> }, { alt('B'), "extend to prevous WORD start", repeated<select<SelectMode::Extend, select_to_previous_word<WORD>>> }, - { alt('l'), "select to line end", repeated<select<SelectMode::Replace, select_to_eol>> }, - { Key::End, "select to line end", repeated<select<SelectMode::Replace, select_to_eol>> }, - { alt('L'), "extend to line end", repeated<select<SelectMode::Extend, select_to_eol>> }, - { alt('h'), "select to line begin", repeated<select<SelectMode::Replace, select_to_eol_reverse>> }, - { Key::Home, "select to line begin", repeated<select<SelectMode::Replace, select_to_eol_reverse>> }, - { alt('H'), "extend to line begin", repeated<select<SelectMode::Extend, select_to_eol_reverse>> }, + { alt('l'), "select to line end", repeated<select<SelectMode::Replace, select_to_line_end<false>>> }, + { Key::End, "select to line end", repeated<select<SelectMode::Replace, select_to_line_end<false>>> }, + { alt('L'), "extend to line end", repeated<select<SelectMode::Extend, select_to_line_end<false>>> }, + { alt('h'), "select to line begin", repeated<select<SelectMode::Replace, select_to_line_begin<false>>> }, + { Key::Home, "select to line begin", repeated<select<SelectMode::Replace, select_to_line_begin<false>>> }, + { alt('H'), "extend to line begin", repeated<select<SelectMode::Extend, select_to_line_begin<false>>> }, { 'x', "select line", repeated<select<SelectMode::Replace, select_line>> }, { 'X', "extend line", repeated<select<SelectMode::Extend, select_line>> }, diff --git a/src/selectors.cc b/src/selectors.cc index 03227734..8d3d5005 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -8,12 +8,6 @@ namespace Kakoune { -static Selection target_eol(Selection sel) -{ - sel.cursor().target = INT_MAX; - return sel; -} - Selection select_line(const Buffer& buffer, const Selection& selection) { Utf8Iterator first = buffer.iterator_at(selection.cursor()); @@ -205,22 +199,6 @@ Selection select_to_reverse(const Buffer& buffer, const Selection& selection, return utf8_range(begin, inclusive ? end : end+1); } -Selection select_to_eol(const Buffer& buffer, const Selection& selection) -{ - ByteCoord begin = selection.cursor(); - LineCount line = begin.line; - ByteCoord end = utf8::previous(buffer.iterator_at({line, buffer[line].length() - 1}), - buffer.iterator_at(line)).coord(); - return target_eol({begin, end}); -} - -Selection select_to_eol_reverse(const Buffer& buffer, const Selection& selection) -{ - ByteCoord begin = selection.cursor(); - ByteCoord end = begin.line; - return {begin, end}; -} - Selection select_number(const Buffer& buffer, const Selection& selection, ObjectFlags flags) { auto is_number = [&](char c) { diff --git a/src/selectors.hh b/src/selectors.hh index a2810d03..57731bd8 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -18,6 +18,12 @@ inline Selection keep_direction(Selection res, const Selection& ref) return res; } +inline Selection target_eol(Selection sel) +{ + sel.cursor().target = INT_MAX; + return sel; +} + template<typename Iterator, typename EndIterator, typename T> void skip_while(Iterator& it, const EndIterator& end, T condition) { @@ -122,8 +128,23 @@ Selection select_to(const Buffer& buffer, const Selection& selection, Selection select_to_reverse(const Buffer& buffer, const Selection& selection, Codepoint c, int count, bool inclusive); -Selection select_to_eol(const Buffer& buffer, const Selection& selection); -Selection select_to_eol_reverse(const Buffer& buffer, const Selection& selection); +template<bool only_move> +Selection select_to_line_end(const Buffer& buffer, const Selection& selection) +{ + ByteCoord begin = selection.cursor(); + LineCount line = begin.line; + ByteCoord end = utf8::previous(buffer.iterator_at({line, buffer[line].length() - 1}), + buffer.iterator_at(line)).coord(); + return target_eol({only_move ? end : begin, end}); +} + +template<bool only_move> +Selection select_to_line_begin(const Buffer& buffer, const Selection& selection) +{ + ByteCoord begin = selection.cursor(); + ByteCoord end = begin.line; + return {only_move ? end : begin, end}; +} enum class ObjectFlags { |
