Skip to content

Commit

Permalink
fix(scrolling): enhance and simplify scrolling
Browse files Browse the repository at this point in the history
The previous scrolling implementation (nvim-telescope#2687) moved the result selection
by one item at a time, which isn't technically scrolling (ie. moving the
view) and feels quite slow.

Let the neovim builtin scrolling do its thing, so using the scroll wheel
feels like scrolling and is functionally scrolling, too. Scrolling does
not move the selection so after scrolling it typically makes sense to
click. Moving the selection with keyboard takes you back to where you
were. This is in line with typical desktop user interfaces.
  • Loading branch information
dancek committed Apr 2, 2024
1 parent 1bb28df commit da66bf4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 90 deletions.
50 changes: 0 additions & 50 deletions lua/telescope/actions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1494,56 +1494,6 @@ end

actions.nop = function(_) end

actions.mouse_scroll_up = function(prompt_bufnr)
local picker = action_state.get_current_picker(prompt_bufnr)

local mouse_win = vim.fn.getmousepos().winid
if picker.results_win == mouse_win then
vim.schedule(function()
actions.move_selection_next(prompt_bufnr)
end)
return ""
else
return "<ScrollWheelDown>"
end
end

actions.mouse_scroll_down = function(prompt_bufnr)
local picker = action_state.get_current_picker(prompt_bufnr)

local mouse_win = vim.fn.getmousepos().winid
if mouse_win == picker.results_win then
vim.schedule(function()
actions.move_selection_previous(prompt_bufnr)
end)
return ""
else
return "<ScrollWheelUp>"
end
end

actions.mouse_scroll_right = function(prompt_bufnr)
local picker = action_state.get_current_picker(prompt_bufnr)

local mouse_win = vim.fn.getmousepos().winid
if mouse_win == picker.results_win then
return ""
else
return "<ScrollWheelLeft>"
end
end

actions.mouse_scroll_left = function(prompt_bufnr)
local picker = action_state.get_current_picker(prompt_bufnr)

local mouse_win = vim.fn.getmousepos().winid
if mouse_win == picker.results_win then
return ""
else
return "<ScrollWheelRight>"
end
end

actions.mouse_click = function(prompt_bufnr)
local picker = action_state.get_current_picker(prompt_bufnr)

Expand Down
40 changes: 0 additions & 40 deletions lua/telescope/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,6 @@ local mappings = {}
mappings.default_mappings = config.values.default_mappings
or {
i = {
["<ScrollWheelDown>"] = {
actions.mouse_scroll_up,
type = "action",
opts = { expr = true },
},
["<ScrollWheelUp>"] = {
actions.mouse_scroll_down,
type = "action",
opts = { expr = true },
},
["<ScrollWheelLeft>"] = {
actions.mouse_scroll_right,
type = "action",
opts = { expr = true },
},
["<ScrollWheelRight>"] = {
actions.mouse_scroll_left,
type = "action",
opts = { expr = true },
},
["<LeftMouse>"] = {
actions.mouse_click,
type = "action",
Expand Down Expand Up @@ -201,26 +181,6 @@ mappings.default_mappings = config.values.default_mappings
["<C-j>"] = actions.nop,
},
n = {
["<ScrollWheelDown>"] = {
actions.mouse_scroll_up,
type = "action",
opts = { expr = true },
},
["<ScrollWheelUp>"] = {
actions.mouse_scroll_down,
type = "action",
opts = { expr = true },
},
["<ScrollWheelLeft>"] = {
actions.mouse_scroll_right,
type = "action",
opts = { expr = true },
},
["<ScrollWheelRight>"] = {
actions.mouse_scroll_left,
type = "action",
opts = { expr = true },
},
["<LeftMouse>"] = {
actions.mouse_click,
type = "action",
Expand Down

0 comments on commit da66bf4

Please sign in to comment.