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

WinResize hook expands incorrect selection values #4234

Open
SeerLite opened this issue Jun 17, 2021 · 1 comment
Open

WinResize hook expands incorrect selection values #4234

SeerLite opened this issue Jun 17, 2021 · 1 comment
Labels

Comments

@SeerLite
Copy link
Contributor

Steps

  1. Open an empty buffer and type add the following content:
1234
  1. Place the cursor on the 4.
  2. Enter both commands:
eval -draft %{ echo -debug "eval: %val{selections_desc}" }
hook window WinResize .* %{ echo -debug "WinResize: %val{selections_desc}" }
  1. Resize the terminal window.
  2. Switch to *debug* buffer.

Outcome

*debug* content is

eval: 1.4,1.4
WinResize: 1.1,1.1
[...]

The hook being window or global makes no difference.

Expected

WinResize's output should be 1.4,1.4 just like eval -drafts. Additionally, moving the cursor after setting the hook should update the hook's output accordingly.

Otherwise, the documentation for WinResize should be updated, as it currently only states that the changes to the selection state will be "discarded", but not that it will be incorrect from the moment it triggers.

@Screwtapello
Copy link
Contributor

Searching the codebase for WinResize led me to the function Window::run_hook_in_own_context, which creates a draft context:

kakoune/src/window.cc

Lines 360 to 362 in 8fdda6d

InputHandler hook_handler{{ *m_buffer, Selection{} },
Context::Flags::Draft,
std::move(client_name)};

Searching the codebase for Context::Flags::Draft led me to the place (I think) where eval -draft creates a draft context:

kakoune/src/commands.cc

Lines 1919 to 1921 in 8fdda6d

input_handler.emplace(base_context->selections(),
Context::Flags::Draft,
base_context->name());

I don't know why one creates a fresh InputHandler object, while the other adds to a stack(?) of input handlers, but it looks to me like eval -draft copies the current selections, while window hooks create a fresh, empty selection set, which matches the behaviour described above.

I'm not sure why the window hook doesn't use the window's current selections; maybe making a copy of the selections would be expensive? Maybe hooks like WinCreate fire before the window is properly initialised, so selection information is not yet available, and it was easier to make all window hooks behave the same way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants