Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Find in Files Improvements (Part 4: Sorting) #6585

Merged
merged 3 commits into from
Mar 4, 2014

Conversation

TomMalbran
Copy link
Contributor

The Find in Files Improvements are back with part 4.

With this PR the files in the Find in Files results are sorted before showing the results. It will always show first the selected file and the rest after sorted similar to how they are displayed in the project tree in Windows.

This fixes issue #4933.

@TomMalbran
Copy link
Contributor Author

@JeffryBooher Any updates here? I would like them to be merged for the next release so I can continue with the next one. This also fixes a bug where the results can change order while updating the files.

return 1;
} else if (index < folders1 && index >= folders2) {
return -1;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need that else.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, execution will never enter this branch

Copy link
Contributor

Choose a reason for hiding this comment

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

you can probably simplify this with return (index >= folders1 && index < folder2) ? 1 : -1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gets this branch when index >= folders1 && index >= folders2. What we can do is:

if (index < folders1 && index < folders2) {
    return entryName1.toLocaleLowerCase().localeCompare(entryName2.toLocaleLowerCase());
} else if (index >= folders1 && index >= folders2) {
    return FileUtils.compareFilenames(entryName1, entryName2);
}
return (index >= folders1 && index < folder2) ? 1 : -1;

@JeffryBooher
Copy link
Contributor

Apologies @TomMalbran this must have gotten lost in the shuffle. I'll review it and pull it in sometime this week.

@TomMalbran
Copy link
Contributor Author

Great. Thanks

@@ -236,7 +240,7 @@ define(function (require, exports, module) {
* @param {string} fullPath
* @param {string} contents
* @param {RegExp} queryExpr
* @return {boolean} True iff matches were added to the search results
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think the iff needed to be changed here. This is scientific notation for if-and-only-if

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see. We use the same notation in Spanish as sii but I never saw it English before, so I thought it was an error.

@JeffryBooher
Copy link
Contributor

@TomMalbran done with initial review. Just a few minor code cleanup items to work on before I test it.

@TomMalbran
Copy link
Contributor Author

@JeffryBooher Thanks for the review. Changed pushed.

@JeffryBooher
Copy link
Contributor

@TomMalbran why do the path headers no longer have the full path? It's relative to the project root now. If I compare Sprint 36 to this PR, FiF says "css.json - src/extensions/default/WebPlatformDocs/" vs. "extensions/default/WebPlatformDocs". I think it's ok but I didn't see a mandate or a note so I'm curious if it was accidental or did you intend for that to happen. I like that it saves space -- especially useful for bigger projects with a lot of subfolders but we should be careful that this was intentional and wasn't broken by accident.

@peterflynn
Copy link
Member

@JeffryBooher Afaik, the headers in the search results have always shown project-relative paths. That's how it works for me on Sprint 36 master currently. Do you have local changes on your machine?

Or might you have had a different project root open in the two cases you tested? (Neither path example above looks like a full, absolute path to me).

@redmunds
Copy link
Contributor

A case where full paths maybe used to be shown is when you have a file open that is outside your current project since Working Set files are also searched. I tested in master and I'm not seeing any path for that case -- seems like full path should be shown.

@JeffryBooher
Copy link
Contributor

@peterflynn the only thing i'm doing is switching between master and pr/6585. There may be some changes in master that are not in pr/6585, however. But the project is basically the brackets source tree. When I get results for master it says "src/..." but for pr/6585 the headers start with the folders below "src" so "thirdparty/jquery/..."

@TomMalbran you might want to merge master into this branch as I always need to rejigger the submodules afterwards but primarily so we can see what's different between your branch and master.

@TomMalbran
Copy link
Contributor Author

Sure will merge with master and check that. This PR is a bit old, but since it can still be merged I haven't merged it with master.

@TomMalbran
Copy link
Contributor Author

@JeffryBooher Just merged with master. There is no code in this PR that changes how the results are displayed, besides sorting the files.

@peterflynn
Copy link
Member

@JeffryBooher What folder is the root of your project when you're testing? src, or the parent folders of src, or something else? It's odd because the paths aren't absolute in either case, so it sounds like they're both being turned into relative paths, just relative to different things. And if not the project root, I dunno what the reference point would be...

The code that makes it relative is on line 372 -- the call to ProjectManager.makeProjectRelativeIfPossible() -- which is totally unchanged in this patch...

@JeffryBooher
Copy link
Contributor

hey @TomMalbran is there anyway that we can add a unit test for this to make sure the list is sorted?

@TomMalbran
Copy link
Contributor Author

@JeffryBooher We currently don't have any FindInFiles test, so not sure how to make them.

I still found a small bug. Since this places the currently selected file, the files order changes when this file the current file changes, which happens when you switch files and start editing which changes the results. Not sure if I should remove this, or save the current file at the start of the search and always use that one.

@JeffryBooher
Copy link
Contributor

got it. merging...

JeffryBooher added a commit that referenced this pull request Mar 4, 2014
Find in Files Improvements (Part 4: Sorting)
@JeffryBooher JeffryBooher merged commit 0270511 into master Mar 4, 2014
@TomMalbran TomMalbran deleted the tom/find-in-files-p4 branch March 4, 2014 00:12
@TomMalbran
Copy link
Contributor Author

@JeffryBooher Cool, but what about the bug I mentioned? It kind of makes the file you are editing the first file, even after switching files first, which doesn't work nice with the pagination. The original idea was to make the currently selected file on the initial search the first one, so that you can see the results from that file for issue #995. But maybe that is not how we should fix that issue. So not sure if I should keep how sorting works but saving the selected file on the initial search or remove that bit of code.

cc @larz0.

Will fix this in a new PR, once I know which way to go.

@larz0
Copy link
Member

larz0 commented Mar 4, 2014

We could sort them alphabetically or we could sort by file type first then alphabetically.

I think the second option is better because hen I start find-in-files when a JS file is opened I'd like to see JS files in the results first, ahead of the matches in say CSS.

@TomMalbran
Copy link
Contributor Author

The files are sorted in the same way as they are in the files tree, if you open it completely. The only difference is that the selected file goes first.

@larz0
Copy link
Member

larz0 commented Mar 4, 2014

Ahh ok cool.

@TomMalbran
Copy link
Contributor Author

@larz0 So, should the selected file on the initial search be first or not?

@larz0
Copy link
Member

larz0 commented Mar 4, 2014

Yes that makes sense.

@JeffryBooher
Copy link
Contributor

@TomMalbran sorry if I pulled the trigger too soon. I figured that we would follow up this issue in another PR anyway but it sounds like you have worked it out with @larz0

@TomMalbran
Copy link
Contributor Author

No problem. Will submit a PR soon to fix that issue. Testing it right now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants