@@ -176,7 +176,6 @@ FocusScope {
176176 superPressTimer.stop();
177177 superLongPressTimer.stop();
178178 root.focus = true;
179− drawer.focus = true;
180179 if (focusInputField) {
181180 drawer.focusInput();
182181 }
@@ -350,19 +349,26 @@ FocusScope {
350349 bottom: parent.bottom
351350 right: parent.left
352351 onRightMarginChanged: {
353− // Remove (and put back) the focus for the searchfield in
354− // order to hide the copy/paste popover when we move the drawer
355− var hadFocus = drawer.searchTextField.focus;
356− var oldSelectionStart = drawer.searchTextField.selectionStart;
357− var oldSelectionEnd = drawer.searchTextField.selectionEnd;
358− drawer.searchTextField.focus = false;
359− drawer.searchTextField.focus = hadFocus;
360− drawer.searchTextField.select(oldSelectionStart, oldSelectionEnd);
352+ if (fullyOpen && hadFocus) {
353+ // See drawer.onDraggingHorizontallyChanged below
354+ drawer.searchTextField.focus = hadFocus;
355+ drawer.searchTextField.select(oldSelectionStart, oldSelectionEnd);
356+ resetOldFocus();
357+ } else if (fullyClosed) {
358+ drawer.searchTextField.clear();
359+ resetOldFocus();
360+ }
361361 }
362362 }
363363 width: Math.min(root.width, units.gu(81))
364364 panelWidth: panel.width
365365 visible: x > -width
366+ property var fullyOpen: x === 0
367+ property var fullyClosed: x === -width
368+
369+ property var hadFocus: false
370+ property var oldSelectionStart: null
371+ property var oldSelectionEnd: null
366372
367373 Behavior on anchors.rightMargin {
368374 enabled: !dragArea.dragging && !launcherDragArea.drag.active && panel.animate && !drawer.draggingHorizontally
@@ -378,6 +384,12 @@ FocusScope {
378384 root.focus = false;
379385 }
380386
387+ function resetOldFocus() {
388+ hadFocus = false;
389+ oldSelectionStart = null;
390+ oldSelectionEnd = null;
391+ }
392+
381393 Keys.onEscapePressed: {
382394 root.hide()
383395 }
@@ -386,7 +398,15 @@ FocusScope {
386398 anchors.rightMargin = Math.max(-drawer.width, anchors.rightMargin + dragDistance);
387399 }
388400 onDraggingHorizontallyChanged: {
389− if (!draggingHorizontally) {
401+ if (draggingHorizontally) {
402+ // Remove (and put back using anchors.onRightMarginChanged) the
403+ // focus for the searchfield in order to hide the copy/paste
404+ // popover when we move the drawer
405+ hadFocus = drawer.searchTextField.focus;
406+ oldSelectionStart = drawer.searchTextField.selectionStart;
407+ oldSelectionEnd = drawer.searchTextField.selectionEnd;
408+ drawer.searchTextField.focus = false;
409+ } else {
390410 if (drawer.x < -units.gu(10)) {
391411 root.hide();
392412 } else {
@@ -572,6 +592,7 @@ FocusScope {
572592 PropertyChanges {
573593 target: drawer
574594 anchors.rightMargin: 0
595+ focus: false
575596 }
576597 },
577598 State {
@@ -591,6 +612,7 @@ FocusScope {
591612 PropertyChanges {
592613 target: drawer
593614 anchors.rightMargin: -drawer.width + root.x // so we never go past panelWidth, even when teased by tutorial
615+ focus: true
594616 }
595617 },
596618 State {