From 5b213e614498e9c0b33c1c30887dc34fbfea3733 Mon Sep 17 00:00:00 2001 From: Simon Redman Date: Mon, 17 Dec 2018 09:25:33 -0700 Subject: [PATCH] [SMS App] Improve filter Summary: - Allow filter box to handle keystrokes passed to the ListView - This is a little cheesy, but fixes T8341 - Pin filter box to always be visible - Clear filter on Esc Test Plan: - Try typing a contact you would like to search for - Before: Every time you type a new letter, the filter box would lose focus and you would have to click it to give it focus again - Now: You can type smoothly - Try scrolling the list - Before: The filter box disappeared off the top of the screen - Now: The filter box is always visible - Try pressing escape - Before: Nothing - Now: Filter clears - Bonus: When using the arrow keys to navigate, before the filter was manually handling those and the view would not loop. Now, the view loops if you try to select an item past the beginning or end (Easiest to see with highlighting from D17612) Reviewers: #kde_connect, apol Reviewed By: #kde_connect, apol Subscribers: kdeconnect Tags: #kde_connect Maniphest Tasks: T8341 Differential Revision: https://phabricator.kde.org/D17614 --- smsapp/qml/ConversationList.qml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/smsapp/qml/ConversationList.qml b/smsapp/qml/ConversationList.qml index 5b4428b4e..7e1a86ff7 100644 --- a/smsapp/qml/ConversationList.qml +++ b/smsapp/qml/ConversationList.qml @@ -71,23 +71,36 @@ Kirigami.ScrollablePage } header: TextField { + /** + * Used as the filter of the list of messages + */ id: filter placeholderText: i18n("Filter...") width: parent.width + z: 10 onTextChanged: { view.model.setFilterFixedString(filter.text); view.currentIndex = 0 } - Keys.onUpPressed: view.currentIndex = Math.max(view.currentIndex-1, 0) - Keys.onDownPressed: view.currentIndex = Math.min(view.currentIndex+1, view.count-1) onAccepted: { view.currentItem.startChat() } + Keys.onReturnPressed: { + event.accepted = true + filter.onAccepted() + } + Keys.onEscapePressed: { + event.accepted = filter.text != "" + filter.text = "" + } Shortcut { sequence: "Ctrl+F" onActivated: filter.forceActiveFocus() } } + headerPositioning: ListView.OverlayHeader + + Keys.forwardTo: [headerItem] delegate: Kirigami.BasicListItem {