Add `show_suggestions` to `CommandView` options
This commit is contained in:
parent
8ce1ecb897
commit
6c89a3e575
|
@ -61,8 +61,8 @@ local function find(label, search_fn)
|
|||
core.command_view:set_text(text, true)
|
||||
core.status_view:show_tooltip(get_find_tooltip())
|
||||
|
||||
core.command_view:set_hidden_suggestions()
|
||||
core.command_view:enter(label, {
|
||||
show_suggestions = false,
|
||||
submit = function(text, item)
|
||||
insert_unique(core.previous_find, text)
|
||||
core.status_view:remove_tooltip()
|
||||
|
@ -94,15 +94,15 @@ local function replace(kind, default, fn)
|
|||
core.command_view:set_text(default, true)
|
||||
|
||||
core.status_view:show_tooltip(get_find_tooltip())
|
||||
core.command_view:set_hidden_suggestions()
|
||||
core.command_view:enter("Find To Replace " .. kind, {
|
||||
show_suggestions = false,
|
||||
submit = function(old)
|
||||
insert_unique(core.previous_find, old)
|
||||
core.command_view:set_text(old, true)
|
||||
|
||||
local s = string.format("Replace %s %q With", kind, old)
|
||||
core.command_view:set_hidden_suggestions()
|
||||
core.command_view:enter(s, {
|
||||
show_suggestions = false,
|
||||
submit = function(new)
|
||||
core.status_view:remove_tooltip()
|
||||
insert_unique(core.previous_replace, new)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue