From 3dcd25383b3f52228f1b5bef2e80aeb835004cdd Mon Sep 17 00:00:00 2001 From: RickyRister Date: Tue, 31 Dec 2024 18:38:56 -0800 Subject: [PATCH] maintain reselection behavior when deleting single selection --- cockatrice/src/client/tabs/tab_deck_editor.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cockatrice/src/client/tabs/tab_deck_editor.cpp b/cockatrice/src/client/tabs/tab_deck_editor.cpp index 01cd911c8..a10dc91f3 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.cpp +++ b/cockatrice/src/client/tabs/tab_deck_editor.cpp @@ -1320,6 +1320,12 @@ void TabDeckEditor::actRemoveCard() { auto selectedRows = getSelectedCardNodes(); + // hack to maintain the old reselection behavior when currently selected row of a single-selection gets deleted + // TODO: remove the hack and also handle reselection when all rows of a multi-selection gets deleted + if (selectedRows.length() == 1) { + deckView->setSelectionMode(QAbstractItemView::SingleSelection); + } + bool modified = false; for (const auto &index : selectedRows) { if (!index.isValid() || deckModel->hasChildren(index)) { @@ -1329,6 +1335,8 @@ void TabDeckEditor::actRemoveCard() modified = true; } + deckView->setSelectionMode(QAbstractItemView::ExtendedSelection); + if (modified) { DeckLoader *const deck = deckModel->getDeckList(); setSaveStatus(!deck->isEmpty()); @@ -1399,9 +1407,17 @@ void TabDeckEditor::actDecrement() { auto selectedRows = getSelectedCardNodes(); + // hack to maintain the old reselection behavior when currently selected row of a single-selection gets deleted + // TODO: remove the hack and also handle reselection when all rows of a multi-selection gets deleted + if (selectedRows.length() == 1) { + deckView->setSelectionMode(QAbstractItemView::SingleSelection); + } + for (const auto &index : selectedRows) { offsetCountAtIndex(index, -1); } + + deckView->setSelectionMode(QAbstractItemView::ExtendedSelection); } void TabDeckEditor::setDeck(DeckLoader *_deck)