From b11bbd9741f2980eae8261780b9605fc109b6447 Mon Sep 17 00:00:00 2001 From: Thaumy Cheng Date: Thu, 19 Mar 2026 00:26:17 +0800 Subject: [PATCH] fix: mouse click on quickfix buffer Previously, double-clicking a quickfix entry opened a new window, while `` reused the existing one. This was caused by the preview mouse mapping overriding the default `<2-LeftMouse>` behavior. Additionally, nvim_set_current_win was called unnecessarily when clicking within the quickfix window itself. Changes: - Emit `` on double left-click to ensure consistent behavior - Remove overridden `<2-LeftMouse>` mapping - Skip `nvim_set_current_win` if the clicked window is qflist --- lua/bqf/keymap.lua | 7 ------- lua/bqf/preview/handler.lua | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lua/bqf/keymap.lua b/lua/bqf/keymap.lua index 343007e..38ca285 100644 --- a/lua/bqf/keymap.lua +++ b/lua/bqf/keymap.lua @@ -170,13 +170,6 @@ function M.initialize() ) end end - api.nvim_buf_set_keymap( - 0, - 'n', - '<2-LeftMouse>', - '', - {desc = utils.has08() and 'Open the item under the cursor' or nil, nowait = true, noremap = false} - ) end --- diff --git a/lua/bqf/preview/handler.lua b/lua/bqf/preview/handler.lua index 2ccffb9..17550f1 100644 --- a/lua/bqf/preview/handler.lua +++ b/lua/bqf/preview/handler.lua @@ -425,8 +425,12 @@ end function M.mouseClick(mode) local clickedWinid = checkClicked() + local clickedBufnr = api.nvim_win_get_buf(clickedWinid) + local qfBufClicked = api.nvim_get_option_value('bt', {buf = clickedBufnr}) == 'quickfix' if not clicked then - api.nvim_set_current_win(clickedWinid) + if not qfBufClicked then + api.nvim_set_current_win(clickedWinid) + end cmd(('norm! %dgg%d|'):format(vim.v.mouse_lnum, vim.v.mouse_col)) else if mode == 't' then @@ -437,9 +441,15 @@ end function M.mouseDoubleClick(mode) local clickedWinid = checkClicked() + local clickedBufnr = api.nvim_win_get_buf(clickedWinid) + local qfBufClicked = api.nvim_get_option_value('bt', {buf = clickedBufnr}) == 'quickfix' if api.nvim_get_current_win() == clickedWinid then - -- ^M = 0x0d - cmd(('norm! %c'):format(0x0d)) + if qfBufClicked then + -- ^M = 0x0d + cmd(('norm %c'):format(0x0d)) + else + cmd(('norm! %c'):format(0x0d)) + end elseif clicked then if mode == 't' then cmd('startinsert')