Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CommandView and autocomplete scroll behavior #1732

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Make autocomplete item scrolling more natural
  • Loading branch information
Guldoman committed Mar 1, 2024
commit 309ee0dd28b72e900734636b39c4591c05422186
23 changes: 20 additions & 3 deletions data/plugins/autocomplete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,14 @@ end)


local partial = ""
local suggestions_offset = 1
local suggestions_idx = 1
local suggestions = {}
local last_line, last_col


local function reset_suggestions()
suggestions_offset = 1
suggestions_idx = 1
suggestions = {}

Expand Down Expand Up @@ -369,6 +371,7 @@ local function update_suggestions()
end
end
suggestions_idx = 1
suggestions_offset = 1
end

local function get_partial_symbol()
Expand Down Expand Up @@ -565,8 +568,8 @@ local function draw_suggestions_box(av)
local font = av:get_font()
local lh = font:get_height() + style.padding.y
local y = ry + style.padding.y / 2
local show_count = #suggestions <= ah and #suggestions or ah
local start_index = suggestions_idx > ah and (suggestions_idx-(ah-1)) or 1
local show_count = math.min(#suggestions, ah)
local start_index = suggestions_offset
local hide_info = config.plugins.autocomplete.hide_info

for i=start_index, start_index+show_count-1, 1 do
Expand Down Expand Up @@ -819,7 +822,7 @@ command.add(predicate, {
local current_partial = get_partial_symbol()
local sz = #current_partial

for idx, line1, col1, line2, col2 in doc:get_selections(true) do
for _, line1, col1, line2, _ in doc:get_selections(true) do
local n = col1 - 1
local line = doc.lines[line1]
for i = 1, sz + 1 do
Expand All @@ -840,10 +843,24 @@ command.add(predicate, {

["autocomplete:previous"] = function()
suggestions_idx = (suggestions_idx - 2) % #suggestions + 1

local ah = math.min(config.plugins.autocomplete.max_height, #suggestions)
if suggestions_offset > suggestions_idx then
suggestions_offset = suggestions_idx
elseif suggestions_offset + ah < suggestions_idx + 1 then
suggestions_offset = suggestions_idx - ah + 1
end
end,

["autocomplete:next"] = function()
suggestions_idx = (suggestions_idx % #suggestions) + 1

local ah = math.min(config.plugins.autocomplete.max_height, #suggestions)
if suggestions_offset + ah < suggestions_idx + 1 then
suggestions_offset = suggestions_idx - ah + 1
elseif suggestions_offset > suggestions_idx then
suggestions_offset = suggestions_idx
end
end,

["autocomplete:cycle"] = function()
Expand Down
Loading