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:
hrsh7th
2021-10-16 23:37:32 +09:00
committed by GitHub
parent f0a6cca5b9
commit 0f28030aef
13 changed files with 279 additions and 84 deletions

View File

@@ -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

View File

@@ -1,6 +1,7 @@
local config = require('cmp.config')
local str = require('cmp.utils.str')
local types = require('cmp.types')
local api = require('cmp.utils.api')
---@class cmp.GhostTextView
local ghost_text_view = {}
@@ -53,6 +54,9 @@ end
---Show ghost text
---@param e cmp.Entry
ghost_text_view.show = function(self, e)
if not api.is_insert_mode() then
return
end
local changed = e ~= self.entry
self.win = vim.api.nvim_get_current_win()
self.entry = e

View File

@@ -3,7 +3,7 @@ local autocmd = require('cmp.utils.autocmd')
local keymap = require('cmp.utils.keymap')
local types = require('cmp.types')
local config = require('cmp.config')
local misc = require('cmp.utils.misc')
local api = require('cmp.utils.api')
---@class cmp.NativeEntriesView
---@field private offset number
@@ -70,7 +70,7 @@ native_entries_view.open = function(self, offset, entries)
end
native_entries_view.close = function(self)
if misc.is_suitable_mode() then
if api.is_suitable_mode() then
vim.fn.complete(1, {})
end
self.offset = -1
@@ -80,7 +80,7 @@ native_entries_view.close = function(self)
end
native_entries_view.abort = function(_)
if misc.is_suitable_mode() then
if api.is_suitable_mode() then
vim.api.nvim_select_popupmenu_item(-1, true, true, {})
end
end