Skip to content

Commit 3a319cd

Browse files
fix: highlight index width calculation
## Details Issue: #212 Calculating the end index of highlighted ranges was done based on display width but should be done using byte width. Fix is simple and replaces the usage of `Str.width` with the Lua `#`. Need a better way to keep the concepts of displayed width and byte width and when to use which straight. For the most part displayed width is the correct thing but when placing marks it is not.
1 parent 6096cf3 commit 3a319cd

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

doc/render-markdown.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 November 25
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 November 27
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local state = require('render-markdown.state')
44
local M = {}
55

66
---@private
7-
M.version = '7.6.0'
7+
M.version = '7.6.1'
88

99
function M.check()
1010
M.start('version')

lua/render-markdown/render/inline_highlight.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ end
4747
function Render:row_col(index, offset)
4848
local lines = Str.split(self.node.text:sub(1, index), '\n')
4949
local row = self.node.start_row + #lines - 1
50-
local col = Str.width(lines[#lines]) - offset
50+
local col = #lines[#lines] - offset
5151
if row == self.node.start_row then
5252
col = col + self.node.start_col
5353
end

tests/conceal_level_spec.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('table.md conceallevel', function()
1313
' 3 │ Heading 1 │ `Heading 2` │',
1414
' 4 ├───────────┼─────────────────────────━┤',
1515
' 5 │ `Item 行` │ 󰖟 [link](https://行.com) │',
16-
' 6 │ <1> │ ==Item 2== │',
16+
' 6 │ <1> │ ==Itém 2== │',
1717
' └───────────┴──────────────────────────┘',
1818
' 7',
1919
'󰫎 8 󰲡 Table no Inline',
@@ -36,7 +36,7 @@ describe('table.md conceallevel', function()
3636
' 3 │ Heading 1 │ Heading 2 │',
3737
' 4 ├───────────┼───────────────────────━┤',
3838
' 5 │ Item 行 │ 󰖟 link │',
39-
' 6 │ <1> │ Item 2 │',
39+
' 6 │ <1> │ Itém 2 │',
4040
' └───────────┴────────────────────────┘',
4141
' 7',
4242
'󰫎 8 󰲡 Table no Inline',
@@ -59,7 +59,7 @@ describe('table.md conceallevel', function()
5959
' 3 │ Heading 1 │ Heading 2 │',
6060
' 4 ├───────────┼───────────────────────━┤',
6161
' 5 │ Item 行 │ 󰖟 link │',
62-
' 6 │ <1> │ Item 2 │',
62+
' 6 │ <1> │ Itém 2 │',
6363
' └───────────┴────────────────────────┘',
6464
' 7',
6565
'󰫎 8 󰲡 Table no Inline',
@@ -82,7 +82,7 @@ describe('table.md conceallevel', function()
8282
' 3 │ Heading 1 │ Heading 2 │',
8383
' 4 ├───────────┼───────────────────────━┤',
8484
' 5 │ Item 行 │ 󰖟 link │',
85-
' 6 │ 1 │ Item 2 │',
85+
' 6 │ 1 │ Itém 2 │',
8686
' └───────────┴────────────────────────┘',
8787
' 7',
8888
'󰫎 8 󰲡 Table no Inline',

tests/data/table.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
| Heading 1 | `Heading 2` |
44
| --------- | ---------------------: |
55
| `Item 行` | [link](https://行.com) |
6-
| &lt;1&gt; | ==Item 2== |
6+
| &lt;1&gt; | ==Itém 2== |
77

88
# Table no Inline
99

tests/table_spec.lua

+14-14
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ describe('table.md', function()
2929
util.table_padding(row:get(), 12, 8),
3030
util.table_pipe(row:get(), 12, false),
3131
util.table_padding(row:get(), 14, 16),
32-
util.inline_highlight(row:get(), 14, 24),
33-
util.conceal(row:get(), 25, 37),
34-
util.table_pipe(row:get(), 37, false),
32+
util.inline_highlight(row:get(), 14, 25),
33+
util.conceal(row:get(), 26, 38),
34+
util.table_pipe(row:get(), 38, false),
3535
util.table_border(row:get(), false, { 11, 24 }),
3636
})
3737

@@ -55,7 +55,7 @@ describe('table.md', function()
5555
' 3 │ Heading 1 │ Heading 2 │',
5656
' 4 ├───────────┼───────────────────────━┤',
5757
' 5 │ Item 行 │ 󰖟 link │',
58-
' 6 │ 1 │ Item 2 │',
58+
' 6 │ 1 │ Itém 2 │',
5959
' └───────────┴────────────────────────┘',
6060
' 7',
6161
'󰫎 8 󰲡 Table no Inline',
@@ -93,9 +93,9 @@ describe('table.md', function()
9393
util.table_padding(row:get(), 12, 8),
9494
util.table_pipe(row:get(), 12, false),
9595
util.table_padding(row:get(), 14, 3),
96-
util.inline_highlight(row:get(), 14, 24),
97-
util.conceal(row:get(), 25, 37),
98-
util.table_pipe(row:get(), 37, false),
96+
util.inline_highlight(row:get(), 14, 25),
97+
util.conceal(row:get(), 26, 38),
98+
util.table_pipe(row:get(), 38, false),
9999
util.table_border(row:get(), false, { 11, 11 }),
100100
})
101101

@@ -119,7 +119,7 @@ describe('table.md', function()
119119
' 3 │ Heading 1 │ Heading 2 │',
120120
' 4 ├───────────┼──────────━┤',
121121
' 5 │ Item 行 │ 󰖟 link │',
122-
' 6 │ 1 │ Item 2 │',
122+
' 6 │ 1 │ Itém 2 │',
123123
' └───────────┴───────────┘',
124124
' 7',
125125
'󰫎 8 󰲡 Table no Inline',
@@ -151,8 +151,8 @@ describe('table.md', function()
151151
util.table_pipe(row:get(), 39, false),
152152
util.table_pipe(row:increment(), 0, false),
153153
util.table_pipe(row:get(), 12, false),
154-
util.inline_highlight(row:get(), 14, 24),
155-
util.table_pipe(row:get(), 37, false),
154+
util.inline_highlight(row:get(), 14, 25),
155+
util.table_pipe(row:get(), 38, false),
156156
})
157157

158158
vim.list_extend(expected, {
@@ -174,7 +174,7 @@ describe('table.md', function()
174174
' 3 │ Heading 1 │ Heading 2 │',
175175
' 4 ├───────────┼───────────────────────━┤',
176176
' 5 │ Item 行 │ 󰖟 link │',
177-
' 6 │ 1 │ Item 2 │',
177+
' 6 │ 1 │ Itém 2 │',
178178
' 7',
179179
'󰫎 8 󰲡 Table no Inline',
180180
' 9',
@@ -216,8 +216,8 @@ describe('table.md', function()
216216
table_row(row:increment(), 40, '│ `Item 行` │ [link](https://行.com) │', false),
217217
util.inline_code(row:get(), 2, 12),
218218
util.link(row:get(), 15, 38, 'web'),
219-
table_row(row:increment(), 38, '│ &lt;1&gt; │ ==Item 2== │', false),
220-
util.inline_highlight(row:get(), 14, 24),
219+
table_row(row:increment(), 39, '│ &lt;1&gt; │ ==Itém 2== │', false),
220+
util.inline_highlight(row:get(), 14, 25),
221221
util.table_border(row:get(), false, { 11, 24 }),
222222
})
223223

@@ -237,7 +237,7 @@ describe('table.md', function()
237237
' 3 │ Heading 1 │ `Heading 2` │',
238238
' 4 ├───────────┼───────────────────────━┤',
239239
' 5 │ `Item 行` │ [link](https://行.com) │',
240-
' 6 │ &lt;1&gt; │ ==Item 2== │',
240+
' 6 │ &lt;1&gt; │ ==Itém 2== │',
241241
' └───────────┴────────────────────────┘',
242242
' 7',
243243
'󰫎 8 󰲡 Table no Inline',

0 commit comments

Comments
 (0)