1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 17:25:07 +00:00

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.
This commit is contained in:
Andreas Kling 2019-04-25 01:33:59 +02:00
parent 2c51bc92af
commit 7a5525edf4

View file

@ -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