|
79 | 79 |
|
80 | 80 | ---@private |
81 | 81 | function Render:checkbox() |
| 82 | + -- add 1 to end to account for space after checkbox |
82 | 83 | local node = self.data.checkbox |
83 | | - local right = self.config.right_pad |
84 | | - |
85 | | - -- add 1 to account for space after checkbox |
| 84 | + local row = node.start_row |
| 85 | + local start_col = node.start_col |
| 86 | + local end_col = node.end_col + 1 |
86 | 87 | local width = self.context:width(node) + 1 |
87 | | - local space = width - str.width(self.data.icon) |
88 | 88 |
|
89 | | - local line = self:line():text(self.data.icon, self.data.highlight) |
90 | | - if space < 0 then |
91 | | - -- not enough space to fit the icon in-place |
92 | | - self.marks:over(self.config, 'check_icon', node, { |
93 | | - virt_text = line:pad(right):get(), |
94 | | - virt_text_pos = 'inline', |
95 | | - conceal = '', |
96 | | - }, { 0, 0, 0, 1 }) |
97 | | - else |
98 | | - local fits = math.min(space, right) ---@type integer |
99 | | - space = space - fits |
100 | | - right = right - fits |
101 | | - |
102 | | - local row = node.start_row |
103 | | - local start_col = node.start_col |
104 | | - local end_col = node.end_col + 1 |
| 89 | + local line = self:line() |
| 90 | + :pad(self.config.left_pad) |
| 91 | + :text(self.data.icon, self.data.highlight) |
| 92 | + :pad(self.config.right_pad) |
105 | 93 |
|
| 94 | + local overlay = line:sub(1, width) |
| 95 | + if not overlay:empty() then |
106 | 96 | self.marks:add(self.config, 'check_icon', row, start_col, { |
107 | | - end_col = end_col - space, |
108 | | - virt_text = line:pad(fits):get(), |
| 97 | + virt_text = overlay:get(), |
109 | 98 | virt_text_pos = 'overlay', |
110 | 99 | }) |
111 | | - if space > 0 then |
112 | | - -- remove extra space after the icon |
113 | | - self.marks:add(self.config, 'check_icon', row, end_col - space, { |
114 | | - end_col = end_col, |
115 | | - conceal = '', |
116 | | - }) |
117 | | - end |
118 | | - if right > 0 then |
119 | | - -- add padding |
120 | | - self.marks:add(self.config, 'check_icon', row, end_col, { |
121 | | - virt_text = self:line():pad(right):get(), |
122 | | - virt_text_pos = 'inline', |
123 | | - }) |
124 | | - end |
| 100 | + end |
| 101 | + |
| 102 | + local inline = line:sub(width + 1, line:width()) |
| 103 | + if not inline:empty() then |
| 104 | + self.marks:add(self.config, 'check_icon', row, end_col, { |
| 105 | + virt_text = inline:get(), |
| 106 | + virt_text_pos = 'inline', |
| 107 | + }) |
| 108 | + end |
| 109 | + |
| 110 | + local space = width - overlay:width() |
| 111 | + if space > 0 then |
| 112 | + self.marks:add(self.config, 'check_icon', row, end_col - space, { |
| 113 | + end_col = end_col, |
| 114 | + conceal = '', |
| 115 | + }) |
125 | 116 | end |
126 | 117 | end |
127 | 118 |
|
|
0 commit comments