feat(Prompt): allow exit supression

Previously, we could set a `:h libmodal-exit-supression` flag in order
to stop the modes from automatically exiting upon an <Esc> press. This
commit adds this functionality to `Prompt`s so that the same may be done
for them.
This commit is contained in:
Iron-E 2020-12-19 18:26:17 -05:00
parent afe38ffc20
commit a389bc6d4e
No known key found for this signature in database
GPG Key ID: 19B71B7B7B021D22

View File

@ -6,6 +6,7 @@
local globals = require('libmodal/src/globals')
local utils = require('libmodal/src/utils')
local Vars = require('libmodal/src/Vars')
local vim = vim
local api = vim.api
@ -74,6 +75,11 @@ end
]]
---------------------------------
function _metaPrompt:_inputLoop()
-- If the mode is not handling exit events automatically and the global exit var is true.
if self.exit.supress and globals.is_true(self.exit:nvimGet()) then
return false
end
-- clear previous `echo`s.
utils.api.nvim_redraw()
@ -197,6 +203,7 @@ function Prompt.new(name, instruction, ...)
local self = setmetatable(
{
['exit'] = Vars.new('exit', name),
['indicator'] = require('libmodal/src/Indicator').prompt(name),
['input'] = require('libmodal/src/Vars').new('input', name),
['_instruction'] = instruction,
@ -206,7 +213,9 @@ function Prompt.new(name, instruction, ...)
)
-- get the arguments
local userCompletions = unpack({...})
local userCompletions, supressExit = unpack({...})
self.exit.supress = supressExit or false
-- get the completion list.
if type(instruction) == globals.TYPE_TBL then -- unload the keys of the mode command table.