-
-
Notifications
You must be signed in to change notification settings - Fork 828
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
feat(git): Add bcommits_range picker #2398
Merged
jamestrew
merged 12 commits into
nvim-telescope:master
from
aaronkollasch:visual-bcommit-filter
Jul 22, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4aa6a9a
Filter bcommits by selection in visual mode
aaronkollasch 343f3f3
Split bcommits_range into new picker
aaronkollasch 068254f
Add option to run bcommits_range as operator
aaronkollasch 5a15036
Rename range arguments to "first" and "last"
aaronkollasch e5f919e
Move operators functionality to new module
aaronkollasch b8a62e3
Run bcommits if no range given to bcommits_range
aaronkollasch ef2e484
Make bcommits_range default to current line
aaronkollasch 54347c2
Improve documentation of telescope.operators
aaronkollasch 9dc1af6
Add default value for last_operator
aaronkollasch 787098d
Update bcommits_range for detached worktrees
aaronkollasch 4591061
Rename range arguments to "from" and "to"
aaronkollasch 527caa1
Move shared bcommits picker into single function
aaronkollasch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
local operators = {} | ||
|
||
local last_operator = { callback = function(_) end, opts = {} } | ||
|
||
--- Execute the last saved operator callback and options | ||
operators.operator_callback = function() | ||
last_operator.callback(last_operator.opts) | ||
end | ||
|
||
--- Enters operator-pending mode, then executes callback. | ||
--- See `:h map-operator` | ||
--- | ||
---@param callback function: the function to call after exiting operator-pending | ||
---@param opts table: options to pass to the callback | ||
operators.run_operator = function(callback, opts) | ||
last_operator = { callback = callback, opts = opts } | ||
vim.o.operatorfunc = "v:lua.require'telescope.operators'.operator_callback" | ||
-- feed g@ to enter operator-pending mode | ||
-- 'i' required for which-key compatibility, etc. | ||
vim.api.nvim_feedkeys("g@", "mi", false) | ||
end | ||
|
||
return operators |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think after running this line we should clear the operator? Or perhaps on line 7? This way we drop the reference to the picker and it can be garbage collected later, which seems like a good idea.
Maybe it should be:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I tried something like that, but it breaks the key
g@
to re-run the last operator. Not sure if that's a big deal or not as I don't use that keymap, but I didn't see a huge reason to break it.How important is it to garbage collect the picker reference and opts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that makes sense.
It is kind of important, but it should be alright cause there is at most one outstanding, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it's only a reference to the most recent picker/callback function used with
operators.run_operator
. At least for this picker it would just keep a reference togit.bcommits_range
and its opts.