UX: Allow saving with cmd+s/ctrl+s with Ace editor (#12674)

When editing the files for a theme in the admin dashboard, typing "cmd+s" (a common key-binding to save in most text editors) used to engage the browser's default "save page" dialogue.

This commit adds a key-binding to the ace editor that saves the file.

Now, the "cmd+s" (and "ctrl+s" for windows) key-binding does the same action as the save button.
This commit is contained in:
Grayden 2021-05-04 07:56:10 -04:00 committed by GitHub
parent 338740c385
commit 61ad959212
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 3 deletions

View File

@ -105,6 +105,15 @@ export default Component.extend({
this.set("content", editor.getSession().getValue());
this._skipContentChangeEvent = false;
});
if (this.attrs.save) {
editor.commands.addCommand({
name: "save",
exec: () => {
this.attrs.save();
},
bindKey: { mac: "cmd-s", win: "ctrl-s" },
});
}
editor.$blockScrolling = Infinity;
editor.renderer.setScrollMargin(10, 10);

View File

@ -120,5 +120,9 @@ export default Component.extend({
onlyOverriddenChanged(value) {
this.onlyOverriddenChanged(value);
},
save() {
this.attrs.save();
},
},
});

View File

@ -50,5 +50,8 @@ export default Component.extend({
}
);
},
save() {
this.attrs.save();
},
},
});

View File

@ -87,4 +87,4 @@
<pre class="field-error">{{error}}</pre>
{{/if}}
{{ace-editor content=activeSection editorId=editorId mode=activeSectionMode autofocus="true" placeholder=placeholder htmlPlaceholder=true}}
{{ace-editor content=activeSection editorId=editorId mode=activeSectionMode autofocus="true" placeholder=placeholder htmlPlaceholder=true save=(action "save")}}

View File

@ -9,7 +9,7 @@
</div>
</div>
{{ace-editor content=editorContents mode=currentEditorMode editorId=editorId}}
{{ace-editor content=editorContents mode=currentEditorMode editorId=editorId save=(action "save")}}
<div class="admin-footer">
<div class="buttons">

View File

@ -1,4 +1,4 @@
{{email-styles-editor styles=model fieldName=fieldName}}
{{email-styles-editor styles=model fieldName=fieldName save=(action "save")}}
<div class="admin-footer">
<div class="buttons">

View File

@ -25,6 +25,7 @@
fieldAdded=(action "fieldAdded")
maximized=maximized
onlyOverriddenChanged=(action "onlyOverriddenChanged")
save=(action "save")
}}
<div class="admin-footer">