Skip to content

Commit

Permalink
feat: added config.ui.wrap and improved wrapping when wrap=true. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jan 19, 2023
1 parent c389ad5 commit d6fc848
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
9 changes: 9 additions & 0 deletions lua/lazy/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ")
Expand Down
10 changes: 8 additions & 2 deletions lua/lazy/view/text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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], {
Expand Down

0 comments on commit d6fc848

Please sign in to comment.