Select entry above deleted entry

* Fix #6304 - Don't cause the list view to scroll to the top when deleting any entry in the list.
This commit is contained in:
hollow-owl 2021-08-17 00:00:41 -05:00 committed by Jonathan White
parent 746276edea
commit af9eb6d6b1
3 changed files with 24 additions and 3 deletions

View File

@ -462,8 +462,16 @@ void DatabaseWidget::deleteSelectedEntries()
void DatabaseWidget::deleteEntries(QList<Entry*> selectedEntries, bool confirm) void DatabaseWidget::deleteEntries(QList<Entry*> selectedEntries, bool confirm)
{ {
if (selectedEntries.isEmpty()) {
return;
}
// Find the index above the first entry for selection after deletion
auto index = m_entryView->indexFromEntry(selectedEntries.first());
index = m_entryView->indexAbove(index);
// Confirm entry removal before moving forward // Confirm entry removal before moving forward
auto* recycleBin = m_db->metadata()->recycleBin(); auto recycleBin = m_db->metadata()->recycleBin();
bool permanent = (recycleBin && recycleBin->findEntryByUuid(selectedEntries.first()->uuid())) bool permanent = (recycleBin && recycleBin->findEntryByUuid(selectedEntries.first()->uuid()))
|| !m_db->metadata()->recycleBinEnabled(); || !m_db->metadata()->recycleBinEnabled();
@ -475,8 +483,15 @@ void DatabaseWidget::deleteEntries(QList<Entry*> selectedEntries, bool confirm)
refreshSearch(); refreshSearch();
m_entryView->setFirstEntryActive(); // Select the row above the deleted entries
auto* currentEntry = currentSelectedEntry(); if (index.isValid()) {
m_entryView->setCurrentIndex(index);
} else {
m_entryView->setFirstEntryActive();
}
// Update the preview widget
auto currentEntry = currentSelectedEntry();
if (currentEntry) { if (currentEntry) {
m_previewView->setEntry(currentEntry); m_previewView->setEntry(currentEntry);
} else { } else {

View File

@ -289,6 +289,11 @@ Entry* EntryView::entryFromIndex(const QModelIndex& index)
} }
} }
QModelIndex EntryView::indexFromEntry(Entry* entry)
{
return m_sortModel->mapFromSource(m_model->indexFromEntry(entry));
}
int EntryView::currentEntryIndex() int EntryView::currentEntryIndex()
{ {
QModelIndexList list = selectionModel()->selectedRows(); QModelIndexList list = selectionModel()->selectedRows();

View File

@ -39,6 +39,7 @@ public:
Entry* currentEntry(); Entry* currentEntry();
void setCurrentEntry(Entry* entry); void setCurrentEntry(Entry* entry);
Entry* entryFromIndex(const QModelIndex& index); Entry* entryFromIndex(const QModelIndex& index);
QModelIndex indexFromEntry(Entry* entry);
int currentEntryIndex(); int currentEntryIndex();
bool inSearchMode(); bool inSearchMode();
bool isSorted(); bool isSorted();