diff options
-rw-r--r-- | LibGUI/GTextEditor.cpp | 15 | ||||
-rw-r--r-- | LibGUI/GTextEditor.h | 1 |
2 files changed, 8 insertions, 8 deletions
diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp index ea1ecd51dc..6c7034da3f 100644 --- a/LibGUI/GTextEditor.cpp +++ b/LibGUI/GTextEditor.cpp @@ -243,7 +243,8 @@ void GTextEditor::paint_event(GPaintEvent& event) for (int i = first_visible_line; i <= last_visible_line; ++i) { auto& line = *m_lines[i]; auto line_rect = line_content_rect(i); - line_rect.set_width(exposed_width); + // FIXME: Make sure we always fill the entire line. + //line_rect.set_width(exposed_width); if (is_multi_line() && i == m_cursor.line()) painter.fill_rect(line_rect, Color(230, 230, 230)); painter.draw_text(line_rect, line.characters(), line.length(), m_text_alignment, Color::Black); @@ -608,26 +609,24 @@ Rect GTextEditor::line_widget_rect(int line_index) const void GTextEditor::scroll_cursor_into_view() { auto rect = cursor_content_rect(); - if (m_cursor.column() == 0) - rect.set_x(0); - else if (m_cursor.column() >= m_lines[m_cursor.line()]->length()) - rect.set_x(m_lines[m_cursor.line()]->width(font()) + m_horizontal_content_padding * 2); + rect.set_x(content_x_for_position(m_cursor)); scroll_into_view(rect, true, true); } Rect GTextEditor::line_content_rect(int line_index) const { + auto& line = *m_lines[line_index]; if (is_single_line()) { - Rect line_rect = { m_horizontal_content_padding, 0, content_width() - m_horizontal_content_padding * 2, font().glyph_height() + 2 }; + Rect line_rect = { content_x_for_position({ line_index, 0 }), 0, line.length() * glyph_width(), font().glyph_height() + 2 }; line_rect.center_vertically_within(rect()); // FIXME: This would not be necessary if we knew more about the font and could center it based on baseline and x-height. line_rect.move_by(0, 1); return line_rect; } return { - m_horizontal_content_padding, + content_x_for_position({ line_index, 0 }), line_index * line_height(), - content_width() - m_horizontal_content_padding * 2, + line.length() * glyph_width(), line_height() }; } diff --git a/LibGUI/GTextEditor.h b/LibGUI/GTextEditor.h index 649d0ac3c9..6776fe5272 100644 --- a/LibGUI/GTextEditor.h +++ b/LibGUI/GTextEditor.h @@ -90,6 +90,7 @@ public: int line_height() const { return font().glyph_height() + m_line_spacing; } GTextPosition cursor() const { return m_cursor; } GTextRange normalized_selection() const { return m_selection.normalized(); } + // FIXME: This should take glyph spacing into account, no? int glyph_width() const { return font().glyph_width('x'); } bool write_to_file(const String& path); |