feat: added `config.ui.wrap` and improved wrapping when wrap=true. Fixes #422

This commit is contained in:
Folke Lemaitre 2023-01-19 08:45:27 +01:00
parent c389ad552b
commit d6fc848067
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
4 changed files with 21 additions and 5 deletions

View File

@ -37,6 +37,7 @@ M.defaults = {
ui = {
-- a number <1 is a percentage., >1 is a fixed size
size = { width = 0.8, height = 0.8 },
wrap = true, -- wrap the lines in the ui
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
border = "none",
icons = {

View File

@ -52,6 +52,15 @@ function M.create()
---@cast self LazyView
Float.init(self)
if Config.options.ui.wrap then
vim.wo[self.win].wrap = true
vim.wo[self.win].linebreak = true
vim.wo[self.win].breakindent = true
-- vim.wo[self.win].breakindentopt = "shift:8"
else
vim.wo[self.win].wrap = false
end
require("lazy.view.colors").setup()
self.state = vim.deepcopy(default_state)

View File

@ -127,13 +127,13 @@ function M:title()
if self.view.state.mode == mode.name then
if mode.name == "home" then
self:append(title, "LazyH1")
self:append(title, "LazyH1", { wrap = true })
else
self:append(title, "LazyButtonActive")
self:append(title, "LazyButtonActive", { wrap = true })
self:highlight({ ["%(.%)"] = "LazySpecial" })
end
else
self:append(title, "LazyButton")
self:append(title, "LazyButton", { wrap = true })
self:highlight({ ["%(.%)"] = "LazySpecial" })
end
self:append(" ")

View File

@ -21,7 +21,7 @@ end
---@param str string
---@param hl? string|Extmark
---@param opts? {indent?: number, prefix?: string}
---@param opts? {indent?: number, prefix?: string, wrap?: boolean}
function Text:append(str, hl, opts)
opts = opts or {}
if #self._lines == 0 then
@ -39,7 +39,13 @@ function Text:append(str, hl, opts)
if l > 1 then
self:nl()
end
if str ~= "" and self:col() > 0 and self:col() + vim.fn.strwidth(line) + self.padding > self.wrap then
if
Config.options.ui.wrap
and opts.wrap
and str ~= ""
and self:col() > 0
and self:col() + vim.fn.strwidth(line) + self.padding > self.wrap
then
self:nl()
end
table.insert(self._lines[#self._lines], {