LibGUI: Make arrow-left/right with selection move cursor to edge of selection
This matches behavior on Linux, macOS, Windows, and it makes it possible to hit ctrl-L arrow-right ctrl-backspace to edit the last component of an URL in browser, or of the current path in File Manager. Also make it so that ctrl-left/right does a word movement that starts at the edge of the selection. This matches Linux and macOS, but not Windows (which instead does a word movement relative to the cursor, not the selection edge).
This commit is contained in:
parent
95077f9a5d
commit
397e5766ff
Notes:
sideshowbarker
2024-07-19 01:57:34 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/397e5766ffb Pull-request: https://github.com/SerenityOS/serenity/pull/3725
1 changed files with 18 additions and 0 deletions
|
@ -794,6 +794,15 @@ void TextEditor::keydown_event(KeyEvent& event)
|
|||
return;
|
||||
}
|
||||
if (event.key() == KeyCode::Key_Left) {
|
||||
if (!event.shift() && m_selection.is_valid()) {
|
||||
set_cursor(m_selection.normalized().start());
|
||||
m_selection.clear();
|
||||
did_update_selection();
|
||||
if (!event.ctrl()) {
|
||||
update();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (event.ctrl()) {
|
||||
TextPosition new_cursor;
|
||||
if (document().has_spans()) {
|
||||
|
@ -836,6 +845,15 @@ void TextEditor::keydown_event(KeyEvent& event)
|
|||
return;
|
||||
}
|
||||
if (event.key() == KeyCode::Key_Right) {
|
||||
if (!event.shift() && m_selection.is_valid()) {
|
||||
set_cursor(m_selection.normalized().end());
|
||||
m_selection.clear();
|
||||
did_update_selection();
|
||||
if (!event.ctrl()) {
|
||||
update();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (event.ctrl()) {
|
||||
TextPosition new_cursor;
|
||||
if (document().has_spans()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue