From 57c8677b5c760c0d6039c5d2e22916404ef1a9a7 Mon Sep 17 00:00:00 2001 From: sin-ack Date: Sat, 16 Jul 2022 23:37:03 +0000 Subject: LibLine: Ignore empty spans when stylizing Previously we would erroneously apply the stylization to the whoever called stylize next. Now we first check whether the span is non-empty before stylizing. All non-empty spans must have at least one character in them (end-exclusive). --- Userland/Libraries/LibLine/Editor.cpp | 2 ++ Userland/Libraries/LibLine/Span.h | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/Userland/Libraries/LibLine/Editor.cpp b/Userland/Libraries/LibLine/Editor.cpp index 0587cf13cc..c10c2497c3 100644 --- a/Userland/Libraries/LibLine/Editor.cpp +++ b/Userland/Libraries/LibLine/Editor.cpp @@ -463,6 +463,8 @@ Editor::CodepointRange Editor::byte_offset_range_to_code_point_offset_range(size void Editor::stylize(Span const& span, Style const& style) { + if (!span.is_empty()) + return; if (style.is_empty()) return; diff --git a/Userland/Libraries/LibLine/Span.h b/Userland/Libraries/LibLine/Span.h index 669341b23c..c497926859 100644 --- a/Userland/Libraries/LibLine/Span.h +++ b/Userland/Libraries/LibLine/Span.h @@ -28,6 +28,11 @@ public: size_t end() const { return m_end; } Mode mode() const { return m_mode; } + bool is_empty() const + { + return m_beginning < m_end; + } + private: size_t m_beginning { 0 }; size_t m_end { 0 }; -- cgit v1.2.3