sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

Project-relative file patterns (starting with `//`) don't work in 'Find in Files'

Open bakerkretzmar opened this issue 3 years ago • 4 comments

Description of the bug

File patterns beginning with // should be treated as relative to the project root. The docs say that this applies to the Find in Files panel too: docs.

If pattern begins with //, it will be compared as a relative path from the project root [4066]

However, searching a file pattern beginning with // produces an error, and a pattern beginning with -// is ignored or treated as a regular path.

This search should not error, and should find one instance of "foo"—inside subfolder/also-contains-foo.txt:

Screen Shot 2022-07-27 at 2 50 38 PM

This search should only find one instance of "foo"—inside contains-foo.txt (but not subfolder/also-contains-foo.txt):

Screen Shot 2022-07-27 at 2 50 48 PM

Steps to reproduce

  1. Start ST in safe mode.
  2. Create some subfolders and files.
  3. Search globally (CmdShiftF) for a string that is in several of the files.
  4. Add a file pattern to the "Where" input of the global search panel.
  5. Use a file pattern that starts with // or -// as documented.
  6. Observe that the pattern is ignored or errors.

Expected behavior

File patterns with // should be relative to the project root exactly as described here: https://www.sublimetext.com/docs/file_patterns.html#path-rules.

Actual behavior

See above.

Sublime Text build number

4134

Operating system & version

macOS 12.3.1

(Linux) Desktop environment and/or window manager

No response

Additional information

No response

OpenGL context information

No response

bakerkretzmar avatar Jul 27 '22 19:07 bakerkretzmar

I can confirm that happening on Windows 11 as well.

It appears ST converts // to \\ and handles it as network share path.

grafik

deathaxe avatar Jul 29 '22 15:07 deathaxe

Find-in-files doesn't support // because that's already the default behavior. If no explicit files/folders or similar are provided the search is performed relative to the project root. The way to do those searches are just subfolder/ and -subfolder/.

BenjaminSchaaf avatar Aug 12 '22 02:08 BenjaminSchaaf

Maybe I'm misunderstanding but I don't think that's true.

If you have a folder named B at the root of the project and also one nested somewhere in the project then how do you restrict the search to just the root B?

Screenshot 2022-08-12 at 09 01 55

rchl avatar Aug 12 '22 07:08 rchl

@BenjaminSchaaf by default the search is performed inside the project root, but not relative to it.

subfolder/ will match subfolder/, nested/subfolder/, nested/deep/subfolder/, etc. Likewise -subfolder/ will exclude all of those.

//subfolder/ would match/exclude subfolder/ only.

From the docs:

image

Could you please re-open this issue? Or am I still not understanding this correctly?

bakerkretzmar avatar Aug 12 '22 15:08 bakerkretzmar

Fixed in build 4135.

BenjaminSchaaf avatar Sep 15 '22 06:09 BenjaminSchaaf