Add show_suggestions to CommandView options

This commit is contained in:
Guldoman
2022-06-02 19:30:22 +02:00
parent 8ce1ecb897
commit 6c89a3e575
2 changed files with 15 additions and 9 deletions
+12 -6
View File
@@ -26,6 +26,7 @@ local default_state = {
suggest = noop,
cancel = noop,
validate = function() return true end,
show_suggestions = true,
typeahead = true,
wrap = true,
}
@@ -36,7 +37,6 @@ function CommandView:new()
self.suggestion_idx = 1
self.suggestions = {}
self.suggestions_height = 0
self.show_suggestions = true
self.last_change_id = 0
self.last_text = ""
self.gutter_width = 0
@@ -50,7 +50,8 @@ end
function CommandView:set_hidden_suggestions()
self.show_suggestions = false
core.warn("Using deprecated function CommandView:set_hidden_suggestions")
self.state.show_suggestions = false
end
@@ -101,7 +102,7 @@ function CommandView:move_suggestion_idx(dir)
end
end
if self.show_suggestions then
if self.state.show_suggestions then
local n = self.suggestion_idx + dir
self.suggestion_idx = overflow_suggestion_idx(n, #self.suggestions)
self:complete()
@@ -162,6 +163,12 @@ function CommandView:enter(text, ...)
}
end
-- Support deprecated CommandView:set_hidden_suggestions
-- Remove this when set_hidden_suggestions is not supported anymore
if options.show_suggestions == nil then
options.show_suggestions = self.state.show_suggestions
end
self.state = common.merge(default_state, options)
core.set_active_view(self)
@@ -180,7 +187,6 @@ function CommandView:exit(submitted, inexplicit)
self.doc:reset()
self.suggestions = {}
if not submitted then cancel(not inexplicit) end
self.show_suggestions = true
self.save_suggestion = nil
self.last_text = ""
end
@@ -246,7 +252,7 @@ function CommandView:update()
-- update suggestions box height
local lh = self:get_suggestion_line_height()
local dest = self.show_suggestions and math.min(#self.suggestions, max_suggestions) * lh or 0
local dest = self.state.show_suggestions and math.min(#self.suggestions, max_suggestions) * lh or 0
self:move_towards("suggestions_height", dest, nil, "commandview")
-- update suggestion cursor offset
@@ -316,7 +322,7 @@ end
function CommandView:draw()
CommandView.super.draw(self)
if self.show_suggestions then
if self.state.show_suggestions then
core.root_view:defer_draw(draw_suggestions_box, self)
end
end