From e3b1f672a8e5ad665f19d89eabb5821b4e5cb4f2 Mon Sep 17 00:00:00 2001 From: Chiarandini Date: Sat, 22 Aug 2026 17:48:26 -0400 Subject: [PATCH] fix: read equation text from the parsed buffer, not the current one Buffer:parse passes 0 as the treesitter source to iter_captures and get_node_text, so both read whichever buffer happens to be current rather than self.bufnr. parse_view runs from the update_interval timer armed by on_lines and WinScrolled, so leaving the markdown buffer inside that window makes the node's range resolve against the wrong buffer: - a longer current buffer yields an empty string, and rendering "" fails. Drawing the resulting error message calls marks.add with length 0, which trips assert(col_end > col) in tracker.add. - a shorter current buffer raises "Index out of bounds" from nvim_buf_get_text. Both are reachable from a file containing nothing but $x+y$. --- lua/mdmath/overlay.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/mdmath/overlay.lua b/lua/mdmath/overlay.lua index 836a2f7..6402bb4 100644 --- a/lua/mdmath/overlay.lua +++ b/lua/mdmath/overlay.lua @@ -151,9 +151,9 @@ function Buffer:parse(start_row, end_row) local function get_queries(tree) local root = tree:root() - for _, node in query:iter_captures(root, 0, start_row, end_row) do + for _, node in query:iter_captures(root, bufnr, start_row, end_row) do local sr, sc, er, ec = node:range() - local value = ts.get_node_text(node, 0) + local value = ts.get_node_text(node, bufnr) process_equation(sr, sc, er, ec, value) end