Fix hardtime changing mappings between modes - #195
Conversation
|
@m4xshen any updates on this? |
|
heyy @V1OL3TF0X sorry for the late reply. Could you please clarify what bug this PR is intended to fix? |
|
Sure thing! The bug was as follows: Steps to reproduce:
vim.keymap.set('n', 'J', function() vim.notify('Normal!') end)
vim.keymap.set('v', 'J', function() vim.notify('Visual!') end)
opts = {
restricted_keys = { J = { 'n', 'v' } },
}
Expected: "Visual!" (I hope that is a sane explenation of the bug, if not - lmk) |
|
Thanks, that's super clear and I can reproduce it! I'll take a look at your PR :) |
There was a problem hiding this comment.
When I call :Hardtime disable, h j k l keys stop working. I guess it's related to the changes here.
There was a problem hiding this comment.
The change was meant initially to not remove user mappings when disabling hardtime, I guess it went a little too far
I changed it to disable / enable not modifying mappings but early returning in handler - lmk if that's okay or should I try to preserve the current logic of modifying mappings.
The way I see it it can work in 3 ways:
- disable deletes the mapping if no user mapping existed and sets the mapping to original mapping if it did - that is the closest to the original approach
- disable overrides
handlerto early return - current implementation, simple but might have perf overhead - disable changes the handler to
get_return_key- the approach that was bugged, I think it was just missingreturnin the statements.
I see upsides and downsides of all of the approaches, so I'll go with whichever you find preferrable.
There was a problem hiding this comment.
@m4xshen after giving it some thought I decided to go with option one, it seems like it can cause the least side effects, especially when repeatedly toggling hardtime
I discovered it because I have those mappings:
I recently changed the last two from
and wanted to add them to hardtime - to my surprise, the functionality broke down.
After investigating I found that
mappingswhich hardtime uses gets only mappings from normal mode, in turn replacingvmapping withnmapping forJafter I enabled them in my hardtime config