Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search -> Find text only works for Editor #22453

Closed
mrclary opened this issue Sep 6, 2024 · 10 comments · Fixed by #23145
Closed

Search -> Find text only works for Editor #22453

mrclary opened this issue Sep 6, 2024 · 10 comments · Fixed by #23145

Comments

@mrclary
Copy link
Contributor

mrclary commented Sep 6, 2024

Description

What steps will reproduce the problem?

In Spyder 5, the user could search for text in other panes, e.g. IPython Console, but now this is only allowed in the Editor pane.

Using the keyboard shortcut cmd-F always changes the focus to the Editor pane and opens the find toolbar in the Editor, rather than in the currently focused pane.

Versions

  • Spyder version: 6.0.0 (standalone)
  • Python version: 3.11.9 64-bit
  • Qt version: 5.15.8
  • PyQt5 version: 5.15.9
  • Operating System: macOS-14.6.1-x86_64-i386-64bit

Dependencies

# Mandatory:
aiohttp >=3.9.3                      :  3.10.5 (OK)
asyncssh >=2.14.0,<3.0.0             :  2.17.0 (OK)
atomicwrites >=1.2.0                 :  1.4.1 (OK)
chardet >=2.0.0                      :  5.2.0 (OK)
cloudpickle >=0.5.0                  :  3.0.0 (OK)
cookiecutter >=1.6.0                 :  2.6.0 (OK)
diff_match_patch >=20181111          :  20230430 (OK)
github >=2.3.0                       :  2.4.0 (OK)
importlib_metadata >=4.6.0           :  8.4.0 (OK)
intervaltree >=3.0.2                 :  3.1.0 (OK)
IPython >=8.13.0,<9.0.0,!=8.17.1     :  8.27.0 (OK)
jedi >=0.17.2,<0.20.0                :  0.19.1 (OK)
jellyfish >=0.7                      :  1.1.0 (OK)
jsonschema >=3.2.0                   :  4.23.0 (OK)
keyring >=17.0.0                     :  25.3.0 (OK)
nbconvert >=4.0                      :  7.16.4 (OK)
numpydoc >=0.6.0                     :  1.8.0 (OK)
parso >=0.7.0,<0.9.0                 :  0.8.4 (OK)
pexpect >=4.4.0                      :  4.9.0 (OK)
pickleshare >=0.4                    :  0.7.5 (OK)
psutil >=5.3                         :  6.0.0 (OK)
pygments >=2.0                       :  2.18.0 (OK)
pylint >=3.1,<4                      :  3.2.7 (OK)
pylint_venv >=3.0.2                  :  3.0.3 (OK)
pyls_spyder >=0.4.0                  :  0.4.0 (OK)
pylsp >=1.12.0,<1.13.0               :  1.12.0 (OK)
pylsp_black >=2.0.0,<3.0.0           :  2.0.0 (OK)
pyuca >=1.2                          :  1.2 (OK)
qdarkstyle >=3.2.0,<3.3.0            :  3.2.3 (OK)
qstylizer >=0.2.2                    :  0.2.3 (OK)
qtawesome >=1.3.1,<1.4.0             :  1.3.1 (OK)
qtconsole >=5.6.0,<5.7.0             :  5.6.0 (OK)
qtpy >=2.4.0                         :  2.4.1 (OK)
rtree >=0.9.7                        :  1.3.0 (OK)
setuptools >=49.6.0                  :  73.0.1 (OK)
sphinx >=0.6.6                       :  8.0.2 (OK)
spyder_kernels >=3.0.0,<3.1.0        :  3.0.0 (OK)
superqt >=0.6.2,<1.0.0               :  0.6.7 (OK)
textdistance >=4.2.0                 :  4.6.2 (OK)
three_merge >=0.1.1                  :  0.1.1 (OK)
watchdog >=0.10.3                    :  5.0.1 (OK)
yarl >=1.9.4                         :  1.9.7 (OK)
zmq >=24.0.0                         :  26.2.0 (OK)

# Optional:
cython >=0.21                        :  3.0.11 (OK)
matplotlib >=3.0.0                   :  3.9.2 (OK)
numpy >=1.7                          :  2.1.0 (OK)
pandas >=1.1.1                       :  2.2.2 (OK)
scipy >=0.17.0                       :  1.14.1 (OK)
sympy >=0.7.3                        :  1.13.2 (OK)

# Spyder plugins:
spyder_notebook.notebookplugin 0.6.1 :  0.6.1 (OK)
@OverLordGoldDragon
Copy link
Contributor

FWIW, I don't reproduce this, I can Ctrl + F in IPython. My env here

@ccordoba12
Copy link
Member

That's right, I can't reproduce it on Linux either. So, it seems this is a Mac only problem.

@mrclary, could you take care of it? Thanks!

@mrclary
Copy link
Contributor Author

mrclary commented Sep 7, 2024

