diff --git a/src/main.cc b/src/main.cc index 37fd8c66..7a22b9af 100644 --- a/src/main.cc +++ b/src/main.cc @@ -322,11 +322,16 @@ void do_insert(Window& window, IncrementalInserter::Mode mode) window.clear_selections(); } +template void do_go(Window& window, int count) { - BufferIterator target; if (count != 0) - target = window.buffer().iterator_at({count, 0}); + { + BufferIterator target = + window.buffer().iterator_at(BufferCoord(count, 0)); + + window.move_cursor_to(window.line_and_column_at(target)); + } else { char c = getch(); @@ -334,28 +339,29 @@ void do_go(Window& window, int count) { case 'g': case 't': - target = window.buffer().iterator_at({0,0}); - break; - case 'l': - target = window.iterator_at(window.cursor_position()); - while (not target.is_end() and *target != '\n') - ++target; - --target; - break; - case 'h': - target = window.iterator_at(window.cursor_position()); - while (not target.is_begin() and *target != '\n') - --target; - ++target; - break; - case 'b': - target = window.buffer().iterator_at( - {window.buffer().line_count() - 1, 0}); - break; + { + BufferIterator target = + window.buffer().iterator_at(BufferCoord(0,0)); + window.move_cursor_to(window.line_and_column_at(target)); break; } + case 'l': + case 'L': + window.select(select_to_eol, append); + break; + case 'h': + case 'H': + window.select(select_to_eol_reverse, append); + break; + case 'b': + { + BufferIterator target = window.buffer().iterator_at( + BufferCoord(window.buffer().line_count() - 1, 0)); + window.move_cursor_to(window.line_and_column_at(target)); + break; + } + } } - window.move_cursor_to(window.line_and_column_at(target)); } Window* current_window; @@ -516,7 +522,8 @@ std::unordered_map> keymap { 'o', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::OpenLineBelow); } }, { 'O', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::OpenLineAbove); } }, - { 'g', do_go }, + { 'g', do_go }, + { 'G', do_go }, { 'y', do_yank }, { 'p', do_paste }, diff --git a/src/selectors.cc b/src/selectors.cc index c2f8e33b..c4864c74 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -223,4 +223,18 @@ Selection select_to_reverse(const BufferIterator& cursor, char c, int count, boo return Selection(cursor, inclusive ? end : end+1); } +Selection select_to_eol(const BufferIterator& cursor) +{ + BufferIterator end = cursor + 1; + skip_while(end, [](char cur) { return not is_eol(cur); }); + return Selection(cursor, end-1); +} + +Selection select_to_eol_reverse(const BufferIterator& cursor) +{ + BufferIterator end = cursor - 1; + skip_while_reverse(end, [](char cur) { return not is_eol(cur); }); + return Selection(cursor, end.is_begin() ? end : end+1); +} + } diff --git a/src/selectors.hh b/src/selectors.hh index a53b30cc..4849ea5c 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -16,6 +16,8 @@ Selection select_matching(const BufferIterator& cursor); Selection select_to(const BufferIterator& cursor, char c, int count, bool inclusive); Selection select_to_reverse(const BufferIterator& cursor, char c, int count, bool inclusive); +Selection select_to_eol(const BufferIterator& cursor); +Selection select_to_eol_reverse(const BufferIterator& cursor); } #endif // selectors_hh_INCLUDED