We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5f38409 commit 67c1923Copy full SHA for 67c1923
lua/neogit/lib/popup/builder.lua
@@ -54,6 +54,8 @@ local M = {}
54
---@field type string
55
---@field user_input boolean
56
---@field value string?
57
+---@field validate fun(string): boolean
58
+---@field validate_help string|nil
59
60
---@class PopupConfig
61
---@field id string
@@ -252,6 +254,10 @@ function M:switch(key, cli, description, opts)
252
254
internal = opts.internal,
253
255
cli_prefix = opts.cli_prefix,
256
user_input = opts.user_input,
257
+ validate = opts.validate or function()
258
+ return true
259
+ end,
260
+ validate_help = opts.validate_help,
261
cli_suffix = opts.cli_suffix,
262
options = opts.options,
263
incompatible = util.build_reverse_lookup(opts.incompatible),
lua/neogit/lib/popup/init.lua
@@ -119,8 +119,17 @@ function M:toggle_switch(switch)
119
if switch.user_input then
120
if switch.enabled then
121
local value = input.get_user_input(switch.cli_prefix .. switch.cli_base, { separator = "" })
122
- if value then
123
- switch.cli = switch.cli_base .. value
+ if value and value ~= "" then
+ if switch.validate(value) then
124
+ switch.cli = switch.cli_base .. value
125
+ else
126
+ switch.enabled = false
127
+ switch.cli = switch.cli_base
128
+ notification.warn(switch.validate_help)
129
+ end
130
131
132
133
end
134
else
135
switch.cli = switch.cli_base
lua/neogit/popups/log/init.lua
@@ -19,7 +19,14 @@ function M.create()
19
:option("F", "grep", "", "Search messages", { key_prefix = "-" })
20
:switch("G", "G", "Search changes", { user_input = true, cli_prefix = "-" })
21
:switch("S", "S", "Search occurrences", { user_input = true, cli_prefix = "-" })
22
- :switch("L", "L", "Trace line evolution", { user_input = true, cli_prefix = "-" })
+ :switch("L", "L", "Trace line evolution", {
23
+ user_input = true,
24
+ cli_prefix = "-",
25
+ validate_help = "Input must match 'start,end:file' or ':funcname:file'",
26
+ validate = function(input)
27
+ return (input:match("^%d+,%d+:.-$") ~= nil) or (input:match("^:.-:.-$") ~= nil)
28
29
+ })
30
:option("s", "since", "", "Limit to commits since", { key_prefix = "-" })
31
:option("u", "until", "", "Limit to commits until", { key_prefix = "-" })
32
:switch("m", "no-merges", "Omit merges", { key_prefix = "=" })
0 commit comments