From 88e945a8561b50d617334788ad3f82b9a69627b6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Thu, 9 Mar 2023 13:26:40 -0500
Subject: [PATCH] searchbar: fix keyboard shortcuts

+ Ctrl+F should focus the sidebar's searchbar
+ Ctrl+Shift+F focus the messages search

This was mostly due to multiple search bar shown, so multiple
shortcut enabled.

Change-Id: Ib910bbdc7c90e3b57846fb316b4b68d4e929b8d8
GitLab: #1028
---
 src/app/mainview/components/ChatViewHeader.qml   |  9 +++++++++
 src/app/mainview/components/ContactSearchBar.qml | 16 +++++-----------
 .../components/KeyboardShortcutTable.qml         |  7 ++++++-
 src/app/mainview/components/Searchbar.qml        |  6 ++++++
 src/app/mainview/components/SidePanel.qml        |  8 ++++++++
 5 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/src/app/mainview/components/ChatViewHeader.qml b/src/app/mainview/components/ChatViewHeader.qml
index ba3847f1b..8ac169d16 100644
--- a/src/app/mainview/components/ChatViewHeader.qml
+++ b/src/app/mainview/components/ChatViewHeader.qml
@@ -159,6 +159,15 @@ Rectangle {
                 Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
                 spacing: headerButtons.spacing
                 visible: root.showSearch && CurrentConversation.isSwarm
+
+                Shortcut {
+                    sequence: "Ctrl+Shift+F"
+                    context: Qt.ApplicationShortcut
+                    enabled: rowSearchBar.visible
+                    onActivated: {
+                        rowSearchBar.openSearchBar()
+                    }
+                }
             }
 
             PushButton {
diff --git a/src/app/mainview/components/ContactSearchBar.qml b/src/app/mainview/components/ContactSearchBar.qml
index d8bc6bc59..d416cf5ad 100644
--- a/src/app/mainview/components/ContactSearchBar.qml
+++ b/src/app/mainview/components/ContactSearchBar.qml
@@ -35,14 +35,16 @@ Rectangle {
 
     function clearText() {
         contactSearchBar.clear()
-        fakeFocus.forceActiveFocus()
+        contactSearchBar.forceActiveFocus()
     }
 
     radius: JamiTheme.primaryRadius
     color: JamiTheme.secondaryBackgroundColor
 
-    FocusScope {
-        id: fakeFocus
+    onFocusChanged: {
+        if (focus) {
+            contactSearchBar.forceActiveFocus()
+        }
     }
 
     LineEditContextMenu {
@@ -125,14 +127,6 @@ Rectangle {
         }
     }
 
-    Shortcut {
-        sequence: "Ctrl+F"
-        context: Qt.ApplicationShortcut
-        onActivated: {
-            contactSearchBar.forceActiveFocus()
-        }
-    }
-
     Keys.onPressed: function (keyEvent) {
         if (keyEvent.key === Qt.Key_Enter ||
                 keyEvent.key === Qt.Key_Return) {
diff --git a/src/app/mainview/components/KeyboardShortcutTable.qml b/src/app/mainview/components/KeyboardShortcutTable.qml
index 948446b10..8bba7e509 100644
--- a/src/app/mainview/components/KeyboardShortcutTable.qml
+++ b/src/app/mainview/components/KeyboardShortcutTable.qml
@@ -108,6 +108,11 @@ Window {
             shortcut2: ""
             description: qsTr("Clear history")
         }
+        ListElement {
+            shortcut: "Ctrl + Shift + F"
+            shortcut2: ""
+            description: qsTr("Search messages/files")
+        }
         ListElement {
             shortcut: "Ctrl + Shift + B"
             shortcut2: ""
@@ -119,7 +124,7 @@ Window {
             description: qsTr("Remove conversation")
         }
         ListElement {
-            shortcut: "Shift + Ctrl + A"
+            shortcut: "Ctrl + Shift + A"
             shortcut2: ""
             description: qsTr("Accept contact request")
         }
diff --git a/src/app/mainview/components/Searchbar.qml b/src/app/mainview/components/Searchbar.qml
index c31f94df5..0bce54340 100644
--- a/src/app/mainview/components/Searchbar.qml
+++ b/src/app/mainview/components/Searchbar.qml
@@ -37,6 +37,10 @@ RowLayout {
     property bool isOpened: false
 
     function openSearchBar() {
+        if (isOpened) {
+            textArea.forceActiveFocus()
+            return
+        }
         searchBarOpened()
         rectTextArea.isSearch = true
         anim.start()
@@ -45,6 +49,8 @@ RowLayout {
     }
 
     function closeSearchbar() {
+        if (!isOpened)
+            return
         searchBarClosed()
         rectTextArea.isSearch = false
         anim.start()
diff --git a/src/app/mainview/components/SidePanel.qml b/src/app/mainview/components/SidePanel.qml
index 965990a7d..721b1ec38 100644
--- a/src/app/mainview/components/SidePanel.qml
+++ b/src/app/mainview/components/SidePanel.qml
@@ -261,6 +261,14 @@ BaseView {
                     anchors.right: parent.right
                     anchors.rightMargin: 15
 
+                    Shortcut {
+                        sequence: "Ctrl+F"
+                        context: Qt.ApplicationShortcut
+                        onActivated: {
+                            contactSearchBar.forceActiveFocus()
+                        }
+                    }
+
                     ContactSearchBar {
                         id: contactSearchBar
 
-- 
GitLab