Skip to content

Commit

Permalink
feat: use treesitter range for virtual indent by default
Browse files Browse the repository at this point in the history
When a user adds stars to a headline, the content in the region now all
gets correctly virtually indented.
  • Loading branch information
PriceHiller committed Nov 10, 2023
1 parent b2c433a commit 995a52e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lua/orgmode/ui/virtual_indent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,23 @@ end
---@param bufnr number buffer id
---@param start_line number start line number to set the indentation, 0-based inclusive
---@param end_line number end line number to set the indentation, 0-based inclusive
function VirtualIndent:set_indent(bufnr, start_line, end_line)
self:_delete_old_extmarks(bufnr, start_line, end_line)
---@param ignore_ts? boolean whether or not to skip the treesitter start & end lookup
function VirtualIndent:set_indent(bufnr, start_line, end_line, ignore_ts)
ignore_ts = ignore_ts or false
local headline = self.lib.headline.from_cursor({ start_line + 1, 1 })
if headline and not ignore_ts then
local parent = headline.headline:parent()
if parent then
for node in parent:iter_children() do
if node:type() == 'body' then
start_line = node:start()
end_line = node:end_()
break
end
end
end
end
self:_delete_old_extmarks(bufnr, start_line - 1, end_line)
for line = start_line, end_line do
local indent = self:_get_indent_size(line)

Expand All @@ -64,7 +79,7 @@ end
---@param bufnr? number buffer id
function VirtualIndent:attach(bufnr)
bufnr = bufnr or 0
self:set_indent(0, 0, vim.api.nvim_buf_line_count(bufnr) - 1)
self:set_indent(0, 0, vim.api.nvim_buf_line_count(bufnr) - 1, true)

vim.api.nvim_buf_attach(bufnr, false, {
on_lines = function(_, _, _, start_line, _, end_line)
Expand Down

0 comments on commit 995a52e

Please sign in to comment.