feat(git): Add bcommits_range picker (#2398)

* Filter bcommits by selection in visual mode

* Split bcommits_range into new picker

* Add option to run bcommits_range as operator

Starts operator-pending mode and shows commits in the range of lines
covered by the next text object or motion

* Rename range arguments to "first" and "last"

Can't use start/end, since end is an annoying keyword to use in lua
and start/stop doesn't fit as well

* Move operators functionality to new module

* Run bcommits if no range given to bcommits_range

* Make bcommits_range default to current line

Instead of calling bcommits

* Improve documentation of telescope.operators

* Add default value for last_operator

Default to a no-op callback

* Update bcommits_range for detached worktrees

See #2597

* Rename range arguments to "from" and "to"

* Move shared bcommits picker into single function
This commit is contained in:
Aaron Kollasch
2023-07-22 17:35:52 -04:00
committed by GitHub
parent f78d956901
commit e7e6492a2d
5 changed files with 189 additions and 71 deletions

View File

@@ -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