Skip to content

Commit

Permalink
fix: silence errors from moving cursor (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Sep 29, 2023
1 parent d7577c6 commit 551a2b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 19 additions & 7 deletions lua/aerial/navigation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ local window = require("aerial.window")

local M = {}

---@param winid integer
---@return nil|aerial.CursorPosition
local function _get_current_lnum(winid)
---@type nil|integer
local bufnr = vim.api.nvim_get_current_buf()
Expand All @@ -26,6 +28,7 @@ local function _get_current_lnum(winid)
end
end

---@return integer?
local function get_target_win()
local bufnr, _ = util.get_buffers()
local winid
Expand All @@ -52,6 +55,8 @@ local function get_target_win()
return winid
end

---@param direction? integer -1 for backwards or 1 for forwards
---@param count? integer
M.up = function(direction, count)
direction = direction or -1
count = count or 1
Expand Down Expand Up @@ -131,11 +136,13 @@ M.up = function(direction, count)
end
end

---@param step? integer
M.prev = function(step)
step = step or 1
M.next(-1 * step)
end

---@param step? integer
M.next = function(step)
step = step or 1
local winid = get_target_win()
Expand Down Expand Up @@ -168,18 +175,20 @@ M.next = function(step)
end
end

---@param opts? {index?: integer, jump?: boolean, split?: string, quiet?: boolean, winid?: integer}
M.select = function(opts)
opts = vim.tbl_extend("keep", opts or {}, {
index = nil,
split = nil,
jump = true,
quiet = false,
})
local winid = opts.winid
if not winid then
winid = get_target_win()
end
if not winid then
error("Could not find destination window")
if not opts.quiet then
error("Could not find destination window")
end
return
end
if opts.index == nil then
Expand All @@ -199,21 +208,24 @@ M.select = function(opts)
end
local bufnr, _ = util.get_buffers()
if not bufnr then
error("Could not find source buffer")
if not opts.quiet then
error("Could not find source buffer")
end
return
end
M.select_symbol(item, winid, bufnr, opts)
end

---@param item aerial.Symbol
---@param winid integer
---@param bufnr integer
---@param opts table
---@param opts {jump: boolean, split: nil|string}
M.select_symbol = function(item, winid, bufnr, opts)
if opts.jump and config.close_on_select then
window.close()
end
if opts.split then
local split = opts.split
local split = opts.split
if split then
if split == "vertical" or split == "v" then
split = "belowright vsplit"
elseif split == "horizontal" or split == "h" or split == "s" then
Expand Down
2 changes: 1 addition & 1 deletion lua/aerial/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ local function create_aerial_buffer(bufnr)
render.update_highlights(bufnr)
end
if config.autojump then
require("aerial.navigation").select({ jump = false })
require("aerial.navigation").select({ jump = false, quiet = true })
end
end,
})
Expand Down

0 comments on commit 551a2b6

Please sign in to comment.