Sublime Forum

Project Filters in Find in Folder?

#1

When I search using Find in Folder the “where” input field contains:

/Users/xxxx/Sites/xxxx/editors/xxx_5.9.2,<project filters>

If I search for a word I know is in the files in that folder I get zero results. If I manually remove the <project filters> portion of that line then Sublime Text finds the word in the appropriate files in the folder.

What is the purpose of <project filters> and why is it making the search results not work? Can I stop Sublime Text from including <project filters> in the where line by default?

0 Likes

#2

A search path like /Users/something/SomePlace will search all files and folders in that path, while adding <project_filters> makes the filters on the open folder like file_exclude_patterns and the like take effect and exclude those files from being part of the search.

For example if your project was a NodeJS project wherein you did folder_exclude_patterns that blocks node_modules from appearing in the side bar, using the bare path would search everything whereas using the project filters would not.

That said, how are you opening the Find in Files dialog? It doesn’t add that filter for me by default when I do it here as far as I’ve been able to see. Does it also happen in Safe Mode?

This sounds like something that a package like SideBarEnhancements, FileManager or the like might be adding on your behalf.

0 Likes

#3

Thank you for those details. On a Mac I am simply dragging a folder from Finder into the left side bar of Sublime Text. When I do that the top level directory / folder appears and I right click on the top level folder and select Find in Folder.

When I do this the <project filters> is always there and I end up manually deleting it to get the search to work.

0 Likes

#4

I forgot to also mention that in Safe Mode the same behavior is exhibited.

0 Likes

#5

That is the expected behavior. The command behind that sidebar option is find_in_folder whose source is located in Default/side_bar.py.

The relevant piece from that plugin is

class FindInFolderCommand(sublime_plugin.WindowCommand):
    def run(self, dirs):
        self.window.run_command(
            "show_panel",
            {
                "panel": "find_in_files",
                "where": ",".join(dirs + ["<project filters>"])
            }
        )

    def is_visible(self, dirs):
        return len(dirs) > 0

Line 7 from the above code is where the <project filters> is coming from.

0 Likes

#6

How would I go about overriding that behavior to not include the project filters? Can I modify that .py file? I cannot find that file on my machine? I am pretty new to ST so I apologize for the lack of expertise here.

0 Likes

#7

Here’s the steps you follow

  1. The first step is to just see the file. Go to View Package File from the command palette & search for Default/side_bar.py. The above snippet comes from this file (It’ll be towards the end).

  2. Copy the entire contents of that file.

  3. Now navigate to your Packages directory (Preferences -> Browse Packages from the main menu). Here create a folder called Default/side_bar.py

  4. Paste contents copied in step (2) into the new file you create in step (4).

  5. Change "where": ",".join(dirs + ["<project filters>"]) to "where": ",".join(dirs). Save. You should be good to go.

One of the reasons why creating overrides like above is a bit dangerous because your ST will happily upgrade & you’d be stuck on outdated files (because it will continue to use the above while Default/side_bar.py might theoretically receive updates).

One way to mitigate this are using packages like OverrideAudit, which helps you keep track of overrides and manage them. So, for example if Default/side_bar.py ever received updates, OverrideAudit will warn you about them. It also makes it easy to generate overrides (You could have done the above 5 steps in 1 or 2 steps with OverrideAudit), but it’s good to know how to manually create overrides as well.

2 Likes

#8

Perfect! Thank you for your assistance!

0 Likes