Override keyboard shortcuts CTRL + V

Hi,

I'm trying to override the paste shortcut by following the example https://ej2.syncfusion.com/documentation/document-editor/how-to/override-the-keyboard-shortcuts/

But it seems the arg.isHandled = true doesn't stop the paste action, so I get the paste action + my function

here is my code, Am I missing something?



regards,
François

2 Replies

HC Harini Chellappa Syncfusion Team March 2, 2020 06:57 AM UTC

Hi François, 

Syncfusion Greetings! 

We have called our paste function on paste event instead of keydown event. Hence args.ishandled doesn’t stop the paste action. 

You can call event.preventDefault() to stop triggering paste event. 

Please refer the below sample code snippet 

documentEditor.keyDown = function (args: DocumentEditorKeyDownEventArgs) { 
    let keyCode: number = args.event.which || args.event.keyCode; 
    let isCtrlKey: boolean = (args.event.ctrlKey || args.event.metaKey) ? true : ((keyCode === 17) ? true : false); 
    //67 is the character code for 'C' 
    if (isCtrlKey && keyCode === 67) { 
        //To prevent copy operation set isHandled to true 
        args.isHandled = true; 
        args.event.preventDefault();  
    } 
} 
 

Please try the above sample code snippet and let us know whether this helps you. 

Regards, 
Harini C 



FR François March 2, 2020 08:53 AM UTC

Hi Harini,

Wonderfull! It solved my problem! Thank's

regards,
François

Loader.
Up arrow icon