@@ -44,8 +44,8 @@ Item {
4444 if (!searchHistory) return;
4545
4646 searchHistory.addQuery(searchField.text);
47+ unfocus();
4748 searchField.text = "";
48− searchField.focus = false;
4949 }
5050
5151 function unfocus() {
@@ -112,6 +112,8 @@ Item {
112112 objectName: "searchContainer"
113113
114114 visible: searchEntryEnabled
115+ property bool popoverShouldOpen: false
116+ property bool popoverShouldClose: false
115117
116118 property bool narrowMode: parent.width < label.contentWidth + units.gu(50)
117119
@@ -127,6 +129,16 @@ Item {
127129 else if (active && !narrowMode) "active"
128130 else if (!active && !narrowMode) "inactive"
129131
132+ onStateChanged: {
133+ if (state == "active" || state == "narrowActive") {
134+ popoverShouldOpen = true;
135+ popoverShouldClose = false;
136+ } else {
137+ popoverShouldOpen = false;
138+ popoverShouldClose = true;
139+ }
140+ }
141+
130142 function openPopover() {
131143 if (searchHistory.count > 0) {
132144 searchContainer.popover = PopupUtils.open(popoverComponent, searchField,
@@ -137,10 +149,17 @@ Item {
137149 }
138150 )
139151 }
152+ popoverShouldOpen = false;
153+ popoverShouldClose = false;
140154 }
141155
142156 function closePopover() {
143− if (searchContainer.popover) PopupUtils.close(searchContainer.popover)
157+ if (searchContainer.popover) {
158+ PopupUtils.close(searchContainer.popover);
159+ searchContainer.popover = null;
160+ }
161+ popoverShouldOpen = false;
162+ popoverShouldClose = false;
144163 }
145164
146165 onActiveFocusChanged: if (!activeFocus) { searchHistory.addQuery(searchField.text) }
@@ -283,12 +302,12 @@ Item {
283302 PropertyAction { target: primaryImage; property: "source" }
284303 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
285304 }
286− ScriptAction { script: searchContainer.openPopover() }
305+ ScriptAction { script: if (searchContainer.popoverShouldOpen) { searchContainer.openPopover(); } }
287306 }
288307 },
289308 Transition {
290309 to: "inactive"
291− ScriptAction { script: searchContainer.closePopover() }
310+ ScriptAction { script: if (searchContainer.popoverShouldClose) { searchContainer.closePopover(); } }
292311 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.InOutQuad }
293312 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
294313 },
@@ -299,12 +318,12 @@ Item {
299318 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.OutQuad }
300319 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
301320 }
302− ScriptAction { script: searchContainer.openPopover() }
321+ ScriptAction { script: if (searchContainer.popoverShouldOpen) { searchContainer.openPopover(); } }
303322 }
304323 },
305324 Transition {
306325 to: "narrowInactive"
307− ScriptAction { script: searchContainer.closePopover() }
326+ ScriptAction { script: if (searchContainer.popoverShouldClose) { searchContainer.closePopover(); } }
308327 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.OutQuad }
309328 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
310329 }