Motion maps from 'i' & 'a' causes 'ciw', 'caw', and others to fail
Hello,
I'm unable to run commands using the motions 'iw' & 'aw' after using the following remaps:
noremap i h
noremap a j
This deviates from Vim behavior since Vim allows iw & aw to be used to manipulate words as expected from ciw daw yaw etc
After doing some code skimming, I believe the issue stems from the following items in the map getting out-prioritized whenever a motion map using 'i' or 'a' as the target keys is created using mapCommand():
{ keys: 'a<character>', type: 'motion', motion: 'textObjectManipulation' },
{ keys: 'i<character>', type: 'motion', motion: 'textObjectManipulation', motionArgs: { textObjectInner: true }},
This is because _mapCommand() method writes user-defined maps to the beginning of the defaultKeymap using .unshift()
I'm thinking the issue would be resolved by ensuring that these a<character> and i<character> commands don't lose priority. This can be accomplished is by keeping these items at the front of map.
Here's a possible solution:
- create a
var invariantMapthat contains thea<character>andi<character>mappings - create a
var userMapthat contains the user-defined mappings - instead of accessing
defaultKeymapdirectly throughout the code, we could replace it with agetCombinedKeymap()method that returns a map that union of theinvariantMap,userMap, and thedefaultKeymap(respecting that order for priority). This way, the invariant mappings remains prioritized over the user-defined mappings, and the user-defined mappings remains prioritized over the default mappings.
Would this strategy make sense?
Running :noremap i h in vim 8.2.8 produces the same result as in codemirror-vim. Maybe there is some other option in vim that needs to be turned on to allow to resolve the conflict between i and ia?
I believe I made a mistake on my end. I don't run into the issue any more. If anyone runs into this issue again re-open this one!
@ivyraine What was the problem? I have a similar issue I usually solve with operator-pending bindings (omap)—can't do that here.
@Acumane https://github.com/replit/codemirror-vim/pull/97 implements omap, could you please check on https://raw.githack.com/replit/codemirror-vim/omap/dev/web-demo.html if it works as expected?