summaryrefslogtreecommitdiff
path: root/src/selectors.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-03-01 15:32:26 +1100
committerMaxime Coste <mawww@kakoune.org>2018-03-01 15:34:31 +1100
commit28716ec058768bdc4fa13b0a9667604e6f307c4c (patch)
treef771a290c7d0687bec169c0a3238cf19c2b83f4c /src/selectors.cc
parentf907e6cc46c4b3e63a6d984c0bd51b4e1e67e456 (diff)
Change x behaviour to select full line first even if on EOL
x will always first select current line fully, and only then select next line.
Diffstat (limited to 'src/selectors.cc')
-rw-r--r--src/selectors.cc18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/selectors.cc b/src/selectors.cc
index 16518279..a53bbafa 100644
--- a/src/selectors.cc
+++ b/src/selectors.cc
@@ -173,17 +173,13 @@ Optional<Selection>
select_line(const Context& context, const Selection& selection)
{
auto& buffer = context.buffer();
- Utf8Iterator first{buffer.iterator_at(selection.cursor()), buffer};
- if (*first == '\n' and first + 1 != buffer.end())
- ++first;
-
- while (first != buffer.begin() and *(first - 1) != '\n')
- --first;
-
- Utf8Iterator last = first;
- while (last + 1 != buffer.end() and *last != '\n')
- ++last;
- return target_eol(utf8_range(first, last));
+ auto line = selection.cursor().line;
+ // Next line if line fully selected
+ if (selection.anchor() <= BufferCoord{line, 0_byte} and
+ selection.cursor() == BufferCoord{line, buffer[line].length() - 1} and
+ line != buffer.line_count() - 1)
+ ++line;
+ return target_eol({{line, 0_byte}, {line, buffer[line].length() - 1}});
}
template<bool only_move>