Adding Option+V shortcut in codemirror V6

I was trying to add shortcut for Option+V key in mac , but it is inserting some special character (ˇ) in the editor which is a default behaviour,
I tried overriding them by below snippets but none of them worked , the same shortcut used to work in codemirror v5 which I implemented by intercepting the event (Option+V) , and after that I fired undo to remove the inserted character and then do the required stuff. And here in V6 the functions associated with events are not getting fired.
Can someone please guide where I am doing wrong?
Method-1 (Adding custom keybinding)

{
        key: 'Alt-v',
        run: (view) => {
         
          // This does not fire on Option+V

          // need to do stuff here
          return false;
        },
        preventDefault: true,
      },

Method-2 ( doing action in keyup event)

        EditorView.domEventHandlers({
            keyup: (event: KeyboardEvent) => {
              funcsRef.current.onKeyUp?.(event);      // This does not fire on Option+V
            },
         })

Codemirror V5 implementation

editor.on('keyup', callback);
// here callback is my custom function where I handle the event
  if (event.code === 'KeyV' && matchModifierKeys(event, { alt: true })) {
     // do the stuff here
      }

The problem is event is not firing in both of the functions on pressing Option+V
Thanks in Advance

Key combinations that produce special characters are intentionally not handled as combinations in CodeMirror, because that would block inserting the character. I’d recommend not using Option combination on macOS, since most of those are, on at least some keyboard layouts, used to type stuff. If you really want to do this anyway, you could probably do it with a raw key event handler.

Ahh, Got it , I have a usecase for this since it was already implemented in Codemirror V5 , and I recently migrated to Codemirror V6
By using raw key event handler. would that not affect other codemirror keybindings which I already have implemented using , EditorView.domEventHandlers and custom keybindings using keymap.of?
Also by raw key event handler you mean to say adding event handling to dom element right? or you are talking about something else which is a part of codemirror event handling?

I meant handlers registered with domEventHandlers. Depending on the extension’s precedence relative to your keymaps, they would be handled either before or after regularly bound keys.

Thanks for reply @marijn , As I shared my implementation above for both the methods I am using Prec.highest() in both of them, but still I am facing the issue i.e. on pressing option+V , none of the handlers fire which is run in method 1 and keydown in method 2 , Am I missing something?

This seems to work for me.

My bad I typed keydown in my above reply , I meant keyup ,
Yeah , I checked for keydown it is working fine. But there is one more issue it is inserting the special character even after we are handling it and preventing default behaviour.
And it is not working for keyup. Reproducible here

Also I checked for some keys it is working like Option+D but for majority of them , it is not woking.

Hi @marijn did you have any chance to look into this?

keyup happens after the character has already been inserted. I don’t know why you insist on using that event, but if you must, you’ll have to figure out how to make it work yourself.