From 6c10e9e121b6f297ebcbe52c3a80fa4c74aa6175 Mon Sep 17 00:00:00 2001 From: Glenford Williams Date: Mon, 10 Jan 2022 17:03:20 -0500 Subject: 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. --- Userland/Libraries/LibGUI/TableView.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'Userland/Libraries/LibGUI/TableView.cpp') 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 + * Copyright (c) 2022, Glenford Williams * * 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); + } } } } -- cgit v1.2.3