From 195b813b7340af5c4ff072449eb25dbde2569cde Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 27 Mar 2015 13:33:14 +0000 Subject: [PATCH] Add support for Home/End keys in normal and insert mode Fixes #260 --- src/input_handler.cc | 18 ++++++++++++++++++ src/normal.cc | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/input_handler.cc b/src/input_handler.cc index 6d712697..b5f9e817 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -950,6 +950,24 @@ public: move(1_line); moved = true; } + else if (key == Key::Home) + { + auto& selections = context().selections(); + for (auto& sel : selections) + sel.anchor() = sel.cursor() = ByteCoord{sel.cursor().line, 0}; + selections.sort_and_merge_overlapping(); + } + else if (key == Key::End) + { + auto& buffer = context().buffer(); + auto& selections = context().selections(); + for (auto& sel : selections) + { + const LineCount line = sel.cursor().line; + sel.anchor() = sel.cursor() = buffer.clamp({line, buffer[line].length()}); + } + selections.sort_and_merge_overlapping(); + } else if (key.modifiers == Key::Modifiers::None) insert(key.key); else if (key == ctrl('r')) diff --git a/src/normal.cc b/src/normal.cc index fdec4258..3ba7760a 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1481,8 +1481,10 @@ static NormalCmdDesc cmds[] = { alt('B'), "extend to prevous WORD start", repeated>> }, { alt('l'), "select to line end", repeated> }, + { Key::End, "select to line end", repeated> }, { alt('L'), "extend to line end", repeated> }, { alt('h'), "select to line begin", repeated> }, + { Key::Home, "select to line begin", repeated> }, { alt('H'), "extend to line begin", repeated> }, { 'x', "select line", repeated> },