[system/dolphin] src: Make inline-rename re-triggering robust and add a regression test
Méven Car <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 28ed41399aab91a040ce9fbf3510df5893777dd6 by Méven Car.
Committed on 18/07/2026 at 12:02.
Pushed by meven into branch 'master'.
Make inline-rename re-triggering robust and add a regression test
Triggering inline renaming again on the item already being renamed (for
example pressing F2 twice) must not disturb the running edit. Two follow-ups:
- DolphinView::renameSelectedItems() connects roleEditingFinished to
slotRoleEditingFinished inside a deferred scrollingStopped lambda. A second
trigger runs that lambda again and used to add a duplicate connection. Pass
Qt::UniqueConnection so the second trigger is a no-op.
- Add KItemListControllerTest::testRestartingInlineRenameKeepsEditor(),
asserting that a second editRole() on the item already being edited does not
cancel the ongoing edit (which would silently drop the pending rename).
BUG: 514401
M +26 -1 src/tests/kitemlistcontrollertest.cpp
M +1 -1 src/views/dolphinview.cpp
https://invent.kde.org/system/dolphin/-/commit/28ed41399aab91a040ce9fbf3510df5893777dd6
diff --git a/src/tests/kitemlistcontrollertest.cpp b/src/tests/kitemlistcontrollertest.cpp
index 2d5aad4563..fad1e1c6c1 100644
--- a/src/tests/kitemlistcontrollertest.cpp
+++ b/src/tests/kitemlistcontrollertest.cpp
@@ -87,7 +87,7 @@ private Q_SLOTS:
void testDragLeaveHoverCleanup();
void testCollapsibleGroups();
-
+ void testRestartingInlineRenameKeepsEditor();
private:
/**
* Make sure that the number of columns in the view is equal to \a count
@@ -1442,6 +1442,31 @@ void KItemListControllerTest::testCollapsibleGroups()
QCOMPARE(m_view->m_layouter->itemRect(3), itemRectBeforeCollapse);
}
+void KItemListControllerTest::testRestartingInlineRenameKeepsEditor()
+{
+ // Regression test: triggering inline renaming again on the item that is already being
+ // renamed (e.g. pressing F2 a second time) must be a no-op. It must NOT cancel the running
+ // edit - doing so used to silently discard the pending rename, so a later commit did nothing.
+ // See KItemListView::editRole().
+ m_selectionManager->setCurrentItem(0);
+
+ m_view->editRole(0, "text"); // start editing item 0
+
+ QSignalSpy canceledSpy(m_view, &KItemListView::roleEditingCanceled);
+ QSignalSpy finishedSpy(m_view, &KItemListView::roleEditingFinished);
+ QVERIFY(canceledSpy.isValid());
+
+ m_view->editRole(0, "text"); // "second F2" on the same item and role
+
+ // The ongoing edit must be left untouched: neither canceled nor finished.
+ QCOMPARE(canceledSpy.count(), 0);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ // Sanity check that the edit really was live: clearing the edited role now cancels it.
+ m_view->editRole(0, QByteArray());
+ QVERIFY(canceledSpy.count() >= 1);
+}
+
QTEST_MAIN(KItemListControllerTest)
#include "kitemlistcontrollertest.moc"
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index 78b8b99496..ac69a408ee 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -866,7 +866,7 @@ void DolphinView::renameSelectedItems()
hideToolTip();
- connect(m_view, &DolphinItemListView::roleEditingFinished, this, &DolphinView::slotRoleEditingFinished);
+ connect(m_view, &DolphinItemListView::roleEditingFinished, this, &DolphinView::slotRoleEditingFinished, Qt::UniqueConnection);
},
Qt::SingleShotConnection);
m_view->scrollToItem(index);