0

I am writing a text editor.

With 1049 (alternate screen) mode + 1000 (mouse tracking) mode enabled, the terminal is able to catch both mouse scroll events and click events. I do not need the click events.

This has the added disadvantage of not allowing other useful motions with your mouse (example: an external copy paste by highlighting text on the terminal screen).

I say vim, because it has ideal mouse behavior, where with a scroll event the cursor position changes to reflect it, and click events seem not to affect it. In addition, it does so in a manner that does not lead to flickering.

The thing that tells me that it does not use 1049 + 1007 is that something like the external copy-paste (by highlighting text) is possible in vim.

My question: How is vim doing this?

I've scoured the source code and am unable to find it. I've also attempted to trace the escape sequences it writes to the screen. This holds true on 2 terminal emulators I've tried.

4
  • (Are you the guy I was talking to about mouse support around 2 weeks ago?) 1007 is not mouse tracking and won't send you click events, so I suspect a typo or other mistake in your post, could you please revise it?
    – egmont
    Commented Aug 18, 2023 at 9:46
  • Run vim (or whatever other utility) under script and then study the resulting typescript file to see the commands it sends to the terminal. Edit the file in various ways (e.g. keep just the part that corresponds to the startup only and not the shutdown of the app), or experiment in other ways (bisect etc.), replay with cat and see if it provides the desired result.
    – egmont
    Commented Aug 18, 2023 at 9:49
  • If mouse support (1000, 1002, 1003-ish) is enabled by an app then it gets click events; external copy-pasting action is still present in most terminal emulators if you also press Shift. If not then it doesn't get clicks; it might get scrolls converted into up/down keypresses depending on the 1007 mode. You cannot have proper mouse reporting (even if it's just scroll events) and shift-less external copy-paste at the same time. When you say you can highlight text as normal in vim, are you absolutely sure you're not confusing vim's own text selection mechanisn with the terminals?
    – egmont
    Commented Aug 18, 2023 at 9:52
  • I meant 1000. It's been revised. This is my main ongoing issue with my text editor. As for highlighting, you can simply do it and it highlights as usual (blue background, like the rest of the computer). Within my application, highlighting is not possible. It's the same within emacs (where the behavior is like vim, and click events seem to be ignored). Commented Aug 18, 2023 at 18:43

1 Answer 1

0

It is hard-coded in the copy of libvterm which vim has used for a couple of years, e.g., in state.c:

  case 1000:
  case 1002:
  case 1003:
    settermprop_int(state, VTERM_PROP_MOUSE,
        !val          ? VTERM_PROP_MOUSE_NONE  :
        (num == 1000) ? VTERM_PROP_MOUSE_CLICK :
        (num == 1002) ? VTERM_PROP_MOUSE_DRAG  :
                        VTERM_PROP_MOUSE_MOVE);
    break;

under the supposition that anything which pretends to be xterm implements the any-event and any-button controls. A lot of vim's term.c attempts to determine which xterm-wannabe may be used, since none of them get it all right, but libvterm ignores the checks that had been done.

(If you want to know how a program does something, starting by reading its source code is the most productive route).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .