summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-02-24 21:24:06 +1100
committerMaxime Coste <mawww@kakoune.org>2018-02-24 21:32:01 +1100
commit6a6e71dc0f86214eb63dfbc605f648b261137f56 (patch)
tree103522ff8f659af62fab85192f0819a207a6d354 /src
parenta0de41d165c5e71f7672e44f4f6d2d09aae9d173 (diff)
Highlight cursors differently when they lie on an end of line
When on an end of line, certain behaviours can be surprising, for example delete will join the following line (which makes sense, and is consistent, but hard to predict if we do not know the cursor is on and end of line). As Kakoune is moving more and more towards treating end of lines as any other character, making it clear when the cursor lies on them seems like a good way to reduce surprise.
Diffstat (limited to 'src')
-rw-r--r--src/face_registry.cc2
-rw-r--r--src/highlighters.cc17
2 files changed, 12 insertions, 7 deletions
diff --git a/src/face_registry.cc b/src/face_registry.cc
index 65e5506b..4ee2f557 100644
--- a/src/face_registry.cc
+++ b/src/face_registry.cc
@@ -133,6 +133,8 @@ FaceRegistry::FaceRegistry()
{ "SecondarySelection", {Face{ Color::Black, Color::Blue }} },
{ "PrimaryCursor", {Face{ Color::Black, Color::White }} },
{ "SecondaryCursor", {Face{ Color::Black, Color::White }} },
+ { "PrimaryCursorEol", {Face{ Color::Black, Color::Cyan }} },
+ { "SecondaryCursorEol", {Face{ Color::Black, Color::Cyan }} },
{ "LineNumbers", {Face{ Color::Default, Color::Default }} },
{ "LineNumberCursor", {Face{ Color::Default, Color::Default, Attribute::Reverse }} },
{ "LineNumbersWrapped", {Face{ Color::Default, Color::Default, Attribute::Italic }} },
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 626a4e60..544ddc5f 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -1163,10 +1163,11 @@ HighlighterAndId create_matching_char_highlighter(HighlighterParameters params)
void highlight_selections(HighlightContext context, DisplayBuffer& display_buffer, BufferRange)
{
const auto& buffer = context.context.buffer();
- const Face primary_face = get_face("PrimarySelection");
- const Face secondary_face = get_face("SecondarySelection");
- const Face primary_cursor_face = get_face("PrimaryCursor");
- const Face secondary_cursor_face = get_face("SecondaryCursor");
+ const Face faces[6] = {
+ get_face("PrimarySelection"), get_face("SecondarySelection"),
+ get_face("PrimaryCursor"), get_face("SecondaryCursor"),
+ get_face("PrimaryCursorEol"), get_face("SecondaryCursorEol"),
+ };
const auto& selections = context.context.selections();
for (size_t i = 0; i < selections.size(); ++i)
@@ -1178,14 +1179,16 @@ void highlight_selections(HighlightContext context, DisplayBuffer& display_buffe
const bool primary = (i == selections.main_index());
highlight_range(display_buffer, begin, end, false,
- apply_face(primary ? primary_face : secondary_face));
+ apply_face(faces[primary ? 0 : 1]));
}
for (size_t i = 0; i < selections.size(); ++i)
{
auto& sel = selections[i];
+ const BufferCoord coord = sel.cursor();
const bool primary = (i == selections.main_index());
- highlight_range(display_buffer, sel.cursor(), buffer.char_next(sel.cursor()), false,
- apply_face(primary ? primary_cursor_face : secondary_cursor_face));
+ const bool eol = buffer[coord.line].length() - 1 == coord.column;
+ highlight_range(display_buffer, coord, buffer.char_next(coord), false,
+ apply_face(faces[2 + (eol ? 2 : 0) + (primary ? 0 : 1)]));
}
}