Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lua/markview/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,24 @@ end
actions.set_query = function (buffer)
---|fS

-- Ensure buffer is valid before setting queries
if not vim.api.nvim_buf_is_valid(buffer) then
return;
end

--[[
NOTE: Check if `buffer` has `markdown` as it's parser language.

This should avoid,
- Invalid buffers(see #456)
- Buffers that do not have correct parser.
]]
local got_parser, parser = pcall(vim.treesitter.get_parser, buffer);

if not got_parser or (parser and parser:lang() ~= "markdown") then
return;
end

local default_path = vim.treesitter.query.get_files("markdown", "highlights")[1];

if not default_path then
Expand Down
8 changes: 8 additions & 0 deletions lua/markview/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@ autocmds.setup = function ()
callback = autocmds.bufHandle
});

vim.api.nvim_create_autocmd({
"BufDelete", "BufWipeout"
}, {
callback = function(args)
require("markview.state").detach(args.buf, true);
end
});

vim.api.nvim_create_autocmd({
"CursorMoved", "TextChanged",
"CursorMovedI", "TextChangedI"
Expand Down