[vim/vim] Add support for mouse buttons 8 and 9 to terminals with xterm-like mouse support (PR #18719)

14 views
Skip to first unread message

notuxic

unread,
Nov 10, 2025, 10:03:53 PM (23 hours ago) Nov 10
to vim/vim, Subscribed

Add support for mouse buttons 8 and 9 to terminals with xterm-like mouse support (xterm, xterm2, sgr, urxvt).

This adds support for:

  • <X1Mouse>
  • <X2Mouse>
  • <X1Release>
  • <X2Release>
  • <X1Drag>
  • <X2Drag>
    including control, meta and shift modifiers.

Button 8 corresponds to X1, button 9 to X2.

Adds tests for these newly supported buttons, existing tests continue working.

Adds documentation mentioning the support.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/18719

Commit Summary

  • 4578ebd Add support for mouse buttons 8 and 9 to xterm-like terminal mouse support
  • c53bc9a Add tests for mouse buttons 8 and 9 for xterm-like terminal mouse support
  • 7620496 Add docs for X1/X2 mouse button support in terminal

File Changes

(4 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18719@github.com>

notuxic

unread,
Nov 10, 2025, 10:18:42 PM (23 hours ago) Nov 10
to vim/vim, Push

@notuxic pushed 1 commit.

  • b21290e Fix missing platform check


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18719/before/7620496cf128b20f6a2d8aa96ac6267835478ccd/after/b21290eadb8e5681b93d149b704882bb2e5445af@github.com>

Copilot

unread,
12:42 PM (8 hours ago) 12:42 PM
to vim/vim, Subscribed

@Copilot commented on this pull request.

Pull Request Overview

This PR adds support for mouse buttons 8 and 9 (X1 and X2 buttons) to terminals with xterm-like mouse support (xterm, xterm2, sgr, urxvt). Previously, these buttons were only supported on Win32 and X11 GUI environments.

Key Changes:

  • Adds button code constants for side buttons (0xa0-0xbf range)
  • Implements button mapping logic to recognize and translate button 8/9 events to X1/X2
  • Adds comprehensive test coverage for press, release, drag, and modifier combinations

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/vim.h Defines MOUSESIDEBUTTONS_LOW constant (0xa0) to identify button 8-9 codes
src/mouse.c Updates mouse code handling to exclude side buttons from wheel processing and adds logic to map button 8/9 to X1/X2
src/testdir/test_termcodes.vim Adds new test function Test_term_mouse_side_buttons covering various button 8/9 scenarios
runtime/doc/term.txt Updates documentation to mention xterm-like terminal support for X1/X2 buttons

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


In src/testdir/test_termcodes.vim:

> +          \ ["<X1Mouse>", TerminalEscapeCode(128, 1, 1, 'M')],
+          \ ["<X1Drag>", TerminalEscapeCode(128+32, 1, 1, 'M')],
+          \ ["<X2Mouse>", TerminalEscapeCode(129, 1, 1, 'M')],
+          \ ["<X2Drag>", TerminalEscapeCode(129+32, 1, 1, 'M')],
+          \ ["<S-X1Mouse>", TerminalEscapeCode(128+4, 1, 1, 'M')],
+          \ ["<S-X2Mouse>", TerminalEscapeCode(129+4, 1, 1, 'M')],
+          \ ["<M-X1Mouse>", TerminalEscapeCode(128+8, 1, 1, 'M')],
+          \ ["<M-X2Mouse>", TerminalEscapeCode(129+8, 1, 1, 'M')],
+          \ ["<C-X1Mouse>", TerminalEscapeCode(128+16, 1, 1, 'M')],
+          \ ["<C-X2Mouse>", TerminalEscapeCode(129+16, 1, 1, 'M')],
+          \ ]
+
+    for [outstr, code] in mouse_codes
+      exe "normal ggC\<C-K>" . code
+      " normal ggD
+      " call feedkeys("i\<C-K>" . code, 'Lx!')

Remove commented-out code. These lines appear to be debugging or alternative testing approaches that were left in. If they're not needed, they should be removed to keep the test clean.

⬇️ Suggested change
-      " call feedkeys("i\<C-K>" . code, 'Lx!')

In src/mouse.c:

> @@ -2993,7 +2997,13 @@ check_termcode_mouse(
 	held_button = MOUSE_RELEASE;
     }
     else
+    {
+#if defined(UNIX)
+	if (use_xterm_mouse() && orig_mouse_code >= MOUSESIDEBUTTONS_LOW)
+	    current_button = (current_button) ? MOUSE_X2 : MOUSE_X1;

[nitpick] Consider using (orig_mouse_code & 0x01) instead of (current_button) for clarity. While the current logic is correct (relying on the LSB being preserved through the mask at line 2871), directly checking the LSB of orig_mouse_code would make the intent more explicit: button 8 (0xa0) has LSB=0 → X1, button 9 (0xa1) has LSB=1 → X2.

⬇️ Suggested change
-	    current_button = (current_button) ? MOUSE_X2 : MOUSE_X1;
+	    current_button = (orig_mouse_code & 0x01) ? MOUSE_X2 : MOUSE_X1;

In src/vim.h:

> @@ -2095,6 +2095,9 @@ typedef int sock_T;
 // Lowest button code for using the mouse wheel (xterm only)
 #define MOUSEWHEEL_LOW		0x60
 
+// Lowest button code for extra mouse buttons 8-11

The comment mentions "extra mouse buttons 8-11" but the implementation only adds support for buttons 8 and 9 (corresponding to X1 and X2). Consider updating the comment to "extra mouse buttons 8-9" to accurately reflect what's implemented, or clarify that 10-11 are reserved for future use.

⬇️ Suggested change
-// Lowest button code for extra mouse buttons 8-11
+// Lowest button code for extra mouse buttons 8-9


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18719/review/3449182294@github.com>

Christian Brabandt

unread,
12:55 PM (8 hours ago) 12:55 PM
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#18719)

thanks


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18719/c3518075753@github.com>

Christian Brabandt

unread,
12:55 PM (8 hours ago) 12:55 PM
to vim/vim, Subscribed

Closed #18719 via 7dd51d3.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18719/issue_event/20868557518@github.com>

Reply all
Reply to author
Forward
0 new messages