Fix rendering of wide characters in the custom completion window (#641)

This commit is contained in:
Dmytro Meleshko
2021-12-13 06:05:55 +02:00
committed by GitHub
parent af07ff9b79
commit 727ddee59e
4 changed files with 103 additions and 42 deletions

View File

@@ -1,17 +1,30 @@
local buffer = {}
buffer.ensure = setmetatable({
cache = {},
}, {
__call = function(self, name)
if not (self.cache[name] and vim.api.nvim_buf_is_valid(self.cache[name])) then
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_option(buf, 'buftype', 'nofile')
vim.api.nvim_buf_set_option(buf, 'bufhidden', 'hide')
self.cache[name] = buf
end
return self.cache[name]
end,
})
buffer.cache = {}
---@return number buf
buffer.get = function(name)
local buf = buffer.cache[name]
if buf and vim.api.nvim_buf_is_valid(buf) then
return buf
else
return nil
end
end
---@return number buf
---@return boolean created_new
buffer.ensure = function(name)
local created_new = false
local buf = buffer.get(name)
if not buf then
created_new = true
buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_option(buf, 'buftype', 'nofile')
vim.api.nvim_buf_set_option(buf, 'bufhidden', 'hide')
buffer.cache[name] = buf
end
return buf, created_new
end
return buffer