javascripttypescriptcodemirrorace-editor

Changing the 'delete' function in ace editors Codemirror extension to perform additional checks


My current goal is to change the behaviour such that all vim commands that delete an entire line or several lines are only executed if certain conditions are met. This topic has helped me overwrite the delete function: Replacing the standard behaviour of the delete line hotkey "dd" in Ace editor's Vim mode with a function call But I have been unable to call the original implementation of the delete function from the function it was overwritten by so that it behaves as normal if the condition is not met.

import * as ace from 'ace-builds';
this.aceEditor = ace.edit(this.editor.nativeElement);
ace.require('ace/keybindings/vim');
this.aceEditor.setKeyboardHandler('ace/keyboard/vim');

ace.config.loadModule('ace/keyboard/vim', () => {
  var VimApi = ace.require('ace/keyboard/vim').CodeMirror.Vim;
  VimApi.defineOperator(
    'delete',
     this.deleteCurrentLineIfSolved.bind(this)
  );
});

deleteCurrentLineIfSolved(event, signal) {
    // if condition is met, call original implementation of delete here
    // else, do nothing
}

The delete function appears to be stored in some form of 'operators' array, github.com/ajaxorg/ace/blob/master/src/keyboard/vim.js#L3182 but I am not sure how to import or access it.

Any help would be much appreciated.


Solution

  • This functionality does not appear to exist, so I have implemented a function that returns the delete function in the /keyboard/vim.js file and used that successfully.