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: calculate blob line without strdisplaywidth #29

Merged
merged 1 commit into from
Nov 4, 2024
Merged
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
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
Loading