mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:57:35 +00:00
TerminalWidget: Implement ALT selection
When holding ALT & selecting text, the terminal now forms a rectangle selection similar to other terminal behaviors.
This commit is contained in:
parent
4ba206b7e5
commit
72ef3e529a
2 changed files with 34 additions and 3 deletions
|
@ -235,6 +235,9 @@ void TerminalWidget::keydown_event(GUI::KeyEvent& event)
|
|||
}
|
||||
write(m_ptm_fd, "\033[6~", 4);
|
||||
return;
|
||||
case KeyCode::Key_Alt:
|
||||
m_alt_key_held = true;
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -272,6 +275,17 @@ void TerminalWidget::keydown_event(GUI::KeyEvent& event)
|
|||
m_scrollbar->set_value(m_scrollbar->max());
|
||||
}
|
||||
|
||||
void TerminalWidget::keyup_event(GUI::KeyEvent& event)
|
||||
{
|
||||
switch (event.key()) {
|
||||
case KeyCode::Key_Alt:
|
||||
m_alt_key_held = false;
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TerminalWidget::paint_event(GUI::PaintEvent& event)
|
||||
{
|
||||
GUI::Frame::paint_event(event);
|
||||
|
@ -490,6 +504,15 @@ bool TerminalWidget::selection_contains(const VT::Position& position) const
|
|||
if (!has_selection())
|
||||
return false;
|
||||
|
||||
if (m_rectangle_selection) {
|
||||
auto min_selection_column = min(m_selection_start.column(), m_selection_end.column());
|
||||
auto max_selection_column = max(m_selection_start.column(), m_selection_end.column());
|
||||
auto min_selection_row = min(m_selection_start.row(), m_selection_end.row());
|
||||
auto max_selection_row = max(m_selection_start.row(), m_selection_end.row());
|
||||
|
||||
return position.column() >= min_selection_column && position.column() <= max_selection_column && position.row() >= min_selection_row && position.row() <= max_selection_row;
|
||||
}
|
||||
|
||||
return position >= normalized_selection_start() && position <= normalized_selection_end();
|
||||
}
|
||||
|
||||
|
@ -569,6 +592,11 @@ void TerminalWidget::mousedown_event(GUI::MouseEvent& event)
|
|||
m_selection_start = buffer_position_at(event.position());
|
||||
m_selection_end = {};
|
||||
}
|
||||
if (m_alt_key_held)
|
||||
m_rectangle_selection = true;
|
||||
else if (m_rectangle_selection)
|
||||
m_rectangle_selection = false;
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
@ -613,7 +641,7 @@ String TerminalWidget::selected_text() const
|
|||
break;
|
||||
}
|
||||
builder.append(line.characters[column]);
|
||||
if (column == line.m_length - 1) {
|
||||
if (column == line.m_length - 1 || (m_rectangle_selection && column == last_column)) {
|
||||
builder.append('\n');
|
||||
}
|
||||
}
|
||||
|
@ -624,12 +652,12 @@ String TerminalWidget::selected_text() const
|
|||
|
||||
int TerminalWidget::first_selection_column_on_row(int row) const
|
||||
{
|
||||
return row == normalized_selection_start().row() ? normalized_selection_start().column() : 0;
|
||||
return row == normalized_selection_start().row() || m_rectangle_selection ? normalized_selection_start().column() : 0;
|
||||
}
|
||||
|
||||
int TerminalWidget::last_selection_column_on_row(int row) const
|
||||
{
|
||||
return row == normalized_selection_end().row() ? normalized_selection_end().column() : m_terminal.columns() - 1;
|
||||
return row == normalized_selection_end().row() || m_rectangle_selection ? normalized_selection_end().column() : m_terminal.columns() - 1;
|
||||
}
|
||||
|
||||
void TerminalWidget::terminal_history_changed()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue