mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
GTextEditor: Allow moving the cursor by clicking.
This commit is contained in:
parent
9997992907
commit
a21ecd440a
Notes:
sideshowbarker
2024-07-19 15:08:40 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/a21ecd440a5
@ -88,7 +88,13 @@ int GTextEditor::content_width() const
|
||||
|
||||
void GTextEditor::mousedown_event(GMouseEvent& event)
|
||||
{
|
||||
(void)event;
|
||||
auto position = event.position();
|
||||
position.move_by(m_horizontal_scrollbar->value(), m_vertical_scrollbar->value());
|
||||
position.move_by(-padding(), -padding());
|
||||
int line_index = position.y() / line_height();
|
||||
int column_index = position.x() / glyph_width();
|
||||
column_index = min(column_index, m_lines[line_index].length());
|
||||
set_cursor(line_index, column_index);
|
||||
}
|
||||
|
||||
void GTextEditor::paint_event(GPaintEvent& event)
|
||||
@ -189,10 +195,7 @@ Rect GTextEditor::cursor_content_rect() const
|
||||
return { };
|
||||
ASSERT(!m_lines.is_empty());
|
||||
ASSERT(m_cursor.column() <= (current_line().text().length() + 1));
|
||||
int x = 0;
|
||||
for (int i = 0; i < m_cursor.column(); ++i)
|
||||
x += font().glyph_width(current_line().text()[i]);
|
||||
return { x, m_cursor.line() * line_height(), 1, line_height() };
|
||||
return { m_cursor.column() * glyph_width(), m_cursor.line() * line_height(), 1, line_height() };
|
||||
}
|
||||
|
||||
Rect GTextEditor::line_widget_rect(int line_index) const
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
int line_height() const { return font().glyph_height() + m_line_spacing; }
|
||||
int padding() const { return 3; }
|
||||
GTextPosition cursor() const { return m_cursor; }
|
||||
int glyph_width() const { return font().glyph_width('x'); }
|
||||
|
||||
private:
|
||||
virtual void paint_event(GPaintEvent&) override;
|
||||
|
Loading…
Reference in New Issue
Block a user