Skip to content

Commit

Permalink
feat: better calculations for window width and height
Browse files Browse the repository at this point in the history
  • Loading branch information
max397574 committed Oct 20, 2024
1 parent 21eb175 commit 0bea5e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lua/care/menu/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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, {
Expand Down
12 changes: 11 additions & 1 deletion lua/care/utils/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0bea5e4

Please sign in to comment.