From 9e72344be40bbae18e78a130b4eb1d4cc7911078 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 5 Jul 2023 12:45:44 +0100 Subject: [PATCH] fix(mouse): fix mouse dragging Fixes: #27 --- lua/satellite/autocmd/mark.lua | 11 ++--------- lua/satellite/autocmd/search.lua | 8 +------- lua/satellite/handlers/diagnostic.lua | 3 +-- lua/satellite/handlers/marks.lua | 8 +------- lua/satellite/mouse.lua | 1 + lua/satellite/view.lua | 4 ++-- 6 files changed, 8 insertions(+), 27 deletions(-) diff --git a/lua/satellite/autocmd/mark.lua b/lua/satellite/autocmd/mark.lua index 9b58a33..c5d0778 100644 --- a/lua/satellite/autocmd/mark.lua +++ b/lua/satellite/autocmd/mark.lua @@ -1,8 +1,4 @@ --- This module implements a user autocmd for Mark events ---- ---- The data fields is populated depending on the specific search event: ---- ... ---- local util = require 'satellite.util' local config = require 'satellite.config' @@ -21,7 +17,6 @@ local group = api.nvim_create_augroup('satellite_autocmd_mark', {}) ---@param m string mark name local function mark_set_keymap(m) local key = config.user_config.handlers.marks.key .. m - ---@diagnostic disable-next-line: missing-parameter if fn.maparg(key) == '' then vim.keymap.set({ 'n', 'x' }, key, function() exec_autocmd { key = key } @@ -30,13 +25,11 @@ local function mark_set_keymap(m) end end --- range over A-Z -for code = 65, 90 do +for code = string.byte('A'), string.byte('Z') do mark_set_keymap(string.char(code)) end --- -- range over a-z -for code = 97, 122 do +for code = string.byte('a'), string.byte('z') do mark_set_keymap(string.char(code)) end diff --git a/lua/satellite/autocmd/search.lua b/lua/satellite/autocmd/search.lua index f4239ed..a245e28 100644 --- a/lua/satellite/autocmd/search.lua +++ b/lua/satellite/autocmd/search.lua @@ -35,7 +35,6 @@ end) -- Refresh when activating search nav mappings for _, seq in ipairs { 'n', 'N', '&', '*' } do - ---@diagnostic disable-next-line: missing-parameter if fn.maparg(seq) == '' then vim.keymap.set('n', seq, function() exec_autocmd { key = seq } @@ -45,15 +44,10 @@ for _, seq in ipairs { 'n', 'N', '&', '*' } do end local function is_search_mode() - if - vim.o.incsearch + return vim.o.incsearch and vim.o.hlsearch and api.nvim_get_mode().mode == 'c' and vim.tbl_contains({ '/', '?' }, fn.getcmdtype()) - then - return true - end - return false end local group = api.nvim_create_augroup('satellite_autocmd_search', {}) diff --git a/lua/satellite/handlers/diagnostic.lua b/lua/satellite/handlers/diagnostic.lua index 1563537..628a6fa 100644 --- a/lua/satellite/handlers/diagnostic.lua +++ b/lua/satellite/handlers/diagnostic.lua @@ -32,8 +32,7 @@ function handler.update(bufnr, winid) local diags = vim.diagnostic.get(bufnr) for _, diag in ipairs(diags) do if diag.severity <= config.min_severity then - local lnum = diag.lnum + 1 - local pos = util.row_to_barpos(winid, lnum - 1) + local pos = util.row_to_barpos(winid, diag.lnum) local count = 1 if marks[pos] and marks[pos].count then diff --git a/lua/satellite/handlers/marks.lua b/lua/satellite/handlers/marks.lua index b1b1b8e..0539466 100644 --- a/lua/satellite/handlers/marks.lua +++ b/lua/satellite/handlers/marks.lua @@ -1,5 +1,4 @@ local util = require 'satellite.util' -local view = require 'satellite.view' local highlight = 'MarkSV' @@ -26,12 +25,7 @@ local config = {} ---@param m string mark name ---@return boolean local function mark_is_builtin(m) - for _, mark in pairs(BUILTIN_MARKS) do - if mark == m then - return true - end - end - return false + return vim.list_contains(BUILTIN_MARKS, m) end function handler.setup(config0, update) diff --git a/lua/satellite/mouse.lua b/lua/satellite/mouse.lua index 12e693d..46320e7 100644 --- a/lua/satellite/mouse.lua +++ b/lua/satellite/mouse.lua @@ -346,6 +346,7 @@ function M.handle_leftmouse() M.refresh_bars() end view.move_scrollbar(winid, row0) + vim.cmd.redraw() end end count = count + 1 diff --git a/lua/satellite/view.lua b/lua/satellite/view.lua index d91d942..1e69be5 100644 --- a/lua/satellite/view.lua +++ b/lua/satellite/view.lua @@ -165,7 +165,7 @@ local render = async.void(function(bbufnr, winid, row, height) end -- local bwinid = winids[winid] - -- if api.nvim_win_is_valid(winid) and api.nvim_win_is_valid(bwinid) then + -- if bwinid and api.nvim_win_is_valid(winid) and api.nvim_win_is_valid(bwinid) then -- reposition_bar(winid, bwinid, row) -- end end) @@ -327,7 +327,7 @@ function M.move_scrollbar(winid, row) local height = api.nvim_win_get_var(bar_winid, 'height') local bar_bufnr0 = api.nvim_win_get_buf(bar_winid) - render(bar_bufnr0, bar_winid, winid, row, height) + render(bar_bufnr0, winid, row, height) end function M.refresh_bars()