fix(mark): jumpable() can't detect under first and last marks
The first and the last marks should be included.
This commit is contained in:
17
README.md
17
README.md
@@ -104,23 +104,14 @@ If you want to use a key that's already used for completion purposes, take a loo
|
|||||||
local cmp = require('cmp')
|
local cmp = require('cmp')
|
||||||
local neogen = require('neogen')
|
local neogen = require('neogen')
|
||||||
|
|
||||||
local t = function(str)
|
|
||||||
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
|
||||||
end
|
|
||||||
|
|
||||||
local check_back_space = function()
|
|
||||||
local col = vim.fn.col '.' - 1
|
|
||||||
return col == 0 or vim.fn.getline('.'):sub(col, col):match '%s' ~= nil
|
|
||||||
end
|
|
||||||
|
|
||||||
cmp.setup {
|
cmp.setup {
|
||||||
...
|
...
|
||||||
|
|
||||||
-- You must set mapping if you want.
|
-- You must set mapping if you want.
|
||||||
mapping = {
|
mapping = {
|
||||||
["<tab>"] = cmp.mapping(function(fallback)
|
["<tab>"] = cmp.mapping(function(fallback)
|
||||||
if neogen.jumpable() then
|
if require('neogen').jumpable() then
|
||||||
vim.fn.feedkeys(t("<cmd>lua require('neogen').jump_next()<CR>"), "")
|
require('neogen').jump_next()
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
@@ -129,8 +120,8 @@ cmp.setup {
|
|||||||
"s",
|
"s",
|
||||||
}),
|
}),
|
||||||
["<S-tab>"] = cmp.mapping(function(fallback)
|
["<S-tab>"] = cmp.mapping(function(fallback)
|
||||||
if neogen.jumpable(-1) then
|
if require('neogen').jumpable(true) then
|
||||||
vim.fn.feedkeys(t("<cmd>lua require('neogen').jump_prev()<CR>"), "")
|
require('neogen').jump_prev()
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -34,11 +34,14 @@ mark.mark_len = function(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
mark.jumpable = function(self, reverse)
|
mark.jumpable = function(self, reverse)
|
||||||
|
if not self.started then
|
||||||
|
return false
|
||||||
|
end
|
||||||
local ret = true
|
local ret = true
|
||||||
if reverse then
|
if reverse then
|
||||||
ret = self.index ~= 1
|
ret = self.index > 0
|
||||||
else
|
else
|
||||||
ret = #self.ids ~= self.index
|
ret = #self.ids >= self.index
|
||||||
end
|
end
|
||||||
if ret then
|
if ret then
|
||||||
ret = self.bufnr == api.nvim_get_current_buf() and self.winid == api.nvim_get_current_win()
|
ret = self.bufnr == api.nvim_get_current_buf() and self.winid == api.nvim_get_current_win()
|
||||||
@@ -47,13 +50,17 @@ mark.jumpable = function(self, reverse)
|
|||||||
end
|
end
|
||||||
|
|
||||||
mark.jump = function(self, reverse)
|
mark.jump = function(self, reverse)
|
||||||
if self.index == 0 or 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
|
||||||
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
|
||||||
|
else
|
||||||
|
self:stop(true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mark.stop = function(self, should_jump)
|
mark.stop = function(self, should_jump)
|
||||||
|
|||||||
Reference in New Issue
Block a user