Commit 5d1b3718 authored by Nate Graham's avatar Nate Graham 🔩
Browse files

Fix search field focus, both initial and on-demand

Summary:
Right now the search field doesn't get focus initially, or when the user types on a page.
This is because the conditional loader that conditionally loads the GlobalDrawer's
toolbar containing the search field isn't able to pass on focus or signals to its content
properly. I tried various methods of fixing this by adding `focus: true` to all the focus
stopes in the chain, but was unsuccessful. So this patch implements the conditional
loading of the top content differently: instead the top content is always loaded, but
conditionally discarded when in non-widescreen mode. This fixes the aforementioned issues.

However it may not be the correct way to fix the problem; if not, assistance would be
appreciated.

BUG: 413407
FIXED-IN: 5.18.0

Test Plan:
- Search field has focus when Discover is launched
- Search field gains focus and accept text when typing anywhere
- When the window is made mobiley, the sidebar's toolbar disappears
- When a mobiley window is made desktoppy, the sidebar;s toolbar re-appears

Reviewers: #discover_software_store, apol, davidedmundson

Reviewed By: #discover_software_store, apol

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24935
parent 87e14561
......@@ -62,61 +62,60 @@ Kirigami.GlobalDrawer {
}
function suggestSearchText(text) {
toploader.item.text = text
toploader.item.forceActiveFocus()
searchField.text = text
searchField.forceActiveFocus()
}
topContent: ConditionalLoader {
id: toploader
condition: !modal
Layout.fillWidth: true
componentFalse: Item {
Layout.minimumHeight: 1
}
componentTrue: Kirigami.AbstractApplicationHeader {
preferredHeight: 40 // Match Kirigami.ToolBarApplicationHeader, which is hardcoded to this
RowLayout {
anchors.fill: parent
anchors.leftMargin: Kirigami.Units.smallSpacing
anchors.rightMargin: Kirigami.Units.smallSpacing
// Give the search field keyboard focus by default
Component.onCompleted: {
searchField.forceActiveFocus();
}
SearchField {
id: searchField
topContent: Kirigami.AbstractApplicationHeader {
id: toolbar
preferredHeight: 40 // Match Kirigami.ToolBarApplicationHeader, which is hardcoded to this
Layout.fillWidth: true
RowLayout {
anchors.fill: parent
anchors.leftMargin: Kirigami.Units.smallSpacing
anchors.rightMargin: Kirigami.Units.smallSpacing
visible: window.leftPage && (window.leftPage.searchFor !== null || window.leftPage.hasOwnProperty("search"))
SearchField {
id: searchField
page: window.leftPage
Layout.fillWidth: true
onCurrentSearchTextChanged: {
var curr = window.leftPage;
visible: window.leftPage && (window.leftPage.searchFor !== null || window.leftPage.hasOwnProperty("search"))
if (pageStack.depth>1)
pageStack.pop()
page: window.leftPage
if (currentSearchText === "" && window.currentTopLevel === "" && !window.leftPage.category) {
Navigation.openHome()
} else if (!curr.hasOwnProperty("search")) {
if (currentSearchText) {
Navigation.clearStack()
Navigation.openApplicationList( { search: currentSearchText })
}
} else {
curr.search = currentSearchText;
curr.forceActiveFocus()
onCurrentSearchTextChanged: {
var curr = window.leftPage;
if (pageStack.depth>1)
pageStack.pop()
if (currentSearchText === "" && window.currentTopLevel === "" && !window.leftPage.category) {
Navigation.openHome()
} else if (!curr.hasOwnProperty("search")) {
if (currentSearchText) {
Navigation.clearStack()
Navigation.openApplicationList( { search: currentSearchText })
}
} else {
curr.search = currentSearchText;
curr.forceActiveFocus()
}
}
}
ToolButton {
ToolButton {
icon.name: "go-home"
onClicked: Navigation.openHome()
icon.name: "go-home"
onClicked: Navigation.openHome()
ToolTip {
text: i18n("Return to the Featured page")
}
ToolTip {
text: i18n("Return to the Featured page")
}
}
}
......@@ -162,11 +161,13 @@ Kirigami.GlobalDrawer {
name: "full"
when: drawer.wideScreen
PropertyChanges { target: drawer; drawerOpen: true }
PropertyChanges { target: drawer; topContent: toolbar }
},
State {
name: "compact"
when: !drawer.wideScreen
PropertyChanges { target: drawer; drawerOpen: false }
PropertyChanges { target: drawer; topContent: null }
}
]
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment