Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When ext_cmdline is enabled, the event grid_cursor_goto will not be sent during incsearch #28800

Closed
xiyaowong opened this issue May 17, 2024 · 5 comments
Labels
closed:question issues that are closed as usage questions has:repro issue contains minimal reproducing steps ui-extensibility UI extensibility, events, protocol
Milestone

Comments

@xiyaowong
Copy link

xiyaowong commented May 17, 2024

Problem

$ ./venv/bin/python3 test.py 
==== Disable ext_cmdline ===
### Start incsearch ###
grid_cursor_goto
grid_cursor_goto
==== Enable ext_cmdline ===
### Start incsearch ###

Steps to reproduce

  • pip install pynvim
  • Install NVIM v0.10.0
  • Run test.py
import threading

from pynvim import attach
from pynvim.api.buffer import Buffer


def test(ext_cmdline):
    print("====", "Enable" if ext_cmdline else "Disable", "ext_cmdline", "===")

    start_incsearch = False

    def event_handler(_, data):
        if not start_incsearch:
            return
        for ev in data:
            ev_name = ev[0]
            if 'cursor' in ev_name:
                print(ev_name)

    nvim = attach('child', argv=["nvim", "--embed", "--clean"])
    nvim.ui_attach(40, 20, True, ext_cmdline=ext_cmdline, ext_linegrid=True)

    buf: Buffer = nvim.api.create_buf(False, True)
    buf.append(['a', 'b', 'c', *[''] * 20, 'd', 'e', 'f'])
    nvim.api.open_win(
        buf,
        True,
        {
            'relative': 'win',
            'row': 3,
            'col': 3,
            'width': 30,
            'height': 15,
        },
    )

    def incsearch():
        nonlocal start_incsearch
        start_incsearch = True
        print('### Start incsearch ###')
        nvim.input('gg/e')

    timer = threading.Timer(1, lambda: nvim.async_call(incsearch))
    timer.start()

    quit = threading.Timer(2, lambda: nvim.async_call(lambda: nvim.quit()))
    quit.start()

    nvim.run_loop(event_handler, event_handler)


test(False)
test(True)

Expected behavior

Should the events be the same? Or is this expected behavior?

Neovim version (nvim -v)

NVIM v0.10.0

Vim (not Nvim) behaves the same?

Operating system/version

Windows 11

Terminal name/version

Windows Terminal

$TERM environment variable

Installation

Scoop

@xiyaowong xiyaowong added the bug issues reporting wrong behavior label May 17, 2024
@zeertzjq zeertzjq added the ui-extensibility UI extensibility, events, protocol label May 17, 2024
@justinmk justinmk added the has:repro issue contains minimal reproducing steps label May 17, 2024
@justinmk justinmk added this to the 0.11 milestone May 17, 2024
@xiyaowong
Copy link
Author

xiyaowong commented May 17, 2024

==== Disable ext_cmdline ===
### Start incsearch ###
['grid_cursor_goto', [1, 19, 2]]
['grid_scroll', [1, 3, 18, 3, 33, 11, 0]]
['win_viewport', [4, <Window(handle=1001)>, 11, 27, 25, 1, 27, 11]]
['grid_cursor_goto', [1, 19, 2]]
==== Enable ext_cmdline ===
### Start incsearch ###
['grid_scroll', [1, 3, 18, 3, 33, 11, 0]]
['win_viewport', [4, <Window(handle=1001)>, 11, 27, 25, 1, 27, 11]]

I printed out events related to scroll and viewport. It seems like this behavior is an intentional change in version 0.10? incsearch scrolls the window but doesn't move the cursor.

There should be relevant commits in the commit log.

I forgot that the current issue is that ext_cmdline is causing event inconsistencies, which should not be the expected behavior.

@luukvbaal
Copy link
Contributor

I forgot that the current issue is that ext_cmdline is causing event inconsistencies, which should not be the expected behavior.

Why not? This event was intentionally removed in d41b8d4 (#27858). All it did is send an event placing the cursor in the current window. Which is unhelpful, because the cursor should be in the cmdline which is unknown to Nvim. Unlike when ext_cmdline is disabled where this event does place the cursor in the cmdline(message grid).

@justinmk justinmk closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2024
@justinmk justinmk added closed:question issues that are closed as usage questions and removed bug issues reporting wrong behavior labels May 17, 2024
@xiyaowong
Copy link
Author

xiyaowong commented May 17, 2024

But the cursor is actually changed:

==== Disable ext_cmdline ===
cursor (1, 0)
### Start incsearch ###
grid_cursor_goto
grid_cursor_goto
cursor (26, 1)
==== Enable ext_cmdline ===
cursor (1, 0)
### Start incsearch ###
cursor (26, 1)
    def incsearch():
        nonlocal start_incsearch
        start_incsearch = True
        print('cursor', win.cursor)
        print("### Start incsearch ###")
        nvim.input("gg/e")
        print('cursor', win.cursor)

@luukvbaal
Copy link
Contributor

Well yes the cursor position in the current window changes for incsearch but the cursor position on the grid does not and should not(implicitly). What problem does this cause?

@xiyaowong
Copy link
Author

xiyaowong commented May 17, 2024

The potential issues may be related to the way UI events are handled. vscode-neovim currently only can adjust viewport based on cursor position rather than drawing.

However, the example I provided is indeed a special case, and the logic can be adjusted to solve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:question issues that are closed as usage questions has:repro issue contains minimal reproducing steps ui-extensibility UI extensibility, events, protocol
Projects
None yet
Development

No branches or pull requests

4 participants