summaryrefslogtreecommitdiff
path: root/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-07 13:54:02 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-07 13:54:02 +0100
commit9997992907d2ecb5c86f17590c63a6284643c589 (patch)
tree1807964b765a6a2cf991b047fe93f45628871610 /LibGUI
parent60c1ab5fbe613f4436c5c830bc4d6d50f4a9ce89 (diff)
downloadserenity-9997992907d2ecb5c86f17590c63a6284643c589.zip
GTextEditor: Make the cursor invalidation work with the padding().
Diffstat (limited to 'LibGUI')
-rw-r--r--LibGUI/GTextEditor.cpp13
-rw-r--r--LibGUI/GTextEditor.h3
2 files changed, 12 insertions, 4 deletions
diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp
index 1604cc6c1f..43ec411d4a 100644
--- a/LibGUI/GTextEditor.cpp
+++ b/LibGUI/GTextEditor.cpp
@@ -62,16 +62,21 @@ void GTextEditor::resize_event(GResizeEvent& event)
void GTextEditor::update_scrollbar_ranges()
{
int available_height = height() - m_horizontal_scrollbar->height();
- int excess_height = max(0, (line_count() * line_height()) - available_height);
+ int excess_height = max(0, (content_height() + padding() * 2) - available_height);
m_vertical_scrollbar->set_range(0, excess_height);
int available_width = width() - m_vertical_scrollbar->width();
- int excess_width = max(0, content_width() - available_width);
+ int excess_width = max(0, (content_width() + padding() * 2) - available_width);
m_horizontal_scrollbar->set_range(0, excess_width);
m_vertical_scrollbar->set_big_step(visible_content_rect().height());
}
+int GTextEditor::content_height() const
+{
+ return line_count() * line_height();
+}
+
int GTextEditor::content_width() const
{
// FIXME: Cache this somewhere.
@@ -196,6 +201,7 @@ Rect GTextEditor::line_widget_rect(int line_index) const
ASSERT(m_vertical_scrollbar);
auto rect = line_content_rect(line_index);
rect.move_by(-(m_horizontal_scrollbar->value() - padding()), -(m_vertical_scrollbar->value() - padding()));
+ rect.set_width(rect.width() + 1); // Add 1 pixel for when the cursor is on the end.
rect.intersect(this->rect());
return rect;
}
@@ -243,10 +249,11 @@ void GTextEditor::set_cursor(int line, int column)
{
if (m_cursor.line() == line && m_cursor.column() == column)
return;
- update_cursor();
+ auto old_cursor_line_rect = line_widget_rect(m_cursor.line());
m_cursor = GTextPosition(line, column);
m_cursor_state = true;
scroll_cursor_into_view();
+ update(old_cursor_line_rect);
update_cursor();
if (on_cursor_change)
on_cursor_change(*this);
diff --git a/LibGUI/GTextEditor.h b/LibGUI/GTextEditor.h
index 4ecc5d3138..044e253a4e 100644
--- a/LibGUI/GTextEditor.h
+++ b/LibGUI/GTextEditor.h
@@ -37,12 +37,13 @@ public:
void set_text(const String&);
int content_width() const;
+ int content_height() const;
Rect visible_content_rect() const;
void scroll_cursor_into_view();
int line_count() const { return m_lines.size(); }
int line_spacing() const { return m_line_spacing; }
int line_height() const { return font().glyph_height() + m_line_spacing; }
- int padding() const { return 2; }
+ int padding() const { return 3; }
GTextPosition cursor() const { return m_cursor; }
private: