diff --git a/lua/neogit/lib/buffer.lua b/lua/neogit/lib/buffer.lua index 8bcea5d0e..076a26404 100644 --- a/lua/neogit/lib/buffer.lua +++ b/lua/neogit/lib/buffer.lua @@ -317,6 +317,7 @@ function Buffer:show() style = "minimal", focusable = true, border = "rounded", + zindex = 48, }) api.nvim_win_set_cursor(content_window, { 1, 0 }) @@ -349,6 +350,7 @@ function Buffer:show() row = vim.o.lines - 2, style = "minimal", border = { "─", "─", "─", "", "", "", "", "" }, + zindex = 49, -- title = (" %s Actions "):format(title), -- title_pos = "center", }) diff --git a/lua/neogit/lib/popup/builder.lua b/lua/neogit/lib/popup/builder.lua index b1e0ec56e..51ca4ea70 100644 --- a/lua/neogit/lib/popup/builder.lua +++ b/lua/neogit/lib/popup/builder.lua @@ -54,6 +54,8 @@ local M = {} ---@field type string ---@field user_input boolean ---@field value string? +---@field validate fun(string): boolean +---@field validate_help string|nil ---@class PopupConfig ---@field id string @@ -90,6 +92,8 @@ local M = {} ---@field value? string Allows for pre-building cli flags that can be customized by user input ---@field user_input? boolean If true, allows user to customize the value of the cli flag ---@field dependent? string[] other switches/options with a state dependency on this one +---@field validate? fun(string): boolean +---@field validate_help? string ---@class PopupOptionOpts ---@field key_prefix? string Allows overwriting the default '=' to set option @@ -252,6 +256,10 @@ function M:switch(key, cli, description, opts) internal = opts.internal, cli_prefix = opts.cli_prefix, user_input = opts.user_input, + validate = opts.validate or function() + return true + end, + validate_help = opts.validate_help, cli_suffix = opts.cli_suffix, options = opts.options, incompatible = util.build_reverse_lookup(opts.incompatible), diff --git a/lua/neogit/lib/popup/init.lua b/lua/neogit/lib/popup/init.lua index 3d95c5820..c582ca297 100644 --- a/lua/neogit/lib/popup/init.lua +++ b/lua/neogit/lib/popup/init.lua @@ -119,8 +119,17 @@ function M:toggle_switch(switch) if switch.user_input then if switch.enabled then local value = input.get_user_input(switch.cli_prefix .. switch.cli_base, { separator = "" }) - if value then - switch.cli = switch.cli_base .. value + if value and value ~= "" then + if switch.validate(value) then + switch.cli = switch.cli_base .. value + else + switch.enabled = false + switch.cli = switch.cli_base + notification.warn(switch.validate_help) + end + else + switch.enabled = false + switch.cli = switch.cli_base end else switch.cli = switch.cli_base diff --git a/lua/neogit/popups/log/init.lua b/lua/neogit/popups/log/init.lua index 700cb2495..3c4bc95bd 100644 --- a/lua/neogit/popups/log/init.lua +++ b/lua/neogit/popups/log/init.lua @@ -19,7 +19,14 @@ function M.create() :option("F", "grep", "", "Search messages", { key_prefix = "-" }) :switch("G", "G", "Search changes", { user_input = true, cli_prefix = "-" }) :switch("S", "S", "Search occurrences", { user_input = true, cli_prefix = "-" }) - :switch("L", "L", "Trace line evolution", { user_input = true, cli_prefix = "-" }) + :switch("L", "L", "Trace line evolution", { + user_input = true, + cli_prefix = "-", + validate_help = "Input must match `start,end:file` or `:funcname:file`", + validate = function(input) + return (input:match("^%d+,%d+:.-$") ~= nil) or (input:match("^:.-:.-$") ~= nil) + end, + }) :option("s", "since", "", "Limit to commits since", { key_prefix = "-" }) :option("u", "until", "", "Limit to commits until", { key_prefix = "-" }) :switch("m", "no-merges", "Omit merges", { key_prefix = "=" }) @@ -89,8 +96,6 @@ function M.create() :action("r", "current", actions.reflog_current) :action("H", "HEAD", actions.reflog_head) :action("O", "other", actions.reflog_other) - :new_action_group("Other") - :action("s", "shortlog") :build() p:show()