Implement hidden suggestions for find dialog

This commit is contained in:
Francesco Abbate 2021-09-07 17:06:19 +02:00 committed by Francesco
parent dfb64fbdf1
commit f85fe102d9
3 changed files with 24 additions and 5 deletions

View File

@ -49,7 +49,9 @@ local function find(label, search_fn)
core.command_view:set_text(text, true) core.command_view:set_text(text, true)
core.status_view:show_tooltip(get_find_tooltip()) core.status_view:show_tooltip(get_find_tooltip())
core.command_view:enter(label, function(text) core.command_view:set_hidden_suggestions()
core.command_view:enter(label, function(text, item)
table.insert(core.previous_find, text)
core.status_view:remove_tooltip() core.status_view:remove_tooltip()
if found then if found then
last_fn, last_text = search_fn, text last_fn, last_text = search_fn, text
@ -61,6 +63,7 @@ local function find(label, search_fn)
end, function(text) end, function(text)
found = update_preview(last_sel, search_fn, text) found = update_preview(last_sel, search_fn, text)
last_fn, last_text = search_fn, text last_fn, last_text = search_fn, text
return core.previous_find
end, function(explicit) end, function(explicit)
core.status_view:remove_tooltip() core.status_view:remove_tooltip()
if explicit then if explicit then

View File

@ -34,6 +34,7 @@ function CommandView:new()
self.suggestion_idx = 1 self.suggestion_idx = 1
self.suggestions = {} self.suggestions = {}
self.suggestions_height = 0 self.suggestions_height = 0
self.show_suggestions = true
self.last_change_id = 0 self.last_change_id = 0
self.gutter_width = 0 self.gutter_width = 0
self.gutter_text_brightness = 0 self.gutter_text_brightness = 0
@ -45,6 +46,11 @@ function CommandView:new()
end end
function CommandView:set_hidden_suggestions()
self.show_suggestions = false
end
function CommandView:get_name() function CommandView:get_name()
return View.get_name(self) return View.get_name(self)
end end
@ -83,10 +89,16 @@ end
function CommandView:move_suggestion_idx(dir) function CommandView:move_suggestion_idx(dir)
local n = self.suggestion_idx + dir local current_suggestion = self.suggestions[self.suggestion_idx].text
self.suggestion_idx = common.clamp(n, 1, #self.suggestions) if self.show_suggestions or self:get_text() == current_suggestion then
local n = self.suggestion_idx + dir
self.suggestion_idx = common.clamp(n, 1, #self.suggestions)
end
self:complete() self:complete()
self.last_change_id = self.doc:get_change_id() self.last_change_id = self.doc:get_change_id()
if not self.show_suggestions then
self.state.suggest(self:get_text())
end
end end
@ -134,6 +146,7 @@ function CommandView:exit(submitted, inexplicit)
self.doc:reset() self.doc:reset()
self.suggestions = {} self.suggestions = {}
if not submitted then cancel(not inexplicit) end if not submitted then cancel(not inexplicit) end
self.show_suggestions = true
end end
@ -187,7 +200,7 @@ function CommandView:update()
-- update suggestions box height -- update suggestions box height
local lh = self:get_suggestion_line_height() local lh = self:get_suggestion_line_height()
local dest = math.min(#self.suggestions, max_suggestions) * lh local dest = self.show_suggestions and math.min(#self.suggestions, max_suggestions) * lh or 0
self:move_towards("suggestions_height", dest) self:move_towards("suggestions_height", dest)
-- update suggestion cursor offset -- update suggestion cursor offset
@ -256,7 +269,9 @@ end
function CommandView:draw() function CommandView:draw()
CommandView.super.draw(self) CommandView.super.draw(self)
core.root_view:defer_draw(draw_suggestions_box, self) if self.show_suggestions then
core.root_view:defer_draw(draw_suggestions_box, self)
end
end end

View File

@ -496,6 +496,7 @@ function core.init()
core.redraw = true core.redraw = true
core.visited_files = {} core.visited_files = {}
core.previous_find = {}
core.restart_request = false core.restart_request = false
core.quit_request = false core.quit_request = false
core.replacements = whitespace_replacements() core.replacements = whitespace_replacements()