Skip to content

Commit

Permalink
change how ModeChange is handled, renamed handle_eagle_focus
Browse files Browse the repository at this point in the history
  • Loading branch information
soulis-1256 committed Feb 23, 2024
1 parent cbf0aa5 commit 9d1ccd7
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lua/eagle/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -371,21 +371,21 @@ function M.process_mouse_pos()
if vim.fn.mode() ~= 'n' or not M.is_mouse_on_code() then
renderDelayTimer:stop()
if eagle_win and vim.api.nvim_win_is_valid(eagle_win) and vim.api.nvim_get_current_win() ~= eagle_win then
M.handle_eagle_focus()
M.manage_windows()
end
return
end

if eagle_win and vim.api.nvim_win_is_valid(eagle_win) then
M.handle_eagle_focus()
M.manage_windows()
end

if vim.api.nvim_get_current_win() ~= eagle_win then
startRender()
end
end

function M.handle_eagle_focus()
function M.manage_windows()
-- if the eagle window is not open, return and make sure it can be re-rendered
-- this is done with win_lock, to prevent the case where the user presses :q for the eagle window
if not eagle_win or not vim.api.nvim_win_is_valid(eagle_win) then
Expand Down Expand Up @@ -499,7 +499,7 @@ local function handle_scroll()

if mousePos.line ~= last_mouse_line then
last_mouse_line = mousePos.line
M.handle_eagle_focus()
M.manage_windows()
end
end

Expand All @@ -526,7 +526,7 @@ local append_keymap = require("eagle.keymap")
append_keymap("n", "<MouseMove>", function(preceding)
preceding()

M.handle_eagle_focus()
M.manage_windows()
isMouseMoving = true
end, { silent = true })

Expand All @@ -541,7 +541,15 @@ append_keymap({ "n", "v" }, ":", function(preceding)
end, { silent = true })

-- detect changes in Neovim modes (close the eagle window when leaving normal mode)
vim.api.nvim_create_autocmd("ModeChanged", { callback = M.process_mouse_pos })
vim.api.nvim_create_autocmd("ModeChanged", { callback = function()
-- when entering normal mode, dont call process_mouse_pos(),
-- because we should let the user move the mouse again to "unlock" the plugin.
-- If we do otherwise, then when the user is focusing on typing something, the eagle window will keep popping up
-- whenever he enters normal mode (assuming the mouse is on code with diagnostics and/or lsp info).
if vim.fn.mode() ~= "n" then
M.process_mouse_pos()
end
end})

-- when the diagnostics of the file change, sort them
vim.api.nvim_create_autocmd("DiagnosticChanged", { callback = M.sort_buf_diagnostics })
Expand Down

0 comments on commit 9d1ccd7

Please sign in to comment.