From 2eab24032b3419f0eb6fda16265b552b6e599bbb Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 22 Feb 2020 13:36:08 +0000 Subject: [PATCH] Made up/down commands on projectsearch ResultView scroll view Fixes #14 --- data/plugins/projectsearch.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/data/plugins/projectsearch.lua b/data/plugins/projectsearch.lua index a529315..63b60dd 100644 --- a/data/plugins/projectsearch.lua +++ b/data/plugins/projectsearch.lua @@ -139,6 +139,14 @@ function ResultsView:each_visible_result() end +function ResultsView:scroll_to_make_selected_visible() + local h = self:get_line_height() + local y = self:get_results_yoffset() + h * (self.selected_idx - 1) + self.scroll.to.y = math.min(self.scroll.to.y, y) + self.scroll.to.y = math.max(self.scroll.to.y, y + h - self.size.y) +end + + function ResultsView:draw() self:draw_background(style.background) @@ -225,11 +233,13 @@ command.add(ResultsView, { ["project-search:select-previous"] = function() local view = core.active_view view.selected_idx = math.max(view.selected_idx - 1, 1) + view:scroll_to_make_selected_visible() end, ["project-search:select-next"] = function() local view = core.active_view view.selected_idx = math.min(view.selected_idx + 1, #view.results) + view:scroll_to_make_selected_visible() end, ["project-search:open-selected"] = function()