Improve seal filesearch plugin#301
Open
yannrouillard wants to merge 4 commits intoHammerspoon:masterfrom
Open
Conversation
Updated the Seal filesearch plugin to resolve a race condition which occurred when a new spotlight search was initiated before the completion of a previous search. This issue resulted in occasional receipt of obsolete `didFinish` spotlight events. To mitigate this, a unique `hs.spotlight` object is now assigned to each new search, and we disregard any event or callback that is not related to the current search. Additionally, the spotlight file search logic has been isolated into a distinct class for improved clarity.
Contrary to most plugins, the Seal filesearch plugin doesn't quickly filter results from an existing set in memory, but it triggers an actual spotlight search each time. That is more resource-intensive and calling it too frequently for each key typed does hurt the responsiveness of the Seal chooser (lua being single-threaded). To avoid that, the plugin now uses it own `queryChangedTimerDuration` parameter so it can be set to higher value compared to the defaut Seal one. The default of 100mn provides a good responsiveness while still display results with an acceptable delay.
Spotlight results naturally put first the items that were recently accessed. However it doesn't put first the item that really contain the word as it (not as a sub-part of the word) whereas it is often the ones you want first typically. We emulate that behaviour by re-ordering the results to boost the item that contains whole words.
e8a4c03 to
c01feb2
Compare
cmsj
requested changes
Aug 7, 2024
| obj.queryChangedTimerDuration = 0.1 | ||
|
|
||
| obj.spotlight = hs.spotlight.new() | ||
| --- |
Member
There was a problem hiding this comment.
Having --- here makes the docstrings parser think you're starting a new entry, but there is nothing specified. This line and line 41 need to be reduced to two dashes.
| end | ||
| if obj.showQueryResultsTimer ~= nil and obj.showQueryResultsTimer:running() then | ||
| obj.showQueryResultsTimer:stop() | ||
| --- |
| return string.find(s, pattern) | ||
| end | ||
|
|
||
| --- |
| self.callback(self.query, self.searchResults) | ||
| end | ||
|
|
||
| --- |
| obj.delayedFileSearchTimer:start() | ||
| end | ||
|
|
||
| --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains several improvements for the Seal filesearch plugin: