Improve macro & dot-repeat support (#363)
* manual support dot-repeat * cmdwin and terminal * cmdline only * Fix * fix * Improve * Fix test * Support macro * disable cmdline for now * Simplify * fmt * consume once * Ignore = type * cmdline * Remove cmdline features
This commit is contained in:
@@ -4,7 +4,7 @@ local window = require('cmp.utils.window')
|
||||
local config = require('cmp.config')
|
||||
local types = require('cmp.types')
|
||||
local keymap = require('cmp.utils.keymap')
|
||||
local misc = require('cmp.utils.misc')
|
||||
local api = require('cmp.utils.api')
|
||||
|
||||
---@class cmp.CustomEntriesView
|
||||
---@field private entries_win cmp.Window
|
||||
@@ -129,16 +129,16 @@ custom_entries_view.open = function(self, offset, entries)
|
||||
width = width + self.column_width.kind + (self.column_width.menu > 0 and 1 or 0)
|
||||
width = width + self.column_width.menu + 1
|
||||
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
local pos = vim.fn.screenpos(0, cursor[1], cursor[2] + 1)
|
||||
local cursor = api.get_cursor()
|
||||
local pos = api.get_screen_cursor()
|
||||
local height = vim.api.nvim_get_option('pumheight')
|
||||
height = height == 0 and #self.entries or height
|
||||
height = math.min(height, #self.entries)
|
||||
if (vim.o.lines - pos.row) <= 8 and pos.row - 8 > 0 then
|
||||
height = math.min(height, pos.row - 1)
|
||||
pos.row = pos.row - height - 1
|
||||
if (vim.o.lines - pos[1]) <= 8 and pos[1] - 8 > 0 then
|
||||
height = math.min(height, pos[1] - 1)
|
||||
pos[1] = pos[1] - height - 1
|
||||
else
|
||||
height = math.min(height, vim.o.lines - pos.row)
|
||||
height = math.min(height, vim.o.lines - pos[1])
|
||||
end
|
||||
|
||||
if width < 1 or height < 1 then
|
||||
@@ -149,8 +149,8 @@ custom_entries_view.open = function(self, offset, entries)
|
||||
self.entries_win:open({
|
||||
relative = 'editor',
|
||||
style = 'minimal',
|
||||
row = pos.row,
|
||||
col = pos.col - 1 - delta - 1,
|
||||
row = pos[1],
|
||||
col = pos[2] - delta - 1,
|
||||
width = width,
|
||||
height = height,
|
||||
zindex = 1001,
|
||||
@@ -270,7 +270,7 @@ custom_entries_view._select = function(self, cursor, option)
|
||||
local is_insert = (option.behavior or types.cmp.SelectBehavior.Insert) == types.cmp.SelectBehavior.Insert
|
||||
if is_insert then
|
||||
if vim.api.nvim_win_get_cursor(self.entries_win.win)[2] == 1 then
|
||||
self.prefix = string.sub(vim.api.nvim_get_current_line(), self.offset, vim.api.nvim_win_get_cursor(0)[2]) or ''
|
||||
self.prefix = string.sub(api.get_current_line(), self.offset, api.get_cursor()[2]) or ''
|
||||
end
|
||||
end
|
||||
|
||||
@@ -286,18 +286,12 @@ custom_entries_view._select = function(self, cursor, option)
|
||||
end
|
||||
|
||||
custom_entries_view._insert = function(self, word)
|
||||
vim.api.nvim_buf_set_keymap(0, 'i', '<Plug>(cmp.view.custom_entries_view._insert.remove)', ('v:lua.cmp.view.custom_entries_view._insert.remove(%s)'):format(self.offset), {
|
||||
expr = true,
|
||||
noremap = true,
|
||||
})
|
||||
keymap.feedkeys(keymap.t('<Plug>(cmp.view.custom_entries_view._insert.remove)'), 't')
|
||||
keymap.feedkeys(word, 'nt')
|
||||
keymap.feedkeys('', 'n', function()
|
||||
local release = require('cmp').core:suspend()
|
||||
local cursor = api.get_cursor()
|
||||
local length = vim.str_utfindex(string.sub(api.get_current_line(), self.offset, cursor[2]))
|
||||
keymap.feedkeys(keymap.backspace(length) .. word, 'int', vim.schedule_wrap(release))
|
||||
end)
|
||||
end
|
||||
|
||||
misc.set(_G, { 'cmp', 'view', 'custom_entries_view', '_insert', 'remove' }, function(offset)
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
local length = vim.str_utfindex(string.sub(vim.api.nvim_get_current_line(), offset, cursor[2]))
|
||||
return keymap.backspace(length)
|
||||
end)
|
||||
|
||||
return custom_entries_view
|
||||
|
||||
Reference in New Issue
Block a user