javascript - ACE change key binding conditionnally -
javascript - ACE change key binding conditionnally -
if user presses down
key while custom popup displayed, down
event cancelled editor , handled manually. however, if popup disactivated, 'down' key should perform usual.
for that, wrote this:
editor.commands.addcommand({ name: 'nav_down.', bindkey: {win: 'down', mac: 'down'}, exec: function(editor) { if(mypopupisopen()) { // whatever want popup. homecoming false; } else { // leave key. homecoming true; } readonly: true });
unfortunately, can homecoming false
or true
, result same, capture downwards event, annoying. how can prevent that?
i tried following:
add key binding dom. after that, interaction happen (i.e. cannot capture it). return false or true suggested mutual events not work here.edit
the solution @a user works well. instead of above command, wrote:
var hashhandler = require("ace/keyboard/hash_handler").hashhandler; keyboardhandler = new hashhandler(); keyboardhandler.addcommand({ name: 'nav_down.', bindkey: {win: 'down', mac: 'down'}, exec: function(editor) { if(mypopupisopen()) { // whatever want popup. homecoming true; // alter here ! true when capture it. } else { // leave key. homecoming false; // alter here ! false when don't capture it. } readonly: true }); editor.keybinding.addkeyboardhandler(keyboardhandler);
in current version ace keeps 1 command each key addcommand phone call removes default binding down.
you can add together new keyboard handler similar autocompletion https://github.com/ajaxorg/ace/blob/v1.1.3/lib/ace/autocomplete.js#l221
var hashhandler = require("ace/keyboard/hash_handler").hashhandler; keyboardhandler = new hashhandler(); keyboardhandler.addcommand(/*add command homecoming false*/) editor.keybinding.addkeyboardhandler(keyboardhandler);
javascript command ace-editor
Comments
Post a Comment