Skip to content

Commit 0583348

Browse files
committed
tweak behaviour of options - when they are set, the trigger key will
first unset them, before letting you set them again.
1 parent 7fe60f9 commit 0583348

File tree

1 file changed

+11
-27
lines changed

1 file changed

+11
-27
lines changed

lua/neogit/lib/popup/init.lua

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -180,42 +180,26 @@ end
180180
---@param value? string
181181
---@return nil
182182
function M:set_option(option, value)
183-
-- Prompt user to select from predetermined choices
184-
if value then
183+
if option.value and option.value ~= "" then -- Toggle option off when it's currently set
184+
option.value = ""
185+
elseif value then
185186
option.value = value
186187
elseif option.choices then
187-
if not option.value or option.value == "" then
188-
local eventignore = vim.o.eventignore
189-
vim.o.eventignore = "WinLeave"
190-
local choice = FuzzyFinderBuffer.new(option.choices):open_async {
191-
prompt_prefix = option.description,
192-
}
193-
vim.o.eventignore = eventignore
194-
195-
if choice then
196-
option.value = choice
197-
else
198-
option.value = ""
199-
end
200-
else
201-
option.value = ""
202-
end
188+
local eventignore = vim.o.eventignore
189+
vim.o.eventignore = "WinLeave"
190+
option.value = FuzzyFinderBuffer.new(option.choices):open_async {
191+
prompt_prefix = option.description,
192+
refocus_status = false,
193+
}
194+
vim.o.eventignore = eventignore
203195
elseif option.fn then
204196
option.value = option.fn(self, option)
205197
else
206-
local input = input.get_user_input(option.cli, {
198+
option.value = input.get_user_input(option.cli, {
207199
separator = "=",
208200
default = option.value,
209201
cancel = option.value,
210202
})
211-
212-
-- If the option specifies a default value, and the user set the value to be empty, defer to default value.
213-
-- This is handy to prevent the user from accidentally loading thousands of log entries by accident.
214-
if option.default and input == "" then
215-
option.value = tostring(option.default)
216-
else
217-
option.value = input
218-
end
219203
end
220204

221205
state.set({ self.state.name, option.cli }, option.value)

0 commit comments

Comments
 (0)