Repository: spyder-ide/spyder

Issue:
Find pane does not set focus in text field
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [ ] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

Ctrl+Shift+F does not focus on "Write text to search" anymore, as it did in Spyder 4.
This breaks any useful workflow with it.

The code looks like it should only switch to it, but setting the focus would be useful:
https://github.com/spyder-ide/spyder/blob/aecad5d083369913d5a876c19b69301758a274ce/spyder/config/main.py#L401

Using Alt+Shift+F works as a workaround if the relevant search phrase is marked, but does not work well, if I want to paste from clipboard (as I have to set the focus accordingly with the mouse)

https://github.com/spyder-ide/spyder/blob/aecad5d083369913d5a876c19b69301758a274ce/spyder/config/main.py#L537

With spyder4 Ctrl+Shift+F covered the workflow pretty well

### What steps reproduce the problem?

1. Cursor placed in code
2. Ctrl+Shift+F or Alt+Shift+F does nothing but switching the window, focus stays in code window
3. Ctrl+V pastes into code window

1. Cursor marked code
2. Alt+Shift+F searches for marked code, Ctrl+Shift+F does nothing

### What is the expected output? What do you see instead?

Pressing either sequence should put the cursor focus correctly into the search field

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

PASTE TRACEBACK HERE

```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 5.2.2
* Python version: 3.9.7
* Qt version: Qt 5.12.10
* PyQt version:  pyqt
* Operating System name/version: GNU/Linux Debian

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
PASTE DEPENDENCIES HERE
```



Discussion:
Hey @maurerle, thanks for reporting. You're right about this problem and we'll try to fix it in a future release.

Resolving patch:
diff --git a/spyder/plugins/findinfiles/plugin.py b/spyder/plugins/findinfiles/plugin.py
--- a/spyder/plugins/findinfiles/plugin.py
+++ b/spyder/plugins/findinfiles/plugin.py
@@ -43,6 +43,7 @@ class FindInFiles(SpyderDockablePlugin):
     WIDGET_CLASS = FindInFilesWidget
     CONF_SECTION = NAME
     CONF_FILE = False
+    RAISE_AND_FOCUS = True
 
     # --- SpyderDocakblePlugin API
     # ------------------------------------------------------------------------


Test patch:
diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py
--- a/spyder/app/tests/test_mainwindow.py
+++ b/spyder/app/tests/test_mainwindow.py
@@ -4683,10 +4683,10 @@ def foo(x):
 @pytest.mark.slow
 @flaky(max_runs=3)
 @pytest.mark.skipif(os.name == 'nt', reason="Tour messes up focus on Windows")
-def test_focus_to_consoles(main_window, qtbot):
+def test_focus_for_plugins_with_raise_and_focus(main_window, qtbot):
     """
-    Check that we give focus to the text widget of our consoles after focus
-    is given to their dockwidgets.
+    Check that we give focus to the focus widget declared by plugins that use
+    the RAISE_AND_FOCUS class constant.
     """
     # Wait for the console to be up
     shell = main_window.ipyconsole.get_current_shellwidget()
@@ -4710,6 +4710,12 @@ def test_focus_to_consoles(main_window, qtbot):
     focus_widget = QApplication.focusWidget()
     assert focus_widget is console.get_widget().get_focus_widget()
 
+    # Switch to Find and assert focus is given to its focus widget
+    find = main_window.get_plugin(Plugins.Find)
+    find.toggle_view_action.setChecked(True)
+    focus_widget = QApplication.focusWidget()
+    assert focus_widget is find.get_widget().get_focus_widget()
+
 
 @pytest.mark.slow
 @flaky(max_runs=3)