summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibVT/TerminalWidget.cpp
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2021-06-05 16:46:33 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-10 17:18:02 +0200
commitce9460de59e31ede6793432a86fa20f83ee6c753 (patch)
treebd3e66aa44253ab7c2cf3f9e10ed7fe4bc3faefb /Userland/Libraries/LibVT/TerminalWidget.cpp
parent13991eade72ef6f2c488f40e9cb1304f0133ed57 (diff)
downloadserenity-ce9460de59e31ede6793432a86fa20f83ee6c753.zip
Kernel+LibVT: Fix selection with scrollback wrap-around
If lines are removed from the tail of the scrollback buffer, the previous line indices will refer to different lines; therefore we need to offset them.
Diffstat (limited to 'Userland/Libraries/LibVT/TerminalWidget.cpp')
-rw-r--r--Userland/Libraries/LibVT/TerminalWidget.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp
index aeb4996218..be866a0e10 100644
--- a/Userland/Libraries/LibVT/TerminalWidget.cpp
+++ b/Userland/Libraries/LibVT/TerminalWidget.cpp
@@ -947,13 +947,16 @@ int TerminalWidget::last_selection_column_on_row(int row) const
return row == normalized_selection_end.row() || m_rectangle_selection ? normalized_selection_end.column() : m_terminal.columns() - 1;
}
-void TerminalWidget::terminal_history_changed()
+void TerminalWidget::terminal_history_changed(int delta)
{
bool was_max = m_scrollbar->value() == m_scrollbar->max();
m_scrollbar->set_max(m_terminal.history_size());
if (was_max)
m_scrollbar->set_value(m_scrollbar->max());
m_scrollbar->update();
+ // If the history buffer wrapped around, the selection needs to be offset accordingly.
+ if (m_selection.is_valid() && delta < 0)
+ m_selection.offset_row(delta);
}
void TerminalWidget::terminal_did_resize(u16 columns, u16 rows)