mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 07:34:58 +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 });
|
||||
}
|
||||
|
||||
void GTextEditor::set_cursor(const GTextPosition& position)
|
||||
void GTextEditor::set_cursor(const GTextPosition& a_position)
|
||||
{
|
||||
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) {
|
||||
// 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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue