Skip to content

Commit

Permalink
fix(notify): take col offsets into account for nvim-notify renderers. F…
Browse files Browse the repository at this point in the history
…ixes #375
  • Loading branch information
folke committed Mar 2, 2023
1 parent d8a1f30 commit 20596d9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lua/noice/view/backend/notify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local require = require("noice.util.lazy")
local Util = require("noice.util")
local View = require("noice.view")
local Manager = require("noice.message.manager")
local NuiText = require("nui.text")

---@class NoiceNotifyOptions
---@field title string
Expand Down Expand Up @@ -85,7 +86,18 @@ function NotifyView:notify_render(messages, render, content)

if idx then
-- we found the offset of the content as a string
local offset = #vim.split(text:sub(1, idx - 1), "\n")
local before = text:sub(1, idx - 1)
local offset = #vim.split(before, "\n")
local offset_col = #before:match("[^\n]*$")

-- in case the content starts in the middle of the line,
-- we need to add a fake prefix to the first line of the first message
-- see #375
if offset_col > 0 then
messages = vim.deepcopy(messages)
table.insert(messages[1]._lines[1]._texts, 1, NuiText(string.rep(" ", offset_col)))
end

-- do our rendering
self:render(buf, { offset = offset, highlight = true, messages = messages })
-- in case we didn't find the offset, we won't highlight anything
Expand Down

0 comments on commit 20596d9

Please sign in to comment.