Change select_to_eol implementation

This commit is contained in:
Maxime Coste 2015-06-07 23:17:23 +01:00
parent dd7ff19714
commit 7acf3da3ca

View File

@ -207,18 +207,18 @@ Selection select_to_reverse(const Buffer& buffer, const Selection& selection,
Selection select_to_eol(const Buffer& buffer, const Selection& selection) Selection select_to_eol(const Buffer& buffer, const Selection& selection)
{ {
Utf8Iterator begin = buffer.iterator_at(selection.cursor()); ByteCoord begin = selection.cursor();
Utf8Iterator end = begin; LineCount line = begin.line;
skip_while(end, buffer.end(), [](Codepoint cur) { return not is_eol(cur); }); ByteCoord end = utf8::previous(buffer.iterator_at({line, buffer[line].length() - 1}),
return target_eol(utf8_range(begin, end != begin ? end-1 : end)); buffer.iterator_at(line)).coord();
return target_eol({begin, end});
} }
Selection select_to_eol_reverse(const Buffer& buffer, const Selection& selection) Selection select_to_eol_reverse(const Buffer& buffer, const Selection& selection)
{ {
Utf8Iterator begin = buffer.iterator_at(selection.cursor()); ByteCoord begin = selection.cursor();
Utf8Iterator end = begin - 1; ByteCoord end = begin.line;
skip_while_reverse(end, buffer.begin(), [](Codepoint cur) { return not is_eol(cur); }); return {begin, end};
return utf8_range(begin, end == buffer.begin() ? end : end+1);
} }
Selection select_number(const Buffer& buffer, const Selection& selection, ObjectFlags flags) Selection select_number(const Buffer& buffer, const Selection& selection, ObjectFlags flags)