Allow command predicates to manage parameters passed to the commands
When a command is performed with parameters, those are now passed to the predicate. The predicate can then return, after the validity boolean, any other value that will then be passed to the actual command. If the predicate only returns the validity boolean, the original parameters are passed through to the actual command. This allows predicates to manipulate the received parameters, and allows them to pass the result of an expensive computation to the actual command, which won't have to recalculate it. String and table predicates will now also return `core.active_view`.
This commit is contained in:
@@ -621,12 +621,13 @@ end
|
||||
-- Commands
|
||||
--
|
||||
local function predicate()
|
||||
return get_active_view() and #suggestions > 0
|
||||
local active_docview = get_active_view()
|
||||
return active_docview and #suggestions > 0, active_docview
|
||||
end
|
||||
|
||||
command.add(predicate, {
|
||||
["autocomplete:complete"] = function()
|
||||
local doc = core.active_view.doc
|
||||
["autocomplete:complete"] = function(dv)
|
||||
local doc = dv.doc
|
||||
local line, col = doc:get_selection()
|
||||
local item = suggestions[suggestions_idx]
|
||||
local text = item.text
|
||||
|
||||
Reference in New Issue
Block a user