mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:17: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);
|
write(m_ptm_fd, "\033[6~", 4);
|
||||||
return;
|
return;
|
||||||
|
case KeyCode::Key_Alt:
|
||||||
|
m_alt_key_held = true;
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -272,6 +275,17 @@ void TerminalWidget::keydown_event(GUI::KeyEvent& event)
|
||||||
m_scrollbar->set_value(m_scrollbar->max());
|
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)
|
void TerminalWidget::paint_event(GUI::PaintEvent& event)
|
||||||
{
|
{
|
||||||
GUI::Frame::paint_event(event);
|
GUI::Frame::paint_event(event);
|
||||||
|
@ -490,6 +504,15 @@ bool TerminalWidget::selection_contains(const VT::Position& position) const
|
||||||
if (!has_selection())
|
if (!has_selection())
|
||||||
return false;
|
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();
|
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_start = buffer_position_at(event.position());
|
||||||
m_selection_end = {};
|
m_selection_end = {};
|
||||||
}
|
}
|
||||||
|
if (m_alt_key_held)
|
||||||
|
m_rectangle_selection = true;
|
||||||
|
else if (m_rectangle_selection)
|
||||||
|
m_rectangle_selection = false;
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -613,7 +641,7 @@ String TerminalWidget::selected_text() const
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
builder.append(line.characters[column]);
|
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');
|
builder.append('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -624,12 +652,12 @@ String TerminalWidget::selected_text() const
|
||||||
|
|
||||||
int TerminalWidget::first_selection_column_on_row(int row) 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
|
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()
|
void TerminalWidget::terminal_history_changed()
|
||||||
|
|
|
@ -92,6 +92,7 @@ private:
|
||||||
virtual void paint_event(GUI::PaintEvent&) override;
|
virtual void paint_event(GUI::PaintEvent&) override;
|
||||||
virtual void resize_event(GUI::ResizeEvent&) override;
|
virtual void resize_event(GUI::ResizeEvent&) override;
|
||||||
virtual void keydown_event(GUI::KeyEvent&) override;
|
virtual void keydown_event(GUI::KeyEvent&) override;
|
||||||
|
virtual void keyup_event(GUI::KeyEvent&) override;
|
||||||
virtual void mousedown_event(GUI::MouseEvent&) override;
|
virtual void mousedown_event(GUI::MouseEvent&) override;
|
||||||
virtual void mousemove_event(GUI::MouseEvent&) override;
|
virtual void mousemove_event(GUI::MouseEvent&) override;
|
||||||
virtual void mousewheel_event(GUI::MouseEvent&) override;
|
virtual void mousewheel_event(GUI::MouseEvent&) override;
|
||||||
|
@ -130,6 +131,8 @@ private:
|
||||||
|
|
||||||
bool m_should_beep { false };
|
bool m_should_beep { false };
|
||||||
bool m_belling { false };
|
bool m_belling { false };
|
||||||
|
bool m_alt_key_held { false };
|
||||||
|
bool m_rectangle_selection { false };
|
||||||
|
|
||||||
int m_pixel_width { 0 };
|
int m_pixel_width { 0 };
|
||||||
int m_pixel_height { 0 };
|
int m_pixel_height { 0 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue