diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2021-07-11 21:46:34 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-11 22:07:57 +0200 |
commit | 0f35912bd789e37b8e7193ffc88827fd1f2fcfec (patch) | |
tree | c1b7a9889db1cf979fa1e0db6519b7d55d904392 /Userland/Libraries/LibGUI/TableView.cpp | |
parent | bc5d50e78b6d92361863096b337bcc8849f301c7 (diff) | |
download | serenity-0f35912bd789e37b8e7193ffc88827fd1f2fcfec.zip |
TableView: Do not select input on keydown
In the Spreadsheet app, selecting a cell and typing something (like
"1") would create an empty editing delegate, set "1" as its value and
immediately select the entire contents of the text box. If your goal
was to type "123", that "1" was selected and will be replaced by "23".
This changes the behavior of TableView to not select the editing
delegate's contents if its creation was a result of a keydown event.
Diffstat (limited to 'Userland/Libraries/LibGUI/TableView.cpp')
-rw-r--r-- | Userland/Libraries/LibGUI/TableView.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGUI/TableView.cpp b/Userland/Libraries/LibGUI/TableView.cpp index d26d4a1064..9a904bec49 100644 --- a/Userland/Libraries/LibGUI/TableView.cpp +++ b/Userland/Libraries/LibGUI/TableView.cpp @@ -173,14 +173,18 @@ void TableView::keydown_event(KeyEvent& event) if (event.is_accepted()) return; - auto is_delete = event.key() == Key_Delete || event.key() == Key_Backspace; - if (is_editable() && edit_triggers() & EditTrigger::AnyKeyPressed && (event.code_point() != 0 || is_delete)) { + auto is_delete = event.key() == Key_Delete; + auto is_backspace = event.key() == Key_Backspace; + auto is_clear = is_delete || is_backspace; + if (is_editable() && edit_triggers() & EditTrigger::AnyKeyPressed && (event.code_point() != 0 || is_clear)) { begin_editing(cursor_index()); if (m_editing_delegate) { if (is_delete) - m_editing_delegate->set_value(event.key() == Key_Delete ? String {} : String::empty()); + m_editing_delegate->set_value(String {}); + else if (is_backspace) + m_editing_delegate->set_value(String::empty()); else - m_editing_delegate->set_value(event.text()); + m_editing_delegate->set_value(event.text(), ModelEditingDelegate::SelectionBehavior::DoNotSelect); } } } |