Skip to content

Commit

Permalink
fix: Reduced flickering when scrolling short distances
Browse files Browse the repository at this point in the history
New bugs may occur.
  • Loading branch information
OXY2DEV committed Aug 25, 2024
1 parent 87badab commit a1923f9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ftplugin/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ if vim.list_contains(markview.configuration.modes, "i") then
table.insert(update_events, "TextChangedI"); -- For smoother experience when writing, potentially can cause bugs
end

local prev_pos = vim.api.nvim_win_get_cursor(0)[1];

-- ISSUE: Work in progress
vim.api.nvim_create_autocmd(update_events, {
buffer = vim.api.nvim_get_current_buf(),
Expand All @@ -133,7 +135,7 @@ vim.api.nvim_create_autocmd(update_events, {

local mode = vim.api.nvim_get_mode().mode;

if cached_mode and cached_mode == mode then
if not vim.list_contains({ "CursorMoved", "CursorMovedI" }, event.event) and cached_mode and cached_mode == mode then
mode_debounce = 0;
end

Expand All @@ -150,6 +152,15 @@ vim.api.nvim_create_autocmd(update_events, {
-- In case something managed to change the mode
mode = vim.api.nvim_get_mode().mode;

local current_pos = vim.api.nvim_win_get_cursor(0)[1];

-- Experimental
-- May introduce bugs
if vim.list_contains({ "CursorMoved", "CursorMovedI" }, event.event) and math.abs(prev_pos - current_pos) < 100 then
prev_pos = current_pos;
return;
end

-- Only on mode change or if the mode changed due to text changed
if mode ~= cached_mode or event.event == "ModeChanged" then
-- Call the on_mode_change callback before exiting
Expand Down

0 comments on commit a1923f9

Please sign in to comment.