1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-24 01:15:07 +00:00

LibGUI: Handle cursor keydown events in AbstractView

Move the basic movement keys (up/down/left/right/home/end/pgup/pgdn)
up to AbstractView::keydown_event() and have it call the virtual
move_cursor() which is then implemented by subclasses.
This commit is contained in:
Andreas Kling 2020-09-02 21:28:12 +02:00
parent 4ba12e9c23
commit 27687b1c6e
6 changed files with 53 additions and 120 deletions

View file

@ -443,4 +443,53 @@ void AbstractView::set_edit_triggers(unsigned triggers)
m_edit_triggers = triggers;
}
void AbstractView::keydown_event(KeyEvent& event)
{
SelectionUpdate selection_update = SelectionUpdate::Set;
if (event.modifiers() == KeyModifier::Mod_Shift) {
selection_update = SelectionUpdate::Shift;
}
if (event.key() == KeyCode::Key_Left) {
move_cursor(CursorMovement::Left, selection_update);
event.accept();
return;
}
if (event.key() == KeyCode::Key_Right) {
move_cursor(CursorMovement::Right, selection_update);
event.accept();
return;
}
if (event.key() == KeyCode::Key_Up) {
move_cursor(CursorMovement::Up, selection_update);
event.accept();
return;
}
if (event.key() == KeyCode::Key_Down) {
move_cursor(CursorMovement::Down, selection_update);
event.accept();
return;
}
if (event.key() == KeyCode::Key_Home) {
move_cursor(CursorMovement::Home, selection_update);
event.accept();
return;
}
if (event.key() == KeyCode::Key_End) {
move_cursor(CursorMovement::End, selection_update);
event.accept();
return;
}
if (event.key() == KeyCode::Key_PageUp) {
move_cursor(CursorMovement::PageUp, selection_update);
event.accept();
return;
}
if (event.key() == KeyCode::Key_PageDown) {
move_cursor(CursorMovement::PageDown, selection_update);
event.accept();
return;
}
}
}