I am using monaco-editor, I would like to define that when user hits Enter key, it will apply only on certain condition.
Here is my code:
renderEditor(el: HTMLElement) {
this.editor = monaco.editor.create(el, {
...
...
});
this.editor.onKeyDown(this.keyDown);
}
keyDown(event: IKeyboardEvent): void {
if (event.code == 'ArrowDown') {
const shouldInsertNewLine = checkIfEnterShouldApplyOnEditorOrNot();
if(! shouldInsertNewLine){
// ?? code here to cancel the 'ArrowDown' hit ??
// (other action happens instead)
}
}
}
now if checkIfShouldMoveCursorOnEditorOrNot returns false, then arrowDown key should not apply on editor (cursor should not move to next line).
How can I achieve that?
I tried using event.preventDefault() but it doesn't work.