diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-08-21 23:19:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-21 23:19:12 +0800 |
commit | d401b33314a4178b23443c78119055c3d34a407e (patch) | |
tree | 9e47e95d17e24146bb1c1a53b3c4a2e2fcb14690 | |
parent | d0717a7c4e453a1c56f75a33367b65cf9f3115a8 (diff) | |
download | rneovim-d401b33314a4178b23443c78119055c3d34a407e.tar.gz rneovim-d401b33314a4178b23443c78119055c3d34a407e.tar.bz2 rneovim-d401b33314a4178b23443c78119055c3d34a407e.zip |
fix(terminal): handle horizontal scrolling in another window (#24828)
-rw-r--r-- | src/nvim/mouse.c | 4 | ||||
-rw-r--r-- | src/nvim/terminal.c | 33 | ||||
-rw-r--r-- | test/functional/terminal/mouse_spec.lua | 49 |
3 files changed, 63 insertions, 23 deletions
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 176aff849e..0f77b5d568 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -1003,13 +1003,13 @@ void ins_mouse(int c) /// K_MOUSERIGHT - MSCR_RIGHT /// "curwin" may have been changed to the window that should be scrolled and /// differ from the window that actually has focus. -static void do_mousescroll(cmdarg_T *cap) +void do_mousescroll(cmdarg_T *cap) { bool shift_or_ctrl = mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL); if (cap->arg == MSCR_UP || cap->arg == MSCR_DOWN) { // Vertical scrolling - if (!(State & MODE_INSERT) && shift_or_ctrl) { + if ((State & MODE_NORMAL) && shift_or_ctrl) { // whole page up or down (void)onepage(cap->arg ? FORWARD : BACKWARD, 1); } else { diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index a7e810087a..2d21451c9d 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -79,6 +79,7 @@ #include "nvim/move.h" #include "nvim/msgpack_rpc/channel_defs.h" #include "nvim/normal.h" +#include "nvim/ops.h" #include "nvim/option.h" #include "nvim/optionstr.h" #include "nvim/pos.h" @@ -1456,18 +1457,38 @@ static bool send_mouse_event(Terminal *term, int c) return false; } - if (c == K_MOUSEDOWN || c == K_MOUSEUP) { + if (c == K_MOUSEUP || c == K_MOUSEDOWN || c == K_MOUSELEFT || c == K_MOUSERIGHT) { win_T *save_curwin = curwin; // switch window/buffer to perform the scroll curwin = mouse_win; curbuf = curwin->w_buffer; - int direction = c == K_MOUSEDOWN ? MSCR_DOWN : MSCR_UP; - if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) { - scroll_redraw(direction, curwin->w_botline - curwin->w_topline); - } else if (p_mousescroll_vert > 0) { - scroll_redraw(direction, (linenr_T)p_mousescroll_vert); + + cmdarg_T cap; + oparg_T oa; + CLEAR_FIELD(cap); + clear_oparg(&oa); + cap.oap = &oa; + + switch (cap.cmdchar = c) { + case K_MOUSEUP: + cap.arg = MSCR_UP; + break; + case K_MOUSEDOWN: + cap.arg = MSCR_DOWN; + break; + case K_MOUSELEFT: + cap.arg = MSCR_LEFT; + break; + case K_MOUSERIGHT: + cap.arg = MSCR_RIGHT; + break; + default: + abort(); } + // Call the common mouse scroll function shared with other modes. + do_mousescroll(&cap); + curwin->w_redr_status = true; curwin = save_curwin; curbuf = curwin->w_buffer; diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index a2e9ffa1d7..6dccd14994 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -287,7 +287,7 @@ describe(':terminal mouse', function() ]]) end) - it("won't lose focus if another window is scrolled", function() + it("scrolling another window keeps focus and respects 'mousescroll'", function() feed('<ScrollWheelUp><4,0><ScrollWheelUp><4,0>') screen:expect([[ {7: 21 }line │line30 | @@ -308,20 +308,6 @@ describe(':terminal mouse', function() ========== ========== | {3:-- TERMINAL --} | ]]) - end) - - it("scrolling another window respects 'mousescroll'", function() - command('set mousescroll=ver:1') - feed('<ScrollWheelUp><4,0>') - screen:expect([[ - {7: 26 }line │line30 | - {7: 27 }line │rows: 5, cols: 25 | - {7: 28 }line │rows: 5, cols: 24 | - {7: 29 }line │mouse enabled | - {7: 30 }line │{1: } | - ========== ========== | - {3:-- TERMINAL --} | - ]]) command('set mousescroll=ver:10') feed('<ScrollWheelUp><4,0>') screen:expect([[ @@ -336,6 +322,39 @@ describe(':terminal mouse', function() command('set mousescroll=ver:0') feed('<ScrollWheelUp><4,0>') screen:expect_unchanged() + feed([[<C-\><C-N><C-W>w]]) + command('setlocal nowrap') + feed('0<C-V>gg3ly$4p<C-W>wi') + screen:expect([[ + {7: 1 }linelinelinelineline │line30 | + {7: 2 }linelinelinelineline │rows: 5, cols: 25 | + {7: 3 }linelinelinelineline │rows: 5, cols: 24 | + {7: 4 }linelinelinelineline │mouse enabled | + {7: 5 }linelinelinelineline │{1: } | + ========== ========== | + {3:-- TERMINAL --} | + ]]) + feed('<ScrollWheelRight><4,0>') + screen:expect([[ + {7: 1 }nelinelineline │line30 | + {7: 2 }nelinelineline │rows: 5, cols: 25 | + {7: 3 }nelinelineline │rows: 5, cols: 24 | + {7: 4 }nelinelineline │mouse enabled | + {7: 5 }nelinelineline │{1: } | + ========== ========== | + {3:-- TERMINAL --} | + ]]) + command('set mousescroll=hor:4') + feed('<ScrollWheelLeft><4,0>') + screen:expect([[ + {7: 1 }nelinelinelineline │line30 | + {7: 2 }nelinelinelineline │rows: 5, cols: 25 | + {7: 3 }nelinelinelineline │rows: 5, cols: 24 | + {7: 4 }nelinelinelineline │mouse enabled | + {7: 5 }nelinelinelineline │{1: } | + ========== ========== | + {3:-- TERMINAL --} | + ]]) end) it('will lose focus if another window is clicked', function() |