mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
ead352dd83
no issue - move all existing markdown editor behaviour out of the editor controller and isolate it into a single component that can be swapped out - split the `register/remove` functions of the `shortcuts-route` out into a separate `shortcuts` mixin
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
import Ember from 'ember';
|
|
import EditorAPI from 'ghost/mixins/ed-editor-api';
|
|
import EditorShortcuts from 'ghost/mixins/ed-editor-shortcuts';
|
|
import EditorScroll from 'ghost/mixins/ed-editor-scroll';
|
|
|
|
const {TextArea, run} = Ember;
|
|
|
|
export default TextArea.extend(EditorAPI, EditorShortcuts, EditorScroll, {
|
|
focus: false,
|
|
|
|
/**
|
|
* Tell the controller about focusIn events, will trigger an autosave on a new document
|
|
*/
|
|
focusIn() {
|
|
this.sendAction('onFocusIn');
|
|
},
|
|
|
|
/**
|
|
* Sets the focus of the textarea if needed
|
|
*/
|
|
setFocus() {
|
|
if (this.get('focus')) {
|
|
this.$().val(this.$().val()).focus();
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Sets up properties at render time
|
|
*/
|
|
didInsertElement() {
|
|
this._super(...arguments);
|
|
|
|
this.setFocus();
|
|
|
|
this.attrs.setEditor(this);
|
|
|
|
run.scheduleOnce('afterRender', this, this.afterRenderEvent);
|
|
},
|
|
|
|
afterRenderEvent() {
|
|
if (this.get('focus') && this.get('focusCursorAtEnd')) {
|
|
this.setSelection('end');
|
|
}
|
|
},
|
|
|
|
actions: {
|
|
toggleCopyHTMLModal(generatedHTML) {
|
|
this.attrs.toggleCopyHTMLModal(generatedHTML);
|
|
}
|
|
}
|
|
});
|