ref: Annotations
This commit is contained in:
@@ -3,6 +3,8 @@ local mark = {}
|
|||||||
local api = vim.api
|
local api = vim.api
|
||||||
local ns = api.nvim_create_namespace("neogen")
|
local ns = api.nvim_create_namespace("neogen")
|
||||||
|
|
||||||
|
--- Start marks creation and get useful informations
|
||||||
|
---@private
|
||||||
mark.start = function(self)
|
mark.start = function(self)
|
||||||
if self.started then
|
if self.started then
|
||||||
mark:stop()
|
mark:stop()
|
||||||
@@ -17,11 +19,18 @@ mark.start = function(self)
|
|||||||
self.started = true
|
self.started = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Get a mark specified with i index
|
||||||
|
---@param i number
|
||||||
|
---@private
|
||||||
mark.get_mark = function(self, i)
|
mark.get_mark = function(self, i)
|
||||||
local id = self.ids[i]
|
local id = self.ids[i]
|
||||||
return api.nvim_buf_get_extmark_by_id(self.bufnr, ns, id, {})
|
return api.nvim_buf_get_extmark_by_id(self.bufnr, ns, id, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Add a mark with position
|
||||||
|
---@param pos table Position as line, col
|
||||||
|
---@return number the id of the inserted mark
|
||||||
|
---@private
|
||||||
mark.add_mark = function(self, pos)
|
mark.add_mark = function(self, pos)
|
||||||
local line, col = unpack(pos)
|
local line, col = unpack(pos)
|
||||||
local id = api.nvim_buf_set_extmark(self.bufnr, ns, line, col, {})
|
local id = api.nvim_buf_set_extmark(self.bufnr, ns, line, col, {})
|
||||||
@@ -29,10 +38,17 @@ mark.add_mark = function(self, pos)
|
|||||||
return id
|
return id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Get how many marks are created
|
||||||
|
---@return number
|
||||||
|
---@private
|
||||||
mark.mark_len = function(self)
|
mark.mark_len = function(self)
|
||||||
return #self.ids
|
return #self.ids
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Verify if the marks can be jumpable
|
||||||
|
---@param reverse boolean
|
||||||
|
---@return boolean
|
||||||
|
---@private
|
||||||
mark.jumpable = function(self, reverse)
|
mark.jumpable = function(self, reverse)
|
||||||
if not self.started then
|
if not self.started then
|
||||||
return false
|
return false
|
||||||
@@ -49,12 +65,15 @@ mark.jumpable = function(self, reverse)
|
|||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Jump to next/previous mark if possible
|
||||||
|
---@param reverse boolean
|
||||||
|
---@private
|
||||||
mark.jump = function(self, reverse)
|
mark.jump = function(self, reverse)
|
||||||
if mark:jumpable(reverse) then
|
if mark:jumpable(reverse) then
|
||||||
self.index = reverse and self.index - 1 or self.index + 1
|
self.index = reverse and self.index - 1 or self.index + 1
|
||||||
if self.index > 0 and self.index <= #self.ids then
|
if self.index > 0 and self.index <= #self.ids then
|
||||||
local line, row = unpack(self:get_mark(self.index))
|
local line, row = unpack(self:get_mark(self.index))
|
||||||
api.nvim_win_set_cursor(self.winid, {line + 1, row})
|
api.nvim_win_set_cursor(self.winid, { line + 1, row })
|
||||||
else
|
else
|
||||||
self:stop(true)
|
self:stop(true)
|
||||||
end
|
end
|
||||||
@@ -63,6 +82,8 @@ mark.jump = function(self, reverse)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Clear marks and stop jumping ability
|
||||||
|
---@private
|
||||||
mark.stop = function(self, should_jump)
|
mark.stop = function(self, should_jump)
|
||||||
local bufnr = self.bufnr
|
local bufnr = self.bufnr
|
||||||
if bufnr and bufnr > 0 and api.nvim_buf_is_valid(bufnr) then
|
if bufnr and bufnr > 0 and api.nvim_buf_is_valid(bufnr) then
|
||||||
@@ -74,7 +95,7 @@ mark.stop = function(self, should_jump)
|
|||||||
if should_jump and winid and winid > 0 and api.nvim_win_is_valid(winid) then
|
if should_jump and winid and winid > 0 and api.nvim_win_is_valid(winid) then
|
||||||
local pos = api.nvim_buf_get_extmark_by_id(self.bufnr, ns, self.last_jump, {})
|
local pos = api.nvim_buf_get_extmark_by_id(self.bufnr, ns, self.last_jump, {})
|
||||||
local line, col = unpack(pos)
|
local line, col = unpack(pos)
|
||||||
api.nvim_win_set_cursor(winid, {line + 1, col})
|
api.nvim_win_set_cursor(winid, { line + 1, col })
|
||||||
end
|
end
|
||||||
api.nvim_buf_del_extmark(bufnr, ns, self.last_jump)
|
api.nvim_buf_del_extmark(bufnr, ns, self.last_jump)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user