Skip to content

Commit

Permalink
text: update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
itepechi committed Sep 30, 2024
1 parent bd94e23 commit 4dce8d6
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lua/hlchunk/utils/chunkHelper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ end
local function virt_text_char_width(char, shiftwidth)
local b1 = char:byte(1)
if b1 == 0x00 then
-- NULL is a terminator when used in virtual texts
-- NULL is treated as a terminator when used in virtual text
return 0
elseif b1 == 0x09 then
return shiftwidth
elseif b1 <= 0x1F or b1 == 0x7F then
-- control chars other than NULL and TAB are two cells wide
-- ASCII control chars other than NULL and TAB are two cells wide
return 2
elseif b1 <= 0x7F then
-- other ASCII chars are single cell wide
Expand Down Expand Up @@ -201,7 +201,7 @@ function chunkHelper.rangeFromTo(i, j, step)
return t
end

---@param char_list table<integer, string>
---@param char_list string[]
---@param leftcol integer
---@param shiftwidth integer
---@return integer[]
Expand Down Expand Up @@ -241,7 +241,7 @@ function chunkHelper.repeatToWidth(str, width, shiftwidth)
local i = 1
while i <= #chars do
local char_width = virt_text_char_width(chars[i], shiftwidth)
---assumed to be an out-of-bounds char (like in nerd fonts) followed by a whitespace if true
---if true, the char is assumed to be an out-of-bounds char (like in nerd fonts), followed by a whitespace
local likely_oob_char =
-- single-cell
char_width == 1
Expand Down Expand Up @@ -305,15 +305,15 @@ function chunkHelper.checkCellsBlank(line, start_col, end_col, shiftwidth)
elseif char == "\t" then
next_col = current_col + shiftwidth
elseif b1 <= 0x1F or char == "\127" then
-- despite nvim_strwidth returning 0 or 1, control chars are 2 cells wide
-- despite nvim_strwidth returning 0 or 1, ASCII control chars are 2 cells wide
next_col = current_col + 2
elseif b1 <= 0x7F then
-- other ASCII chars are single cell wide
next_col = current_col + 1
else
local char_width = vim.api.nvim_strwidth(char)
if char_width == 1 and chars[current_char + 1] == " " then
-- the char is assumed to be an out-of-bounds char (like in nerd fonts)
-- the char is assumed to be an out-of-bounds char (like in nerd fonts),
-- followed by a whitespace
next_col = current_col + 2
-- skip the whitespace part of out-of-bounds char + " "
Expand All @@ -327,9 +327,8 @@ function chunkHelper.checkCellsBlank(line, start_col, end_col, shiftwidth)
-- (e.g. "%s" matches to "\v" but it will be printed as ^K)
if
(current_col >= start_col or next_col - 1 >= start_col)
-- Singles
--
-- Indent characters
--
-- Unicode Scripts Z*
-- 0020 - SPACE
and char ~= " "
Expand All @@ -340,6 +339,7 @@ function chunkHelper.checkCellsBlank(line, start_col, end_col, shiftwidth)
and char ~= " "
--
-- Non indent characters
--
-- Unicode Scripts Z*
-- 00A0 - NO-BREAK SPACE
and char ~= " "
Expand Down Expand Up @@ -372,6 +372,7 @@ function chunkHelper.checkCellsBlank(line, start_col, end_col, shiftwidth)
]]
--
-- Others
--
-- 2800 - BRAILLE PATTERN BLANK
and char ~= ""
--[[
Expand Down Expand Up @@ -401,7 +402,7 @@ function chunkHelper.virtTextStrWidth(str, shiftwidth, stop_on_null)
local current_width = 0
for _, char in ipairs(chunkHelper.utf8Split(str)) do
if stop_on_null and char == "\0" then
-- NULL is a terminator when used in virtual texts
-- NULL is treated as a terminator when used in virtual text
return current_width
end
current_width = current_width + virt_text_char_width(char, shiftwidth)
Expand Down

0 comments on commit 4dce8d6

Please sign in to comment.