From 66866aafd3941cb8fdd03343c46e0d9f94cd99fa Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 8 Jun 2015 13:51:06 +0100 Subject: [PATCH] Change gl/gh to only move cursor, not selecting (/) are unchanged That is more consistant with other goto commands (that just move the cursor) --- src/normal.cc | 16 ++++++++-------- src/selectors.cc | 22 ---------------------- 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(buffer, ByteCoord{0,0}, context.selections()); break; case 'l': - select(context, {}); + select>(context, {}); break; case 'h': - select(context, {}); + select>(context, {}); break; case 'j': { @@ -1492,12 +1492,12 @@ static NormalCmdDesc cmds[] = { alt('E'), "extend to next WORD end", repeated>> }, { 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> }, + { 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> }, { 'X', "extend line", repeated> }, 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 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 +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 +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 {