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)
This commit is contained in:
Maxime Coste 2015-06-08 13:51:06 +01:00
parent 942fc224af
commit 66866aafd3
3 changed files with 31 additions and 32 deletions

View File

@ -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>> },

View File

@ -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) {

View File

@ -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
{