codemirror-vim icon indicating copy to clipboard operation
codemirror-vim copied to clipboard

Motion maps from 'i' & 'a' causes 'ciw', 'caw', and others to fail

Open bytewife opened this issue 3 years ago • 1 comments

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 invariantMap that contains the a<character> and i<character> mappings
  • create a var userMap that contains the user-defined mappings
  • instead of accessing defaultKeymap directly throughout the code, we could replace it with a getCombinedKeymap() method that returns a map that union of the invariantMap, 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?

bytewife avatar Feb 20 '22 03:02 bytewife

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?

nightwing avatar Aug 15 '22 14:08 nightwing

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!

bytewife avatar Oct 09 '22 20:10 bytewife

@ivyraine What was the problem? I have a similar issue I usually solve with operator-pending bindings (omap)—can't do that here.

Acumane avatar Dec 31 '22 23:12 Acumane

@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?

nightwing avatar Mar 29 '23 00:03 nightwing