Made wrapping overflow optional
This commit is contained in:
parent
b3278f6360
commit
86e3f4a690
|
@ -145,7 +145,7 @@ command.add(nil, {
|
||||||
else
|
else
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end)
|
end, true)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:open-log"] = function()
|
["core:open-log"] = function()
|
||||||
|
|
|
@ -44,6 +44,7 @@ function CommandView:new()
|
||||||
self.font = "font"
|
self.font = "font"
|
||||||
self.size.y = 0
|
self.size.y = 0
|
||||||
self.label = ""
|
self.label = ""
|
||||||
|
self.wrap_on_overflow = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,11 +90,18 @@ function CommandView:set_text(text, select)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function CommandView:move_suggestion_idx(dir)
|
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
|
if self.show_suggestions then
|
||||||
local n = self.suggestion_idx + dir
|
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:complete()
|
||||||
self.last_change_id = self.doc:get_change_id()
|
self.last_change_id = self.doc:get_change_id()
|
||||||
else
|
else
|
||||||
|
@ -104,7 +112,7 @@ function CommandView:move_suggestion_idx(dir)
|
||||||
if n == 0 and self.save_suggestion then
|
if n == 0 and self.save_suggestion then
|
||||||
self:set_text(self.save_suggestion)
|
self:set_text(self.save_suggestion)
|
||||||
else
|
else
|
||||||
self.suggestion_idx = common.clamp(n, 1, #self.suggestions)
|
self.suggestion_idx = overflow_suggestion_idx(n, #self.suggestions)
|
||||||
self:complete()
|
self:complete()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -135,10 +143,11 @@ function CommandView:submit()
|
||||||
end
|
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
|
if self.state ~= default_state then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
self.wrap_on_overflow = wrap_on_overflow or false;
|
||||||
self.state = {
|
self.state = {
|
||||||
submit = submit or noop,
|
submit = submit or noop,
|
||||||
suggest = suggest or noop,
|
suggest = suggest or noop,
|
||||||
|
|
Loading…
Reference in New Issue