Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(input): don't filter ^M and <cr> for the command line #734

Merged
merged 2 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/noice/message/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function Message:focus()
if win then
vim.api.nvim_set_current_win(win)
-- switch to normal mode
vim.cmd("stopinsert")
vim.cmd("stopinsert")
return true
end
end
Expand Down
10 changes: 6 additions & 4 deletions lua/noice/text/block.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local require = require("noice.util.lazy")

local Highlight = require("noice.text.highlight")
local Util = require("noice.util")
local NuiLine = require("nui.line")
local Object = require("nui.object")

Expand All @@ -10,6 +9,7 @@ local Object = require("nui.object")

---@class NoiceBlock
---@field _lines NuiLine[]
---@field fix_cr boolean?
---@overload fun(content?: NoiceContent|NoiceContent[], highlight?: string|table): NoiceBlock
local Block = Object("Block")

Expand Down Expand Up @@ -110,7 +110,7 @@ function Block:_append(content, highlight)
if #self._lines == 0 then
table.insert(self._lines, NuiLine())
end
if type(content) == "string" and true then
if type(content) == "string" and self.fix_cr ~= false then
-- handle carriage returns. They overwrite the line from the first character
local cr = content:match("^.*()[\r]")
if cr then
Expand Down Expand Up @@ -167,8 +167,10 @@ function Block:append(contents, highlight)
---@type number|string|table, string
local attr_id, text = unpack(content)
-- msg_show messages can contain invalid \r characters
text = text:gsub("%^M", "\r")
text = text:gsub("\r\n", "\n")
if self.fix_cr ~= false then
text = text:gsub("%^M", "\r")
text = text:gsub("\r\n", "\n")
end

---@type string|table|nil
local hl_group
Expand Down
1 change: 1 addition & 0 deletions lua/noice/ui/cmdline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ end
---@param text_only? boolean
function Cmdline:format(message, text_only)
local format = self:get_format()
message.fix_cr = false

if format.icon then
message:append(NoiceText.virtual_text(format.icon, format.icon_hl_group))
Expand Down
Loading