Update: making IPython Console active and then selecting Search in the menubar restores the correct behavior. I don't know what could be causing this issue.

find_text

@ccordoba12
Copy link
Member

Update: making IPython Console active and then selecting Search in the menubar restores the correct behavior. I don't know what could be causing this issue.

How did you try to enable the search widget before?

@mrclary
Copy link
Contributor Author

mrclary commented Sep 13, 2024

Update: making IPython Console active and then selecting Search in the menubar restores the correct behavior. I don't know what could be causing this issue.

How did you try to enable the search widget before?

Using cmd-f while the console has focus.

@ccordoba12
Copy link
Member

Ok, but now you're unable to reproduce this problem?

@mrclary
Copy link
Contributor Author

mrclary commented Sep 13, 2024

Ok, but now you're unable to reproduce this problem?

Incorrect. The problem is still reproducible. The correct behavior is restored only for the current Spyder session. If Spyder is restarted, then the issue manifests again.

Perhaps related is that the Search menu items are greyed out, even after the correct behavior is restored. "Replace text" and "Go to line..." should certainly be context dependent (greyed out for IPython Console), but shouldn't "Find text", "Find next", and "Find previous" be selectable for any widget that supports the Search widget?

@dalthviz
Copy link
Member

dalthviz commented Dec 4, 2024

Perhaps related is that the Search menu items are greyed out, even after the correct behavior is restored. "Replace text" and "Go to line..." should certainly be context dependent (greyed out for IPython Console), but shouldn't "Find text", "Find next", and "Find previous" be selectable for any widget that supports the Search widget?

Not sure if an issue exists about that but maybe creating one could be worthy 👍🏼 An initial idea that comes to mind to enable the menu actions to do something like that is to create a plugin that encapsulates the find/replace widget. I would say that as a minimum that plugin should be the one registering the relevant actions over the Search menu and be able to manage the logic necessary for the find/replace actions to trigger the relevant callback depending on the current focused widget (if the focused widget supports using/has a find/replace widget). That minimum logic probably would be similar to what the Editor does currently for the actions over the Edit menu:

def update_edit_menu(self):
"""
Enable edition related actions only when the Editor has focus.
Also enable actions in case the focused widget has editable properties.
"""
# Disabling all actions to begin with
for child in [
self.undo_action, self.redo_action, self.copy_action,
self.cut_action, self.paste_action, self.selectall_action
] + self.edit_menu_actions:
child.setEnabled(False)
possible_text_widget = QApplication.focusWidget()
editor = self.get_current_editor()
readwrite_editor = possible_text_widget == editor
# We need the first validation to avoid a bug at startup. That probably
# happens when the menu is tried to be rendered automatically in some
# Linux distros.
# Fixes spyder-ide/spyder#22432
if editor is not None and readwrite_editor and not editor.isReadOnly():
# Case where the current editor has the focus
if not self.is_file_opened():
return
# Undo, redo
self.undo_action.setEnabled(editor.document().isUndoAvailable())
self.redo_action.setEnabled(editor.document().isRedoAvailable())
# Editor only actions
for action in self.edit_menu_actions:
action.setEnabled(True)
not_readonly = not editor.isReadOnly()
has_selection = editor.has_selected_text()
elif (isinstance(possible_text_widget, BaseEditMixin) and
hasattr(possible_text_widget, "isReadOnly")):
# Case when a text based widget has the focus.
not_readonly = not possible_text_widget.isReadOnly()
has_selection = possible_text_widget.has_selected_text()
else:
# Case when no text based widget has the focus.
return
# Copy, cut, paste, select all
self.copy_action.setEnabled(has_selection)
self.cut_action.setEnabled(has_selection and not_readonly)
self.paste_action.setEnabled(not_readonly)
self.selectall_action.setEnabled(True)

@ccordoba12
Copy link
Member

Not sure if an issue exists about that but maybe creating one could be worthy 👍🏼

Yeah, please do @dalthviz. We really need to fix that.

An initial idea that comes to mind to enable the menu actions to do something like that is to create a plugin that encapsulates the find/replace widget. I would say that as a minimum that plugin should be the one registering the relevant actions over the Search menu and be able to manage the logic necessary for the find/replace actions to trigger the relevant callback depending on the current focused widget (if the focused widget supports using/has a find/replace widget).

I haven't thought about that but sounds like a good idea. But I don't see clearly what the relationship between that plugin and the find/replace widget would be.

@dalthviz
Copy link
Member

dalthviz commented Dec 5, 2024

But I don't see clearly what the relationship between that plugin and the find/replace widget would be.

What I initial though was kind of moving that widget definition to be part of a FindReplace/Search plugin. To be more specific, move the widget definition from widgets/findreplace.py to plugins/findreplace/widgets.py or something like that (to kind of organize better where related logic will live even if we don't do anything to the find/replace widget itself)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment