diff --git a/doc/telescope.txt b/doc/telescope.txt index b0b6248c35..58fcfe2837 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1040,9 +1040,11 @@ builtin.git_bcommits_range({opts}) *telescope.builtin.git_bcommits_range()* {git_command} (table) command that will be executed. {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} {start} (number) the first line in the range - (optional in visual mode) + (optional in visual or operator mode) {stop} (number) the last line in the range - (optional in visual mode) + (optional in visual or operator mode) + {operator} (boolean) select lines in operator-pending mode + (default: false) builtin.git_branches({opts}) *telescope.builtin.git_branches()* List branches for current directory, with output from `git log --oneline` diff --git a/lua/telescope/builtin/__git.lua b/lua/telescope/builtin/__git.lua index da160cf21a..c31b9802e3 100644 --- a/lua/telescope/builtin/__git.lua +++ b/lua/telescope/builtin/__git.lua @@ -194,6 +194,14 @@ git.bcommits = function(opts) :find() end +local last_bcommits_range_opts = {} + +local bcommits_range_callback = function() + last_bcommits_range_opts.operator = false + last_bcommits_range_opts.operator_callback = true + git.bcommits_range(last_bcommits_range_opts) +end + git.bcommits_range = function(opts) opts.current_line = (opts.current_file == nil) and get_current_buf_line(opts.winnr) or nil opts.current_file = vim.F.if_nil(opts.current_file, vim.api.nvim_buf_get_name(opts.bufnr)) @@ -207,6 +215,14 @@ git.bcommits_range = function(opts) if visual then line_number_start = vim.F.if_nil(line_number_start, vim.fn.line "v") line_number_stop = vim.F.if_nil(line_number_stop, vim.fn.line ".") + elseif opts.operator then + last_bcommits_range_opts = opts + vim.o.operatorfunc = "v:lua.require'telescope.builtin.__git'.bcommits_range_callback" + vim.api.nvim_feedkeys("g@", "n", false) + return + elseif opts.operator_callback then + line_number_start = vim.fn.line "'[" + line_number_stop = vim.fn.line "']" end local line_range = string.format("%d,%d:%s", line_number_start, line_number_stop, Path:new(opts.current_file):make_relative(opts.cwd)) @@ -512,4 +528,4 @@ local function apply_checks(mod) return mod end -return apply_checks(git) +return vim.tbl_extend("keep", apply_checks(git), { bcommits_range_callback = bcommits_range_callback }) diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 9867261754..3552aebbfe 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -175,6 +175,7 @@ builtin.git_bcommits = require_on_exported_call("telescope.builtin.__git").bcomm ---@field git_command table: command that will be executed. {"git","log","--pretty=oneline","--abbrev-commit","--no-patch","-L"} ---@field start number: the first line in the range (optional in visual or operator mode) ---@field stop number: the last line in the range (optional in visual or operator mode) +---@field operator boolean: select lines in operator-pending mode (default: false) builtin.git_bcommits_range = require_on_exported_call("telescope.builtin.__git").bcommits_range --- List branches for current directory, with output from `git log --oneline` shown in the preview window