]> cloud.milkyroute.net Git - dolphin.git/commitdiff
KFileItemListWidget: wrong selection when renamed file ends with a dot
authorShitong Xu <xushitong@uniontech.com>
Sun, 23 Mar 2025 15:02:24 +0000 (15:02 +0000)
committerFelix Ernst <felixernst@kde.org>
Sun, 23 Mar 2025 15:02:24 +0000 (15:02 +0000)
When a file name ends with a dot, it should be treated like there is no
extension. When triggering a rename, the file name except the
extension should be selected, which is equal to the full file name when
the file ends with a dot.

src/kitemviews/kfileitemlistwidget.cpp

index 3a7b37895a70879c6f450baf98eed4f1f27695c2..e1da7192a20fc9b3fe7526c9dcc4c1c56f6c55c2 100644 (file)
@@ -176,15 +176,14 @@ int KFileItemListWidget::selectionLength(const QString &text) const
     const QString extension = db.suffixForFileName(text);
     if (extension.isEmpty()) {
         // For an unknown extension just exclude the extension after
-        // the last point. This does not work for multiple extensions like
+        // the last dot. This does not work for multiple extensions like
         // *.tar.gz but usually this is anyhow a known extension.
         indexOfExtension = text.lastIndexOf(QLatin1Char('.'));
 
-        // If no point could be found, use whole text length for selection.
-        if (indexOfExtension < 1) {
+        // if there either is no dot, or the last dot is the first or last char, treat as no extension.
+        if (indexOfExtension < 1 || indexOfExtension == text.length() - 1) {
             indexOfExtension = text.length();
         }
-
     } else {
         indexOfExtension -= extension.length() + 1;
     }