1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 00:35:08 +00:00

LibGUI: Implement trailing whitespace visualization in TextEditor

This patch adds an optional mode where TextEditor highlights trailing
whitespace characters on each line with a nice reddish dither pattern.

We should probably make this themable and I'm sure it could be nicer
somehow, but this is just a first cut and I do kinda like it. :^)
This commit is contained in:
Andreas Kling 2020-09-01 19:10:55 +02:00
parent 08f1ea3e45
commit aa70d8c217
4 changed files with 52 additions and 0 deletions

View file

@ -94,6 +94,23 @@ size_t TextDocumentLine::first_non_whitespace_column() const
return length();
}
Optional<size_t> TextDocumentLine::last_non_whitespace_column() const
{
for (ssize_t i = length() - 1; i >= 0; --i) {
auto code_point = code_points()[i];
if (!isspace(code_point))
return i;
}
return {};
}
bool TextDocumentLine::ends_in_whitespace() const
{
if (!length())
return false;
return isspace(code_points()[length() - 1]);
}
String TextDocumentLine::to_utf8() const
{
StringBuilder builder;