-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
local require = require("noice.util.lazy") | ||
|
||
---@module 'snacks' | ||
|
||
local Config = require("noice.config") | ||
local Format = require("noice.text.format") | ||
local Manager = require("noice.message.manager") | ||
|
||
local M = {} | ||
|
||
function M.find() | ||
local messages = Manager.get(Config.options.commands.history.filter, { | ||
history = true, | ||
sort = true, | ||
reverse = true, | ||
}) | ||
|
||
---@param message NoiceMessage | ||
return vim.tbl_map(function(message) | ||
return { | ||
message = message, | ||
text = message._lines[1]:content(), | ||
} | ||
end, messages) | ||
end | ||
|
||
---@param item snacks.picker.Item | ||
function M.format(item) | ||
local message = item.message --[[@as NoiceMessage]] | ||
message = Format.format(message, "snacks") | ||
return vim.tbl_map(function(text) | ||
return { text:content(), text.extmark and text.extmark.hl_group } | ||
end, message._lines[1]._texts) | ||
end | ||
|
||
---@type snacks.picker.preview | ||
function M.preview(ctx) | ||
local message = ctx.item.message --[[@as NoiceMessage]] | ||
message = Format.format(message, "snacks_preview") | ||
ctx.preview:reset() | ||
vim.bo[ctx.buf].modifiable = true | ||
message:render(ctx.buf, Config.ns) | ||
vim.bo[ctx.buf].modifiable = false | ||
end | ||
|
||
---@type snacks.picker.Config | ||
M.source = { | ||
source = "noice", | ||
finder = M.find, | ||
format = M.format, | ||
preview = M.preview, | ||
} | ||
|
||
---@param opts? snacks.picker.Config|{} | ||
function M.open(opts) | ||
return Snacks.picker("noice", opts) | ||
end | ||
|
||
return M |