Skip to content

Commit

Permalink
fix: Fixed a bug causing callbacks to not work.
Browse files Browse the repository at this point in the history
  • Loading branch information
OXY2DEV committed Aug 31, 2024
1 parent 308024c commit 6641174
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions lua/markview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,7 @@ markview.splitView = {

close = function (self)
pcall(vim.api.nvim_win_close, self.window, true);
self.augroup = vim.api.nvim_create_augroup("markview_splitview", { clear = true });

self.attached_buffer = nil;
self.window = nil;
Expand Down Expand Up @@ -1561,7 +1562,7 @@ markview.splitView = {
pcall(markview.configuration.callbacks.on_enable, self.buf, self.window);

local cursor = vim.api.nvim_win_get_cursor(windows[1]);
vim.api.nvim_win_set_cursor(self.window, cursor);
pcall(vim.api.nvim_win_set_cursor, self.window, cursor);

local parsed_content;

Expand Down Expand Up @@ -1591,7 +1592,7 @@ markview.splitView = {
callback = vim.schedule_wrap(function ()
-- Set cursor
cursor = vim.api.nvim_win_get_cursor(windows[1]);
vim.api.nvim_win_set_cursor(self.window, cursor);
pcall(vim.api.nvim_win_set_cursor, self.window, cursor);
end)
});

Expand All @@ -1604,6 +1605,15 @@ markview.splitView = {
self:close();
end)
});
vim.api.nvim_create_autocmd({
"BufHidden"
}, {
group = self.augroup,
buffer = self.buffer,
callback = vim.schedule_wrap(function ()
markview.commands.splitDisable(self.attached_buffer);
end)
});

vim.api.nvim_create_autocmd({
"TextChanged", "TextChangedI"
Expand Down
2 changes: 1 addition & 1 deletion plugin/markview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ local redraw_autocmd = function (augroup, buffer)
end

-- Only on mode change or if the mode changed due to text changed
if event.buffer and event.buffer == buffer and mode ~= cached_mode or event.event == "ModeChanged" then
if mode ~= cached_mode or event.event == "ModeChanged" then
-- Call the on_mode_change callback before exiting
if not markview.configuration.callbacks or not markview.configuration.callbacks.on_mode_change then
goto noCallbacks;
Expand Down

0 comments on commit 6641174

Please sign in to comment.