]> cloud.milkyroute.net Git - dolphin.git/commitdiff
[Inline Rename] Move cursor to correct position on pressing Home and End
authorChinmoy Ranjan Pradhan <chinmoyrp65@gmail.com>
Sun, 5 May 2019 13:00:19 +0000 (18:30 +0530)
committerChinmoy Ranjan Pradhan <chinmoyrp65@gmail.com>
Sun, 12 May 2019 11:03:14 +0000 (16:33 +0530)
Summary:
When pressing home or end key on a wrapped file name the cursor should move to beginning or end of the whole file name
instead of the last line (which is the default behaviour of any textedit widget).

BUG: 363179

Reviewers: #dolphin, elvisangelaccio

Subscribers: kfm-devel

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D21031

src/kitemviews/private/kitemlistroleeditor.cpp

index e79a9f9d144483a2b023499490fffd0f9be7e78b..eb6f1de767c48a44f964dcd8bb8704ed9a85bf34 100644 (file)
@@ -107,6 +107,23 @@ void KItemListRoleEditor::keyPressEvent(QKeyEvent* event)
         }
         break;
     }
+    case Qt::Key_Home:
+    case Qt::Key_End: {
+        if (event->modifiers() == Qt::NoModifier || event->modifiers() == Qt::ShiftModifier) {
+            const QTextCursor::MoveOperation op = event->key() == Qt::Key_Home
+                                                ? QTextCursor::Start
+                                                : QTextCursor::End;
+            const QTextCursor::MoveMode mode = event->modifiers() == Qt::NoModifier
+                                             ? QTextCursor::MoveAnchor
+                                             : QTextCursor::KeepAnchor;
+            QTextCursor cursor = textCursor();
+            cursor.movePosition(op, mode);
+            setTextCursor(cursor);
+            event->accept();
+            return;
+        }
+        break;
+    }
     default:
         break;
     }