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

Added find & replace in files #16571

Merged
merged 1 commit into from Apr 8, 2018
Merged

Conversation

Zylann
Copy link
Contributor

@Zylann Zylann commented Feb 12, 2018

This PR adds a way to globally search text files in the project, and replace all occurences of a given text. It's very useful for navigating script name occurences or refactoring.

Should fix #16336.
Partially fixes #6217 (quite ambitious though)
Related to #2592 but doesn't fix its specific case.

When editing a text-based script, use Ctrl+Shift+F to open it (or use the menu), which is pretty standard for this action.
(I had to change the default shortcut for "goto function" to Ctrl+Alt+F).

A window will open:

image

If you had selected text, it will be copied in the search field.
In addition, the search field will be given focus. If you press enter just after that, it will trigger the search (so you can do it without touching the mouse).
If you press Replace..., the search will happen the same way, but you will be given the ability to enter which text to use for replacement.

Search results are shown in the bottom dock, which opens automatically when a search begins.
If the search takes long, a progress bar can be seen, but you can still interact with the editor during the search.

image

Clicking a result will jump to the file and select the occurence (this should not conflict with the local file search).

Using Replace all will work on the files directly, and cannot be undone at the moment. Files that are open already will be reloaded using the same logic as external modifications do.

Scripts embedded in scenes and resources are problematic for this tool because unless tscn and tres files get included in the filter, it would require to preemptively load every single scene and resource of the project in case it has builtin scripts (which would slow down and complexify the logic due to varying data formats).

This implementation is almost completely separate from the existing Search & Replace, because it works quite differently and on a larger scope.
Some features are not yet supported (such as looking only for opened files, using a thread, highlighting occurrences in the results...) but can be added later.

Known bug:
Sometimes, the top of the results panel cannot be resized, I have no idea why.

@volzhs volzhs added this to the 3.1 milestone Feb 12, 2018
@godotengine godotengine deleted a comment Feb 12, 2018
@@ -0,0 +1,799 @@
#include "find_in_files.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add the Godot copyright header?

@@ -0,0 +1,154 @@
#ifndef FIND_IN_FILES_H
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@Zylann
Copy link
Contributor Author

Zylann commented Feb 20, 2018

Added copyright header

@JarLowrey
Copy link

Is this in 3.0.2? When I hit Ctrl+Shift+F this is the window that appears

capture

@Zylann
Copy link
Contributor Author

Zylann commented Mar 27, 2018

It's not in 3.0.2 yet, this is a PR which adds it for an upcoming version.

@reduz reduz merged commit 3a08f17 into godotengine:master Apr 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Find in Files/Replace in Files Add global search/replace to editor
5 participants