Skip to content

Commit

Permalink
fix: calculate blob line without strdisplaywidth (#29)
Browse files Browse the repository at this point in the history
This is a workaround for the error "E976: using Blob as a String" on
strdisplaywidth.

Lines containing control characters are expected to be only composed of
ASCII.

Co-authored-by: aileot <[email protected]>
  • Loading branch information
aileot and aileot authored Nov 4, 2024
1 parent aad94e1 commit 897c905
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lua/deadcolumn/configs.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
local M = {}

local function displaywidth(line)
if vim.fn.type(line) == vim.v.t_blob then
-- This is a workaround for the error "E976: using Blob as a String" on
-- strdisplaywidth. Lines containing control characters are expected to be
-- only composed of ASCII.
return #line
end
return vim.fn.strdisplaywidth(line)
end

-- Functions to get the line length for different scopes
local scope_fn = {
line = function()
return vim.fn.strdisplaywidth(vim.fn.getline('.'))
return displaywidth(vim.api.nvim_get_current_line())
end,
buffer = function()
local range = 1000
Expand All @@ -14,7 +24,7 @@ local scope_fn = {
current_linenr + range,
false
)
return math.max(0, unpack(vim.tbl_map(vim.fn.strdisplaywidth, lines)))
return math.max(0, unpack(vim.tbl_map(displaywidth, lines)))
end,
visible = function()
local lines = vim.api.nvim_buf_get_lines(
Expand All @@ -23,7 +33,7 @@ local scope_fn = {
vim.fn.line('w$'),
false
)
return math.max(0, unpack(vim.tbl_map(vim.fn.strdisplaywidth, lines)))
return math.max(0, unpack(vim.tbl_map(displaywidth, lines)))
end,
cursor = function()
return vim.api.nvim_win_get_cursor(0)[2] + 1
Expand Down

0 comments on commit 897c905

Please sign in to comment.