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

stop processing key events twice on windows (#71) #73

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TeFiLeDo
Copy link
Contributor

@TeFiLeDo TeFiLeDo commented Feb 6, 2025

Basically what the title says.

What?

On windows igrep does run, but is basically unusable. When navigating through matches the cursor always moves by two lines (see #71). When opening the pattern dialog or keymap popup they close immediately. In some cases when running the program the first match is immediately opened. After closing the editor it is again opened immediately.

How?

Key events seem to be sent twice on windows, the second time with a release kind. This commit ignores such release events.

The crossterm documentation says the kind field is only set in certain conditions. Therefore the changes only use it if those conditions are met:

  1. The field is always set if the platform is windows. Thus it is always used on windows.

  2. On unix platform the field needs to be explicitly enabled before it can be used. I could not find any code enabling the field, therefore it is always ignored.

    Should this change in the future, the event_kind_enabled definition needs to be updated. This has been marked by a comment.

Notes

Sorry for having this commit show up multiple times in #71. I tried to get GitHub to display the commit as verified, but it just doesn't want to. I don't know what its problem is, local git can verify the commit just fine. Also, I use the same SSH key for pushing, so either GitHubs commit verification or push authentication is broken.

If this is a problem I can recreate the commit in a couple of days with my GPG key that I used last time I contributed.

@TeFiLeDo
Copy link
Contributor Author

TeFiLeDo commented Feb 6, 2025

I looked at the Lints check. None of the issues in there has anything to do with my changes.

// The following line needs to be amended if and when enabling the
// `KeyboardEnhancementFlags::REPORT_EVENT_TYPES` flag on unix.
let event_kind_enabled = cfg!(target_family = "windows");
let process_event = !event_kind_enabled || key_event.kind != KeyEventKind::Release;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we simply do this? I don't have a Windows machine to test this unfortunately.

let process_event = key_event.kind != KeyEventKind::Release;

Copy link
Contributor Author

@TeFiLeDo TeFiLeDo Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be fine for windows, but I don't know about other platforms.

The crossterm documentation seems to suggest that the field should only be read:

If searched through the igrep code, but did not find any code enabling that flag. I could not find any default value for that field when the flag is disabled. Given that the mentioned issue also is about windows, I did not want to change the behavior on other platforms.

I could change the variable name to check_event_kind if you think that is more readable. Currently it is basically a weird form of conditional compilation. However, if someone enables that flag later on they only need to change that line to be on par with windows.

@konradsz
Copy link
Owner

Thanks for looking into this! Don't worry about the lints, I will take care of them.

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

Successfully merging this pull request may close these issues.

2 participants