mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 03:06:53 +08:00
FEATURE: auto focus text editor when editing themes
This commit is contained in:
@ -7,6 +7,13 @@ export default Ember.Component.extend({
|
|||||||
_editor: null,
|
_editor: null,
|
||||||
_skipContentChangeEvent: null,
|
_skipContentChangeEvent: null,
|
||||||
|
|
||||||
|
@observes('editorId')
|
||||||
|
editorIdChanged() {
|
||||||
|
if (this.get('autofocus')) {
|
||||||
|
this.send('focus');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
@observes('content')
|
@observes('content')
|
||||||
contentChanged() {
|
contentChanged() {
|
||||||
if (this._editor && !this._skipContentChangeEvent) {
|
if (this._editor && !this._skipContentChangeEvent) {
|
||||||
@ -63,7 +70,20 @@ export default Ember.Component.extend({
|
|||||||
// xxx: don't run during qunit tests
|
// xxx: don't run during qunit tests
|
||||||
this.appEvents.on('ace:resize', self, self.resize);
|
this.appEvents.on('ace:resize', self, self.resize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.get("autofocus")) {
|
||||||
|
this.send("focus");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
focus() {
|
||||||
|
if (this._editor) {
|
||||||
|
this._editor.focus();
|
||||||
|
this._editor.navigateFileEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -38,6 +38,11 @@ export default Ember.Controller.extend({
|
|||||||
return fieldName && fieldName.indexOf("scss") > -1 ? "scss" : "html";
|
return fieldName && fieldName.indexOf("scss") > -1 ? "scss" : "html";
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@computed("fieldName", "currentTargetName")
|
||||||
|
editorId(fieldName, currentTarget) {
|
||||||
|
return fieldName + "|" + currentTarget;
|
||||||
|
},
|
||||||
|
|
||||||
@computed("fieldName", "currentTargetName", "model")
|
@computed("fieldName", "currentTargetName", "model")
|
||||||
activeSection: {
|
activeSection: {
|
||||||
get(fieldName, target, model) {
|
get(fieldName, target, model) {
|
||||||
|
@ -17,7 +17,6 @@ export default Ember.Route.extend({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
setupController(controller, wrapper) {
|
setupController(controller, wrapper) {
|
||||||
controller.set("model", wrapper.model);
|
controller.set("model", wrapper.model);
|
||||||
controller.setTargetName(wrapper.target || "common");
|
controller.setTargetName(wrapper.target || "common");
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class='custom-ace-gutter'></div>
|
<div class='custom-ace-gutter'></div>
|
||||||
{{ace-editor content=activeSection mode=activeSectionMode}}
|
{{ace-editor content=activeSection editorId=editorId mode=activeSectionMode autofocus="true"}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class='admin-footer'>
|
<div class='admin-footer'>
|
||||||
|
Reference in New Issue
Block a user