From ac3b8b821d5473858ef20cd82ca842d21785d968 Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Tue, 29 Sep 2020 11:44:33 -0400
Subject: [PATCH] smartlist: keep focus when clearing the search field

- the focus should be grabbed when selecting another view or
  conversation

Change-Id: I41ab6a7a743615269c4dde01b5503a3ae21a836d
Gitlab: #110
---
 src/mainview/components/ContactSearchBar.qml               | 6 ------
 src/mainview/components/ConversationSmartListView.qml      | 6 ------
 .../components/ConversationSmartListViewItemDelegate.qml   | 3 +--
 src/mainview/components/SidePanel.qml                      | 7 +------
 4 files changed, 2 insertions(+), 20 deletions(-)

diff --git a/src/mainview/components/ContactSearchBar.qml b/src/mainview/components/ContactSearchBar.qml
index 40704ff84..6db304f70 100644
--- a/src/mainview/components/ContactSearchBar.qml
+++ b/src/mainview/components/ContactSearchBar.qml
@@ -27,12 +27,6 @@ Rectangle {
 
     signal contactSearchBarTextChanged(string text)
 
-    // Hack - there is no real way now to make TextField lose its focus,
-    // unless transfer it to other component.
-    function clearFocus() {
-        fakeFocus.forceActiveFocus()
-    }
-
     function clearText() {
         contactSearchBar.clear()
         fakeFocus.forceActiveFocus()
diff --git a/src/mainview/components/ConversationSmartListView.qml b/src/mainview/components/ConversationSmartListView.qml
index 001bed352..7f8c16f99 100644
--- a/src/mainview/components/ConversationSmartListView.qml
+++ b/src/mainview/components/ConversationSmartListView.qml
@@ -29,10 +29,8 @@ ListView {
     signal needToAccessMessageWebView(string currentUserDisplayName, string currentUserAlias, string currentUID, bool callStackViewShouldShow, bool isAudioOnly, int callState)
     signal needToSelectItems(string conversationUid)
     signal needToDeselectItems
-    signal needToGrabFocus
 
     signal needToShowChatView(string accountId, string convUid)
-    signal currentIndexIsChanged
     signal forceUpdatePotentialInvalidItem
 
     // Refresh all items within the model.
@@ -81,10 +79,6 @@ ListView {
         function onUpdateSmartList() { updateListView() }
     }
 
-    onCurrentIndexChanged: {
-        root.currentIndexIsChanged()
-    }
-
     clip: true
 
     delegate: ConversationSmartListViewItemDelegate {
diff --git a/src/mainview/components/ConversationSmartListViewItemDelegate.qml b/src/mainview/components/ConversationSmartListViewItemDelegate.qml
index 12cc257d3..f7a415ade 100644
--- a/src/mainview/components/ConversationSmartListViewItemDelegate.qml
+++ b/src/mainview/components/ConversationSmartListViewItemDelegate.qml
@@ -42,7 +42,7 @@ ItemDelegate {
 
 
         // When currentIndex is -1, deselect items, if not, change select item
-        function onCurrentIndexIsChanged() {
+        function onCurrentIndexChanged() {
             if (conversationSmartListView.currentIndex === -1
                     || conversationSmartListView.currentIndex !== index) {
                 itemSmartListBackground.color = Qt.binding(function () {
@@ -55,7 +55,6 @@ ItemDelegate {
                                                1.8) : JamiTheme.releaseColor
                 })
                 conversationSmartListView.needToSelectItems(UID)
-                conversationSmartListView.needToGrabFocus()
             }
         }
 
diff --git a/src/mainview/components/SidePanel.qml b/src/mainview/components/SidePanel.qml
index 3fdbb7c09..de122ebc7 100644
--- a/src/mainview/components/SidePanel.qml
+++ b/src/mainview/components/SidePanel.qml
@@ -46,8 +46,7 @@ Rectangle {
     // For contact request conv to be focused correctly.
     function setCurrentUidSmartListModelIndex() {
         conversationSmartListView.currentIndex
-                = conversationSmartListView.model.currentUidSmartListModelIndex(
-                    )
+                = conversationSmartListView.model.currentUidSmartListModelIndex()
     }
 
     function updatePendingRequestCount() {
@@ -205,10 +204,6 @@ Rectangle {
                         isAudioOnly, callState)
         }
 
-        onNeedToGrabFocus: {
-            contactSearchBar.clearFocus()
-        }
-
         Component.onCompleted: {
             ConversationsAdapter.setQmlObject(this)
             conversationSmartListView.currentIndex = -1
-- 
GitLab