Insert NBSP in DocumentEditor

Hi, 
I saw that NBSP (non breaking space) is working correctly in document editor when it's rendered from existing docx document (for exaple using "Open" document option).

But I didn't see possibility to insert it manually to the text -  shortcut ctrl+shift+space is not working same as in Word. 
Is there possibility to insert hard space?

1 Reply 1 reply marked as answer

GT Gunasekaran T Syncfusion Team April 19, 2021 12:30 PM UTC

Hi Cezary, 

At present our Document editor doesn’t insert non-breaking space on Ctrl + Shift + Space key. You can add custom logic to this key combination using keyDown event of our DocumentEditor component. We have prepared a custom example to achieve your requirement of inserting non-breaking space on Ctrl + Shift + Space key. Please find the example from below link. 

The following code can be added to the DocumentEditor/#created or DocumentEditorContainer/#created event for hooking the keyDown event and write custom logic. 
//Hooks the keyDown event for Document editor component to write custom logic. 
    this.container.documentEditor.keyDown = this.onKeyDown.bind(this); 

Please in the implementation of keyDown event handler. 
  onKeyDown(args: DocumentEditorKeyDownEventArgs): void { 
    let keyCode: number = args.event.which || args.event.keyCode; 
    let isCtrlKey: boolean = (args.event.ctrlKey || args.event.metaKey) ? true : ((keyCode === 17) ? true : false); 
    let isShiftKey: boolean = args.event.shiftKey ? args.event.shiftKey : ((keyCode === 16) ? true : false); 
 
    //Checks if the Ctrl, Shift and Space key are pressed. 
    if (isCtrlKey && isShiftKey && keyCode === 32) { 
      //Inserts a non-breaking space character at the cursor position 
      this.container.documentEditor.editor.insertText(String.fromCharCode(160)); 
      args.isHandled = true; 
   
 

Please let us know if you have any other questions. 

Regards, 
Gunasekaran

Marked as answer
Loader.
Up arrow icon