Skip to content

Commit

Permalink
LibVT: Don't crash when clicking outside of the terminal's buffer area
Browse files Browse the repository at this point in the history
When resizing a terminal window the number of columns may change.
Previously we assumed that this also affects lines which were in the
terminal's buffer while that is not necessarily true.
  • Loading branch information
gunnarbeutner authored and awesomekling committed Jun 23, 2021
1 parent c503a28 commit 21ee0ad
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Userland/Libraries/LibVT/TerminalWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,9 @@ VT::Position TerminalWidget::buffer_position_at(const Gfx::IntPoint& position) c
column = 0;
if (row >= m_terminal.rows())
row = m_terminal.rows() - 1;
if (column >= m_terminal.columns())
column = m_terminal.columns() - 1;
auto& line = m_terminal.line(row);
if (column >= (int)line.length())
column = line.length() - 1;
row += m_scrollbar->value();
return { row, column };
}
Expand Down Expand Up @@ -736,7 +737,7 @@ void TerminalWidget::doubleclick_event(GUI::MouseEvent& event)
start_column = column;
}

for (int column = position.column(); column < m_terminal.columns() && (line.code_point(column) == ' ') == want_whitespace; ++column) {
for (int column = position.column(); column < (int)line.length() && (line.code_point(column) == ' ') == want_whitespace; ++column) {
end_column = column;
}

Expand Down

0 comments on commit 21ee0ad

Please sign in to comment.