From 7a5525edf4561a3a46dadad2dfb41a1ca9d81f21 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 25 Apr 2019 01:33:59 +0200 Subject: [PATCH] GTextEditor: Go a little past the cursor for Home/End scroll-into-view. When jumping to the start of a line, or to the end of a line, scrolling two pixels past the end yields a pleasant effect. --- LibGUI/GTextEditor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp index 0b350fb51e..a90571914e 100644 --- a/LibGUI/GTextEditor.cpp +++ b/LibGUI/GTextEditor.cpp @@ -605,7 +605,12 @@ Rect GTextEditor::line_widget_rect(int line_index) const void GTextEditor::scroll_cursor_into_view() { - scroll_into_view(cursor_content_rect(), true, true); + auto rect = cursor_content_rect(); + if (m_cursor.column() == 0) + rect.set_x(content_x_for_position({ m_cursor.line(), 0 }) - 2); + else if (m_cursor.column() == m_lines[m_cursor.line()]->length()) + rect.set_x(content_x_for_position({ m_cursor.line(), m_lines[m_cursor.line()]->length() }) + 2); + scroll_into_view(rect, true, true); } Rect GTextEditor::line_content_rect(int line_index) const