diff --git a/specifyweb/frontend/js_src/lib/appresources.js b/specifyweb/frontend/js_src/lib/appresources.js index 52887a0594c..3171673ec1d 100644 --- a/specifyweb/frontend/js_src/lib/appresources.js +++ b/specifyweb/frontend/js_src/lib/appresources.js @@ -37,6 +37,24 @@ function fileExtFor(resource) { return ""; } +// Copied from https://github.com/ajaxorg/ace/issues/3149#issuecomment-444570508 +function setCommandEnabled(editor, name, enabled) { + const command = editor.commands.byName[name]; + if (!command.bindKeyOriginal) + command.bindKeyOriginal = command.bindKey; + command.bindKey = enabled ? command.bindKeyOriginal : null; + editor.commands.addCommand(command); + // special case for backspace and delete which will be called from + // textarea if not handled by main commandb binding + if (!enabled) { + var key = command.bindKeyOriginal; + if (key && typeof key == "object") + key = key[editor.commands.platform]; + if (/backspace|delete/i.test(key)) + editor.commands.bindKey(key, "null") + } +} + const AppResourcePage = Backbone.View.extend({ __name__: "AppresourcePage", id: "appresource-page", @@ -144,6 +162,21 @@ const ResourceDataView = Backbone.View.extend({ editor.setValue(this.appresourceData.get('data')); editor.setPrintMarginColumn(null); editor.clearSelection(); + + editor.on('focus', ()=>{ + setCommandEnabled(editor, "indent", true); + setCommandEnabled(editor, "outdent", true); + }); + + editor.commands.addCommand({ + name: "escape", + bindKey: {win: "Esc", mac: "Esc"}, + exec() { + setCommandEnabled(editor, "indent", false); + setCommandEnabled(editor, "outdent", false); + } + }); + editor.on("change", () => { this.appresourceData.set('data', editor.getValue(), {changedBy: editor}); }); @@ -446,7 +479,7 @@ const DisciplineResourcesView = Backbone.View.extend({ type="button" class="fake-link" > - ${this.discipline.get('name')} + ${this.discipline.get('name')} (${this.count}) `)), $('