Skip to content

strings.truncate can freeze when in a fast event/strings.strcharpart's fallback is used #682

Description

@lazy-orb-weaver

(I saw the no longer maintained sign, consider this for documentation purposes or something)

there's an oopsie in strings.strcharpart's fallback function. sub takes start and end positions, and not start and length like vim's strcharpart:

if vim.in_fast_event() then
return str:sub(nchar + 1, charlen)
end
return vim.fn.strcharpart(str, nchar, charlen)

when this fallback function is used, the truncate function can get stuck in an infinite loop whenever the direction is positive and the string is long enough to be truncated. for example, this freezes in a fast state:

truncate("test string", 5, "...", 1)

to fix this, I think the fallback just needs to be: return str:sub(nchar + 1, nchar + charlen)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions