diff options
author | Glenford Williams <gw_dev@outlook.com> | 2022-01-10 17:03:20 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-11 00:18:15 +0100 |
commit | 6c10e9e121b6f297ebcbe52c3a80fa4c74aa6175 (patch) | |
tree | 39b0c8a0b86689b69b220566a8480407a3ec15a0 /Userland | |
parent | 2f50d8f4d3a0a1203933183e3ea31fe85a84dda0 (diff) | |
download | serenity-6c10e9e121b6f297ebcbe52c3a80fa4c74aa6175.zip |
LibGUI: Make Tableview handle multi-selected indexes when deleting
Previously when the delete key was pressed, only the first selected
cell index would have been deleted. This commit remedies that by first
checking when more than a single index is selected.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGUI/TableView.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGUI/TableView.cpp b/Userland/Libraries/LibGUI/TableView.cpp index af55303d9d..1ce93d194a 100644 --- a/Userland/Libraries/LibGUI/TableView.cpp +++ b/Userland/Libraries/LibGUI/TableView.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2022, Glenford Williams <gw_dev@outlook.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -178,12 +179,20 @@ void TableView::keydown_event(KeyEvent& event) 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(String {}); - else if (is_backspace) + if (is_delete) { + if (selection().size() > 1) { + selection().for_each_index([&](GUI::ModelIndex& index) { + begin_editing(index); + m_editing_delegate->set_value(String {}); + }); + } else { + m_editing_delegate->set_value(String {}); + } + } else if (is_backspace) { m_editing_delegate->set_value(String::empty()); - else + } else { m_editing_delegate->set_value(event.text(), ModelEditingDelegate::SelectionBehavior::DoNotSelect); + } } } } |