I create a customize node using the ace editor as below:
HTML content
<div id="func-tabs-content" style="min-height: calc(100% - 95px);">
<div id="func-tab-body" style="display:none">
<div class="form-row" style="margin-bottom: 0px;">
<input type="hidden" id="node-input-func" autofocus="autofocus" />
<input type="hidden" id="node-input-noerr" />
</div>
<div class="form-row node-text-editor-row" style="position:relative">
<div style="position: absolute; right:0; bottom: calc(100% + 3px);">
<button id="node-function-expand-js" class="red-ui-button red-ui-button-small">
<i class="fa fa-expand"></i>
</button>
</div>
<div id="node-input-func-editor" style="height: 220px; min-height:120px; margin-top: 30px;" class="node-text-editor"></div>
</div>
</div>
</div>
and in oneditprepare() function
this.editor = RED.editor.createEditor({
id: "node-input-func-editor",
mode: "ace/mode/javascript",
value: "",
highlightActiveLine: true,
globals: {
console: false,
openContract: false,
},
esversion: 5,
asi: false,
});
return editor;
I write a custom command for the ace editor as below:
var keyBinding = function(editor) {
if (!editor.commands.commandKeyBinding["Ctrl-Shift-F"]) {
editor.commands.addCommand({
name: "formatPrettier",
bindKey: {
win: "Ctrl-Shift-F",
mac: "Command-Shift-F",
},
exec: function(editor) {
console.log('format src code');
},
readOnly: true,
});
}
};
keyBinding(this.editor);
It works well when the editor is in the normal state. But when the edit is expanded, my new command doesn't work even though the command list is still updated. My expand editor is written as follows:
var expandButtonClickHandler = function(editor) {
return function(e) {
e.preventDefault();
var value = editor.getValue();
RED.editor.editJavaScript({
value: value,
width: "Infinity",
cursor: editor.getCursorPosition(),
mode: "ace/mode/javascript",
complete: function(v, cursor) {
editor.setValue(v, -1);
editor.gotoLine(cursor.row + 1, cursor.column, false);
setTimeout(function() {
editor.focus();
}, 300);
},
globals: {
console: false,
openContract: false,
},
esversion: 5,
asi: false,
});
keyBinding(editor);
console.log(editor);
}
}
$("#node-function-expand-js").on(
"click",
expandButtonClickHandler(this.editor)
);
I check the editor variable after it expanded and its commands are still correct:
I don't know where I was wrong. Can you give me an idea to fix this? Thanks everyone for watching