mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +00:00
LibGUI: Make GTextEditor::set_cursor() public
Also clamp the cursor value to the possible range instead of asserting when trying to set a cursor past the end of the document.
This commit is contained in:
parent
7eed2e968c
commit
0a0dfeee8b
2 changed files with 13 additions and 5 deletions
|
@ -848,11 +848,18 @@ void GTextEditor::set_cursor(int line, int column)
|
||||||
set_cursor({ line, column });
|
set_cursor({ line, column });
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTextEditor::set_cursor(const GTextPosition& position)
|
void GTextEditor::set_cursor(const GTextPosition& a_position)
|
||||||
{
|
{
|
||||||
ASSERT(!m_lines.is_empty());
|
ASSERT(!m_lines.is_empty());
|
||||||
ASSERT(position.line() < m_lines.size());
|
|
||||||
ASSERT(position.column() <= m_lines[position.line()].length());
|
GTextPosition position = a_position;
|
||||||
|
|
||||||
|
if (position.line() >= m_lines.size())
|
||||||
|
position.set_line(m_lines.size() - 1);
|
||||||
|
|
||||||
|
if (position.column() > m_lines[position.line()].length())
|
||||||
|
position.set_column(m_lines[position.line()].length());
|
||||||
|
|
||||||
if (m_cursor != position) {
|
if (m_cursor != position) {
|
||||||
// NOTE: If the old cursor is no longer valid, repaint everything just in case.
|
// NOTE: If the old cursor is no longer valid, repaint everything just in case.
|
||||||
auto old_cursor_line_rect = m_cursor.line() < m_lines.size()
|
auto old_cursor_line_rect = m_cursor.line() < m_lines.size()
|
||||||
|
|
|
@ -164,6 +164,9 @@ public:
|
||||||
|
|
||||||
void add_custom_context_menu_action(GAction&);
|
void add_custom_context_menu_action(GAction&);
|
||||||
|
|
||||||
|
void set_cursor(int line, int column);
|
||||||
|
void set_cursor(const GTextPosition&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GTextEditor(Type, GWidget* parent);
|
GTextEditor(Type, GWidget* parent);
|
||||||
|
|
||||||
|
@ -229,8 +232,6 @@ private:
|
||||||
Rect cursor_content_rect() const;
|
Rect cursor_content_rect() const;
|
||||||
Rect content_rect_for_position(const GTextPosition&) const;
|
Rect content_rect_for_position(const GTextPosition&) const;
|
||||||
void update_cursor();
|
void update_cursor();
|
||||||
void set_cursor(int line, int column);
|
|
||||||
void set_cursor(const GTextPosition&);
|
|
||||||
Line& current_line() { return m_lines[m_cursor.line()]; }
|
Line& current_line() { return m_lines[m_cursor.line()]; }
|
||||||
const Line& current_line() const { return m_lines[m_cursor.line()]; }
|
const Line& current_line() const { return m_lines[m_cursor.line()]; }
|
||||||
GTextPosition text_position_at(const Point&) const;
|
GTextPosition text_position_at(const Point&) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue