From 8416e3de662ee8075e2ffd0c71589ffdecd1f6b3 Mon Sep 17 00:00:00 2001 From: Nate Graham Date: Wed, 4 Aug 2021 11:24:46 -0600 Subject: [PATCH] [applets/clipboard] Delete items with delete key Pressing the delete key will now delete the highlighted list item under any of the following circumstances: 1. A list item is selected and has focus 2. A list item is selected and the search field has focus but it is empty or the insertion point is at the end of the string (in either case, pressing the delete key would otherwise do nothing) This allows quickly and easily deleting clipboard items using only the keyboard, including after using the search field to filter it down. BUG: 439174 FIXED-IN: 5.78 --- .../clipboard/contents/ui/ClipboardItemDelegate.qml | 3 +++ applets/clipboard/contents/ui/ClipboardPage.qml | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/applets/clipboard/contents/ui/ClipboardItemDelegate.qml b/applets/clipboard/contents/ui/ClipboardItemDelegate.qml index 253b9d9ed..47a074f87 100644 --- a/applets/clipboard/contents/ui/ClipboardItemDelegate.qml +++ b/applets/clipboard/contents/ui/ClipboardItemDelegate.qml @@ -60,6 +60,9 @@ PlasmaExtras.ListItem { menuListView.currentIndex = -1 } } + Keys.onDeletePressed: { + remove(UuidRole); + } ListView.onIsCurrentItemChanged: { if (ListView.isCurrentItem) { diff --git a/applets/clipboard/contents/ui/ClipboardPage.qml b/applets/clipboard/contents/ui/ClipboardPage.qml index 260ef1168..004661a91 100644 --- a/applets/clipboard/contents/ui/ClipboardPage.qml +++ b/applets/clipboard/contents/ui/ClipboardPage.qml @@ -90,6 +90,19 @@ ColumnLayout { clearButtonShown: true Layout.fillWidth: true + // Only override delete key behavior to delete list items if + // it would do nothing + Keys.enabled: filter.text.length == 0 || filter.cursorPosition == filter.length + Keys.onDeletePressed: { + let clipboardItemIndex = clipboardMenu.view.currentIndex + if (clipboardItemIndex != -1) { + let uuid = clipboardMenu.model.get(clipboardItemIndex).UuidRole + if (uuid) { + clipboardMenu.view.currentItem.remove(uuid); + } + } + } + Connections { target: main function onClearSearchField() {