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 in simple directory search to treeview. #1110

Merged
merged 2 commits into from
Sep 14, 2022

Conversation

adamharrison
Copy link
Member

Changed projectsearch to allow for searching only particular sub-directories (I tend to have large, multiple directory projects), and this massively cuts down on what I have to search.

Thoughts?

["project-search:find"] = function()
core.command_view:enter("Find Text In Project", {
["project-search:find"] = function(path)
core.command_view:enter("Find Text In " .. (path or "Project"), {
Copy link
Member

Choose a reason for hiding this comment

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

It might be better to show path relative to the current project directory.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right. I'll fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I changed this to use paths relative to whichever project directory is the parent project.

@@ -332,3 +332,5 @@ keymap.add {
["home"] = "project-search:move-to-start-of-doc",
["end"] = "project-search:move-to-end-of-doc"
}

return {}
Copy link
Member

Choose a reason for hiding this comment

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

Should we return the ResultsView here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally we'd have a table that contains resultsview, that represents the plugin as a whole, like the other plugins. I'll change it to do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, seems like most of the core plugins don't bother doing this; so I'll just return to that convention.

if file.type == "file" then
local path = (dir_name == core.project_dir and "" or (dir_name .. PATHSEP))
find_all_matches_in_file(self.results, path .. file.filename, fn)
if file.type == "file" and (not path or (dir_name .. "/" .. file.filename):find(path, 1, true) == 1) then
Copy link
Member

Choose a reason for hiding this comment

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

Would this work too?

Suggested change
if file.type == "file" and (not path or (dir_name .. "/" .. file.filename):find(path, 1, true) == 1) then
if file.type == "file" and (not path or (dir_name .. "/"):find(path, 1, true) == 1) then

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, no, checked this; dir_name is the project path, file.filename is the subsequent path. We'll need the whole thing to check.

Strange way of naming things, really, but I think it's outside scope to fundamentally change the naming convention.

@@ -819,6 +819,22 @@ command.add(function()
end
})

local projectsearch = core.try(require, "plugins.projectsearch")
Copy link
Member

Choose a reason for hiding this comment

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

IIRC core.try creates an error log entry on fail, so it might be better to use pcall directly here.
We should probably add an optional require function.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right a third time, I'll put it as pcall for now.

@adamharrison
Copy link
Member Author

OK, should be good.

@jgmdev
Copy link
Member

jgmdev commented Sep 14, 2022

Tested and so far is working nicely! merging....

@jgmdev jgmdev merged commit 10d810b into lite-xl:master Sep 14, 2022
takase1121 pushed a commit to takase1121/lite-xl that referenced this pull request Nov 14, 2022
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.

3 participants