From 0bea5e46ed61fee6c1b8663666cbc879b918d435 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 13 Oct 2024 10:00:00 +0200 Subject: [PATCH] feat: better calculations for window width and height --- lua/care/menu/init.lua | 9 ++++++--- lua/care/utils/window.lua | 12 +++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lua/care/menu/init.lua b/lua/care/menu/init.lua index fde7f20..94f234d 100644 --- a/lua/care/menu/init.lua +++ b/lua/care/menu/init.lua @@ -103,8 +103,13 @@ function Menu:draw_docs(entry) local do_stylize = format == "markdown" and vim.g.syntax_on ~= nil + width = width - (has_border and 2 or 0) + if do_stylize then - contents = vim.lsp.util._normalize_markdown(contents, { width = width - (has_border and 2 or 0) }) + contents = vim.lsp.util._normalize_markdown( + vim.split(table.concat(contents, "\n"), "\n", { trimempty = true }), + { width = width - (has_border and 2 or 0) } + ) vim.bo[self.docs_window.buf].filetype = "markdown" vim.treesitter.start(self.docs_window.buf) vim.api.nvim_buf_set_lines(self.docs_window.buf, 0, -1, false, contents) @@ -135,8 +140,6 @@ function Menu:draw_docs(entry) local height = math.min(content_height, config.max_height) - -- vim.fn.screenpos(0,0,vim.api.nvim_win_get_cursor(0)[2]).col - local docs_view_conf = self.config.ui.docs_view or {} self.docs_window:open_cursor_relative(width, height, win_offset, { diff --git a/lua/care/utils/window.lua b/lua/care/utils/window.lua index 366a4fc..5452a4f 100644 --- a/lua/care/utils/window.lua +++ b/lua/care/utils/window.lua @@ -93,9 +93,11 @@ function Window:open_cursor_relative(width, wanted_height, offset, config) col = col, zindex = 1000, }) + vim.wo[self.winnr][0].showbreak = "" vim.wo[self.winnr][0].scrolloff = 0 vim.wo[self.winnr][0].smoothscroll = true vim.wo[self.winnr][0].winhighlight = "Normal:@care.menu,FloatBorder:@care.border" + vim.wo[self.winnr][0].breakindent = false self:open_scrollbar_win(width, height, offset) end @@ -189,7 +191,15 @@ function Window:get_data() else local height = 0 for _, line in ipairs(vim.api.nvim_buf_get_lines(self.buf, 0, -1, false)) do - height = height + math.max(1, math.ceil(vim.fn.strdisplaywidth(line) / data.width_without_border)) + local wrapped_width = vim.fn.strdisplaywidth(line) - data.width_without_border + height = height + 1 + if wrapped_width > 0 then + height = height + + math.max( + 1, + math.ceil(wrapped_width / (data.width_without_border - vim.fn.strdisplaywidth(vim.o.showbreak))) + ) + end end data.total_lines = height end