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

Replace <C-C><C-C> with <C-C> #366

Closed
wants to merge 3 commits into from
Closed

Replace <C-C><C-C> with <C-C> #366

wants to merge 3 commits into from

Conversation

dstein64
Copy link
Contributor

Vim intentionally replaces <C-C> with <C-C><C-C>, which is reflected in the output when using -W (vim/vim#11541).

In VimGolf, when a user enters <C-C>, the input will count as two keystrokes towards the score, showing <C-C> twice in the displayed keystrokes.

This PR updates the code to replace <C-C><C-C> with <C-C>. This will allow the CLI to not double count <C-C> in the reported keystrokes and score. My motivation for handling this in keylog.rb, rather than e.g., cli.rb, is that the server code would be able to utilize this update as well. However, without updating the database, which appears to save scores, the scores would presumably still be incorrect for already-submitted solutions.

This fixes #224.

@dstein64
Copy link
Contributor Author

dstein64 commented Nov 15, 2022

"My motivation for handling this in keylog.rb, rather than e.g., cli.rb, is that the server code would be able to utilize this update as well."

To elaborate, my thought was that an alternative way to handle this would be to have the CLI fix the issue right when reading the keylog file generated by Vim. Then all new submossions from the updated CLI wouldn't have the issue.

But I thought that there may be users that don't update their CLI version frequently, and the current version of the PR would properly handle their entry upon submission (although if they were using an older CLI, the wrong keystrokes and score would still be shown when they're using the application, but not by the webapp after submission).

Upon further thought, I'm less confident in the approach I implemented versus the alternative (having this handled immediately by the CLI when loading the keylog script). If you're interested in the general type of update in this PR (replacing <C-C><C-C> with <C-C>, with various possibilities for the actual implementation), please let me know if you have any preference one way or the other.

Comment on lines +11 to +13
# Vim intentionally replaces "<C-C>" (\x03) with "<C-C><C-C>" (Vim #11541).
# Convert "<C-C><C-C>" back to "<C-C>" (VimGolf #224).
@input = input.force_encoding(Encoding::ASCII_8BIT).gsub("\x03\x03", "\x03")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally had the comment and update on separate lines, after the input.force_encoding line, but I moved them both here after a rubocop error from too many lines.

@dstein64
Copy link
Contributor Author

I'm going to close this for now, to explore the alternative approach I mentioned above.

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.

<C-C> gets counted twice when used to exit insert mode
1 participant