From babb8023c617575232a7ca83ad0a2145877cd4d7 Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Sun, 10 Oct 2021 12:13:57 +0900 Subject: [PATCH] Add `cmp.visible` --- README.md | 6 ++++++ lua/cmp/utils/window.lua | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d8f5aa..0c154db 100644 --- a/README.md +++ b/README.md @@ -434,6 +434,12 @@ Programatic API You can use the following APIs. +#### `cmp.visible()` + +Return the completion menu is visible or not. + +NOTE: This method returns true if the native popup menu is visible. For convenience to define mappings. + #### `cmp.confirm({ select = boolean, behavior = cmp.ConfirmBehavior.{Insert,Replace} })` Confirm current selected item if possible. diff --git a/lua/cmp/utils/window.lua b/lua/cmp/utils/window.lua index 6f87ce4..c612748 100644 --- a/lua/cmp/utils/window.lua +++ b/lua/cmp/utils/window.lua @@ -258,7 +258,7 @@ window.get_content_height = function(self) }, function() local height = 0 for _, text in ipairs(vim.api.nvim_buf_get_lines(self.buf, 0, -1, false)) do - height = height + math.ceil(math.max(1, vim.fn.strdisplaywidth(text)) / self.style.width) + height = height + math.ceil(math.max(1, vim.str_utfindex(text)) / self.style.width) end return height end)