summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--DevTools/HackStudio/main.cpp4
-rw-r--r--Libraries/LibGUI/GTextEditor.cpp5
-rw-r--r--Libraries/LibGUI/GTextEditor.h21
3 files changed, 14 insertions, 16 deletions
diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp
index cdbcf9e7e4..6f46e34261 100644
--- a/DevTools/HackStudio/main.cpp
+++ b/DevTools/HackStudio/main.cpp
@@ -256,8 +256,8 @@ static void rehighlight()
dbg() << token.to_string() << " @ " << token.m_start.line << ":" << token.m_start.column << " - " << token.m_end.line << ":" << token.m_end.column;
#endif
GTextEditor::Span span;
- span.start = { token.m_start.line, token.m_start.column };
- span.end = { token.m_end.line, token.m_end.column };
+ span.range.set_start({ token.m_start.line, token.m_start.column });
+ span.range.set_end({ token.m_end.line, token.m_end.column });
auto style = style_for_token_type(token.m_type);
span.color = style.color;
span.font = style.font;
diff --git a/Libraries/LibGUI/GTextEditor.cpp b/Libraries/LibGUI/GTextEditor.cpp
index f4caf54fe7..df373af563 100644
--- a/Libraries/LibGUI/GTextEditor.cpp
+++ b/Libraries/LibGUI/GTextEditor.cpp
@@ -373,11 +373,10 @@ void GTextEditor::paint_event(GPaintEvent& event)
for (int i = 0; i < visual_line_text.length(); ++i) {
const Font* font = &this->font();
Color color;
- int physical_line = line_index;
- int physical_column = start_of_visual_line + i;
+ GTextPosition physical_position(line_index, start_of_visual_line + i);
// FIXME: This is *horribly* inefficient.
for (auto& span : m_spans) {
- if (!span.contains(GTextPosition(physical_line, physical_column)))
+ if (!span.range.contains(physical_position))
continue;
color = span.color;
if (span.font)
diff --git a/Libraries/LibGUI/GTextEditor.h b/Libraries/LibGUI/GTextEditor.h
index f15437667f..4995eec28d 100644
--- a/Libraries/LibGUI/GTextEditor.h
+++ b/Libraries/LibGUI/GTextEditor.h
@@ -78,6 +78,15 @@ public:
return m_start == other.m_start && m_end == other.m_end;
}
+ bool contains(const GTextPosition& position) const
+ {
+ if (!(position.line() > m_start.line() || (position.line() == m_start.line() && position.column() >= m_start.column())))
+ return false;
+ if (!(position.line() < m_end.line() || (position.line() == m_end.line() && position.column() <= m_end.column())))
+ return false;
+ return true;
+ }
+
private:
GTextPosition normalized_start() const { return m_start < m_end ? m_start : m_end; }
GTextPosition normalized_end() const { return m_start < m_end ? m_end : m_start; }
@@ -168,17 +177,7 @@ public:
void set_cursor(const GTextPosition&);
struct Span {
- bool contains(const GTextPosition& position) const
- {
- if (!(position.line() > start.line() || (position.line() == start.line() && position.column() >= start.column())))
- return false;
- if (!(position.line() < end.line() || (position.line() == end.line() && position.column() <= end.column())))
- return false;
- return true;
- }
-
- GTextPosition start;
- GTextPosition end;
+ GTextRange range;
Color color;
const Font* font { nullptr };
};