[system/dolphin/release/26.08] 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 7ca6daea69a38c006a001bb423b9398b639d027f by Méven Car.
Committed on 19/07/2026 at 09:43.
Pushed by meven into branch 'release/26.08'.

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
(cherry picked from commit 28ed41399aab91a040ce9fbf3510df5893777dd6)

M  +27   -0    src/tests/kitemlistcontrollertest.cpp
M  +1    -1    src/views/dolphinview.cpp

https://invent.kde.org/system/dolphin/-/commit/7ca6daea69a38c006a001bb423b9398b639d027f

diff --git a/src/tests/kitemlistcontrollertest.cpp b/src/tests/kitemlistcontrollertest.cpp
index 2125755bb7..baaadb4baa 100644
--- a/src/tests/kitemlistcontrollertest.cpp
+++ b/src/tests/kitemlistcontrollertest.cpp
@@ -85,6 +85,8 @@ private Q_SLOTS:
     void testDragMoveHoverIdempotency();
     void testDragLeaveHoverCleanup();
 
+    void testRestartingInlineRenameKeepsEditor();
+
 private:
     /**
      * Make sure that the number of columns in the view is equal to \a count
@@ -1356,6 +1358,31 @@ void KItemListControllerTest::testDragLeaveHoverCleanup()
     QCOMPARE(hoveredSpy.count(), 1);
 }
 
+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);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.