From 03c199420ebeb186b89211bec8bfb1c1463bf8a8 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 22 Sep 2011 14:02:07 +0000 Subject: [PATCH] basic g (go) command, gg/gt goes to first line, gb goes to last --- src/main.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main.cc b/src/main.cc index 191c82f8..7ab02efd 100644 --- a/src/main.cc +++ b/src/main.cc @@ -248,6 +248,32 @@ void do_insert(Window& window, bool append = false) } } +void do_go(Window& window, int count) +{ + BufferCoord target; + if (count != 0) + { + target.line = count; + } + else + { + char c = getch(); + switch (c) + { + case 'g': + case 't': + target.line = 0; + break; + case 'b': + target.line = window.buffer().line_count() - 1; + break; + } + } + + BufferIterator target_it = window.buffer().iterator_at(target); + window.move_cursor_to(window.line_and_column_at(target_it)); +} + Window* current_window; void edit(const CommandParameters& params) @@ -348,6 +374,7 @@ std::unordered_map> keymap { 'a', [](Window& window, int count) { do_insert(window, true); } }, { 'o', [](Window& window, int count) { window.select(true, select_line); window.append("\n"); do_insert(window, true); } }, + { 'g', do_go }, { ':', [](Window& window, int count) { do_command(); } }, { ' ', [](Window& window, int count) { window.empty_selections(); } },