|
45 | 45 | ---@param bufnr number buffer id
|
46 | 46 | ---@param start_line number start line number to set the indentation, 0-based inclusive
|
47 | 47 | ---@param end_line number end line number to set the indentation, 0-based inclusive
|
48 |
| -function VirtualIndent:set_indent(bufnr, start_line, end_line) |
49 |
| - self:_delete_old_extmarks(bufnr, start_line, end_line) |
| 48 | +---@param ignore_ts? boolean whether or not to skip the treesitter start & end lookup |
| 49 | +function VirtualIndent:set_indent(bufnr, start_line, end_line, ignore_ts) |
| 50 | + ignore_ts = ignore_ts or false |
| 51 | + local headline = self.lib.headline.from_cursor({ start_line + 1, 1 }) |
| 52 | + if headline and not ignore_ts then |
| 53 | + local parent = headline.headline:parent() |
| 54 | + if parent then |
| 55 | + for node in parent:iter_children() do |
| 56 | + if node:type() == 'body' then |
| 57 | + start_line = node:start() |
| 58 | + end_line = node:end_() |
| 59 | + break |
| 60 | + end |
| 61 | + end |
| 62 | + end |
| 63 | + end |
| 64 | + self:_delete_old_extmarks(bufnr, start_line - 1, end_line) |
50 | 65 | for line = start_line, end_line do
|
51 | 66 | local indent = self:_get_indent_size(line)
|
52 | 67 |
|
|
64 | 79 | ---@param bufnr? number buffer id
|
65 | 80 | function VirtualIndent:attach(bufnr)
|
66 | 81 | bufnr = bufnr or 0
|
67 |
| - self:set_indent(0, 0, vim.api.nvim_buf_line_count(bufnr) - 1) |
| 82 | + self:set_indent(0, 0, vim.api.nvim_buf_line_count(bufnr) - 1, true) |
68 | 83 |
|
69 | 84 | vim.api.nvim_buf_attach(bufnr, false, {
|
70 | 85 | on_lines = function(_, _, _, start_line, _, end_line)
|
|
0 commit comments