Merge pull request #1003 from zesterer/master

Added suggestion wrapping for CommandView
This commit is contained in:
Jefferson González 2022-05-30 12:53:06 -04:00 committed by GitHub
commit f1f61f034b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 6 deletions

View File

@ -145,7 +145,7 @@ command.add(nil, {
else
return true
end
end)
end, true)
end,
["core:open-log"] = function()

View File

@ -44,6 +44,7 @@ function CommandView:new()
self.font = "font"
self.size.y = 0
self.label = ""
self.wrap_on_overflow = false
end
@ -89,11 +90,18 @@ function CommandView:set_text(text, select)
end
end
function CommandView:move_suggestion_idx(dir)
local function overflow_suggestion_idx(n, count)
if self.wrap_on_overflow then
return (n - 1) % count + 1
else
return common.clamp(n, 1, count)
end
end
if self.show_suggestions then
local n = self.suggestion_idx + dir
self.suggestion_idx = common.clamp(n, 1, #self.suggestions)
self.suggestion_idx = overflow_suggestion_idx(n, #self.suggestions)
self:complete()
self.last_change_id = self.doc:get_change_id()
else
@ -104,7 +112,7 @@ function CommandView:move_suggestion_idx(dir)
if n == 0 and self.save_suggestion then
self:set_text(self.save_suggestion)
else
self.suggestion_idx = common.clamp(n, 1, #self.suggestions)
self.suggestion_idx = overflow_suggestion_idx(n, #self.suggestions)
self:complete()
end
else
@ -135,10 +143,11 @@ function CommandView:submit()
end
function CommandView:enter(text, submit, suggest, cancel, validate)
function CommandView:enter(text, submit, suggest, cancel, validate, wrap_on_overflow)
if self.state ~= default_state then
return
end
self.wrap_on_overflow = wrap_on_overflow or false;
self.state = {
submit = submit or noop,
suggest = suggest or noop,

View File

@ -13,7 +13,7 @@ function DocView:draw_overlay(...)
local y = self.position.y
local w = math.ceil(SCALE * 1)
local h = self.size.y
local color = style.guide or style.selection
renderer.draw_rect(x, y, w, h, color)
end