Skip to content

Commit

Permalink
fix: use strwidth instead of strdisplaywidth
Browse files Browse the repository at this point in the history
`strdisplaywidth` is broken when called while loading a buffer. For
example on `BufReadPost`.

fix #832
  • Loading branch information
lukas-reineke committed Jun 28, 2024
1 parent 4288ce8 commit 65e20ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lua/ibl/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ M.default_config = {
---@return boolean, string?
local validate_char = function(char)
if type(char) == "string" then
local length = vim.fn.strdisplaywidth(char)
local length = vim.fn.strwidth(char)
return length <= 1, string.format("'%s' has a display width of %d", char, length)
else
if #char == 0 then
return false, "table is empty"
end
for i, c in ipairs(char) do
local length = vim.fn.strdisplaywidth(c)
local length = vim.fn.strwidth(c)
if length > 1 then
return false, string.format("index %d '%s' has a display width of %d", i, c, length)
end
Expand Down
4 changes: 2 additions & 2 deletions lua/ibl/virt_text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ M.get = function(

if indent.is_indent(ws) then
whitespace_hl = utils.tbl_get_index(highlights.whitespace, indent_index).char
if vim.fn.strdisplaywidth(char) == 0 then
if vim.fn.strwidth(char) == 0 then
char = char_map[whitespace.SPACE] --[[@as string]]
sa = false
else
Expand All @@ -108,7 +108,7 @@ M.get = function(

if config.scope.char then
local scope_char = get_char(config.scope.char, scope_index)
if vim.fn.strdisplaywidth(scope_char) == 1 then
if vim.fn.strwidth(scope_char) == 1 then
char = scope_char
end
end
Expand Down

0 comments on commit 65e20ab

Please sign in to comment.