2015-10-21 15:30:57 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWAceEditorWidget class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2015-10-21 15:30:57 +00:00
|
|
|
*/
|
|
|
|
|
2016-03-14 14:15:10 +00:00
|
|
|
/* global ace */
|
2015-10-21 15:30:57 +00:00
|
|
|
|
|
|
|
/**
|
2015-10-30 16:19:25 +00:00
|
|
|
* Text input widget which use an Ace editor instance when available
|
|
|
|
*
|
|
|
|
* For the most part this can be treated just like a TextInputWidget with
|
|
|
|
* a few extra considerations:
|
|
|
|
*
|
|
|
|
* - For performance it is recommended to destroy the editor when
|
|
|
|
* you are finished with it, using #teardown. If you need to use
|
|
|
|
* the widget again let the editor can be restored with #setup.
|
|
|
|
* - After setting an initial value the undo stack can be reset
|
|
|
|
* using clearUndoStack so that you can't undo past the initial
|
|
|
|
* state.
|
2015-10-21 15:30:57 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.WhitespacePreservingTextInputWidget
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
2024-05-27 04:59:02 +00:00
|
|
|
* @param {string} [config.autocomplete='none'] Symbolic name of autocomplete
|
2015-11-25 00:35:26 +00:00
|
|
|
* mode: 'none', 'basic' (requires the user to press Ctrl-Space) or
|
|
|
|
* 'live' (shows a list of suggestions as the user types)
|
2024-05-27 04:59:02 +00:00
|
|
|
* @param {Array} [config.autocompleteWordList=null] List of words to
|
2017-01-11 21:20:09 +00:00
|
|
|
* autocomplete to
|
2015-10-21 15:30:57 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget = function VeUiMWAceEditorWidget( config ) {
|
|
|
|
// Configuration
|
|
|
|
config = config || {};
|
|
|
|
|
2015-11-25 00:35:26 +00:00
|
|
|
this.autocomplete = config.autocomplete || 'none';
|
2017-01-11 21:20:09 +00:00
|
|
|
this.autocompleteWordList = config.autocompleteWordList || null;
|
2015-11-25 00:35:26 +00:00
|
|
|
|
2018-02-19 15:41:20 +00:00
|
|
|
this.$ace = $( '<div>' ).attr( 'dir', 'ltr' );
|
2015-10-21 15:30:57 +00:00
|
|
|
this.editor = null;
|
|
|
|
// Initialise to a rejected promise for the setValue call in the parent constructor
|
2019-11-02 05:06:28 +00:00
|
|
|
this.loadingPromise = ve.createDeferred().reject().promise();
|
2015-10-21 15:30:57 +00:00
|
|
|
this.styleHeight = null;
|
|
|
|
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWAceEditorWidget.super.call( this, config );
|
|
|
|
|
|
|
|
// Clear the fake loading promise and setup properly
|
|
|
|
this.loadingPromise = null;
|
|
|
|
this.setup();
|
|
|
|
|
|
|
|
this.$element
|
|
|
|
.append( this.$ace )
|
|
|
|
.addClass( 've-ui-mwAceEditorWidget' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWAceEditorWidget, ve.ui.WhitespacePreservingTextInputWidget );
|
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The editor has resized
|
2020-06-02 20:30:00 +00:00
|
|
|
*
|
2024-04-29 11:52:40 +00:00
|
|
|
* @event ve.ui.MWAceEditorWidget#resize
|
2015-10-21 15:30:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the Ace editor instance
|
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.setup = function () {
|
|
|
|
if ( !this.loadingPromise ) {
|
2016-10-18 15:38:31 +00:00
|
|
|
this.loadingPromise = mw.loader.getState( 'ext.codeEditor.ace' ) ?
|
|
|
|
mw.loader.using( 'ext.codeEditor.ace' ) :
|
2019-11-02 05:06:28 +00:00
|
|
|
ve.createDeferred().reject().promise();
|
2015-11-19 07:11:10 +00:00
|
|
|
// Resolved promises will run synchronously, so ensure #setupEditor
|
|
|
|
// runs after this.loadingPromise is stored.
|
|
|
|
this.loadingPromise.done( this.setupEditor.bind( this ) );
|
2015-10-21 15:30:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the Ace editor instance
|
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.teardown = function () {
|
2024-04-30 16:44:25 +00:00
|
|
|
this.loadingPromise.done( () => {
|
2024-05-01 12:32:49 +00:00
|
|
|
this.$input.removeClass( 'oo-ui-element-hidden' );
|
|
|
|
this.editor.destroy();
|
|
|
|
this.editor = null;
|
2024-04-30 16:44:25 +00:00
|
|
|
} ).always( () => {
|
2024-05-01 12:32:49 +00:00
|
|
|
this.loadingPromise = null;
|
2015-10-21 15:30:57 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the Ace editor
|
2015-10-23 09:34:59 +00:00
|
|
|
*
|
2024-04-29 18:14:26 +00:00
|
|
|
* @fires ve.ui.MWAceEditorWidget#resize
|
2015-10-21 15:30:57 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.setupEditor = function () {
|
2024-05-21 14:22:56 +00:00
|
|
|
let basePath = mw.config.get( 'wgExtensionAssetsPath', '' );
|
2017-01-11 21:20:09 +00:00
|
|
|
|
2016-09-26 19:34:37 +00:00
|
|
|
if ( basePath.slice( 0, 2 ) === '//' ) {
|
2016-09-08 11:48:42 +00:00
|
|
|
// ACE uses web workers, which have importScripts, which don't like relative links.
|
|
|
|
basePath = window.location.protocol + basePath;
|
|
|
|
}
|
|
|
|
ace.config.set( 'basePath', basePath + '/CodeEditor/modules/ace' );
|
|
|
|
|
2015-10-21 15:30:57 +00:00
|
|
|
this.$input.addClass( 'oo-ui-element-hidden' );
|
|
|
|
this.editor = ace.edit( this.$ace[ 0 ] );
|
2016-03-26 21:46:36 +00:00
|
|
|
this.setMinRows( this.minRows );
|
2017-01-11 21:20:09 +00:00
|
|
|
|
|
|
|
// Autocompletion
|
2015-10-21 15:30:57 +00:00
|
|
|
this.editor.setOptions( {
|
2016-11-15 23:05:05 +00:00
|
|
|
enableBasicAutocompletion: this.autocomplete !== 'none',
|
|
|
|
enableLiveAutocompletion: this.autocomplete === 'live'
|
2015-10-21 15:30:57 +00:00
|
|
|
} );
|
2017-01-11 21:20:09 +00:00
|
|
|
if ( this.autocompleteWordList ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const completer = {
|
2024-05-01 12:32:49 +00:00
|
|
|
getCompletions: ( editor, session, pos, prefix, callback ) => {
|
2024-05-21 14:22:56 +00:00
|
|
|
const wordList = this.autocompleteWordList;
|
2024-04-30 16:44:25 +00:00
|
|
|
callback( null, wordList.map( ( word ) => ( {
|
|
|
|
caption: word,
|
|
|
|
value: word,
|
|
|
|
meta: 'static'
|
|
|
|
} ) ) );
|
2017-01-11 21:20:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
ace.require( 'ace/ext/language_tools' ).addCompleter( completer );
|
|
|
|
}
|
|
|
|
|
2015-10-21 15:30:57 +00:00
|
|
|
this.editor.getSession().on( 'change', this.onEditorChange.bind( this ) );
|
2015-10-23 09:34:59 +00:00
|
|
|
this.editor.renderer.on( 'resize', this.onEditorResize.bind( this ) );
|
2015-11-16 19:36:08 +00:00
|
|
|
this.setEditorValue( this.getValue() );
|
2022-03-18 22:30:54 +00:00
|
|
|
// Force resize (T303964)
|
2023-11-27 17:58:29 +00:00
|
|
|
// eslint-disable-next-line es-x/no-resizable-and-growable-arraybuffers
|
2022-03-18 22:30:54 +00:00
|
|
|
this.editor.resize( true );
|
2015-10-21 15:30:57 +00:00
|
|
|
};
|
|
|
|
|
2015-11-25 00:35:26 +00:00
|
|
|
/**
|
|
|
|
* Set the autocomplete property
|
|
|
|
*
|
|
|
|
* @param {string} mode Symbolic name of autocomplete mode
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {ve.ui.MWAceEditorWidget}
|
|
|
|
* @chainable
|
2015-11-25 00:35:26 +00:00
|
|
|
*/
|
2016-06-07 16:17:02 +00:00
|
|
|
ve.ui.MWAceEditorWidget.prototype.setAutocomplete = function ( mode ) {
|
2015-11-25 00:35:26 +00:00
|
|
|
this.autocomplete = mode;
|
2024-04-30 16:44:25 +00:00
|
|
|
this.loadingPromise.done( () => {
|
2024-05-01 12:32:49 +00:00
|
|
|
this.editor.renderer.setOptions( {
|
|
|
|
enableBasicAutocompletion: this.autocomplete !== 'none',
|
|
|
|
enableLiveAutocompletion: this.autocomplete === 'live'
|
2015-11-25 00:35:26 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
return this;
|
2016-06-07 16:17:02 +00:00
|
|
|
};
|
2015-11-25 00:35:26 +00:00
|
|
|
|
2015-10-21 15:30:57 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.setValue = function ( value ) {
|
2015-11-16 19:36:08 +00:00
|
|
|
// Always do something synchronously so that getValue can be used immediately.
|
|
|
|
// setEditorValue is called once when the loadingPromise resolves in setupEditor.
|
|
|
|
if ( this.loadingPromise.state() === 'resolved' ) {
|
|
|
|
this.setEditorValue( value );
|
|
|
|
} else {
|
|
|
|
ve.ui.MWAceEditorWidget.super.prototype.setValue.call( this, value );
|
|
|
|
}
|
2015-10-27 19:02:17 +00:00
|
|
|
return this;
|
2015-10-21 15:30:57 +00:00
|
|
|
};
|
|
|
|
|
2015-11-16 19:36:08 +00:00
|
|
|
/**
|
|
|
|
* Set the value of the Ace editor widget
|
|
|
|
*
|
2021-06-04 11:58:18 +00:00
|
|
|
* @param {string} value
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {ve.ui.MWAceEditorWidget}
|
|
|
|
* @chainable
|
2015-11-16 19:36:08 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.setEditorValue = function ( value ) {
|
|
|
|
if ( value !== this.editor.getValue() ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const selectionState = this.editor.session.selection.toJSON();
|
2015-11-16 19:36:08 +00:00
|
|
|
this.editor.setValue( value );
|
|
|
|
this.editor.session.selection.fromJSON( selectionState );
|
|
|
|
}
|
2019-04-16 15:17:29 +00:00
|
|
|
return this;
|
2015-11-16 19:36:08 +00:00
|
|
|
};
|
|
|
|
|
2015-12-20 12:40:08 +00:00
|
|
|
/**
|
|
|
|
* Set the minimum number of rows in the Ace editor widget
|
|
|
|
*
|
|
|
|
* @param {number} minRows The minimum number of rows
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {ve.ui.MWAceEditorWidget}
|
|
|
|
* @chainable
|
2015-12-20 12:40:08 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.setMinRows = function ( minRows ) {
|
2016-03-26 21:46:36 +00:00
|
|
|
this.minRows = minRows;
|
2024-04-30 16:44:25 +00:00
|
|
|
this.loadingPromise.done( () => {
|
2024-05-01 12:32:49 +00:00
|
|
|
this.editor.setOptions( {
|
|
|
|
minLines: this.minRows || 3,
|
|
|
|
maxLines: this.autosize ? this.maxRows : this.minRows || 3
|
2015-12-20 12:40:08 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
// TODO: Implement minRows setter for OO.ui.TextInputWidget
|
|
|
|
// and call it here in loadingPromise.fail
|
2019-04-16 15:17:29 +00:00
|
|
|
return this;
|
2015-12-20 12:40:08 +00:00
|
|
|
};
|
|
|
|
|
2019-02-08 19:18:22 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.setReadOnly = function ( readOnly ) {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWAceEditorWidget.super.prototype.setReadOnly.call( this, readOnly );
|
|
|
|
|
2024-04-30 16:44:25 +00:00
|
|
|
this.loadingPromise.done( () => {
|
2024-05-01 12:32:49 +00:00
|
|
|
this.editor.setReadOnly( this.isReadOnly() );
|
2019-02-08 19:18:22 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
this.$element.toggleClass( 've-ui-mwAceEditorWidget-readOnly', !!this.isReadOnly() );
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2015-11-14 02:23:16 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.getRange = function () {
|
2024-05-21 14:22:56 +00:00
|
|
|
let lines;
|
2015-11-14 02:23:16 +00:00
|
|
|
function posToOffset( row, col ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
let offset = 0;
|
2015-11-14 02:23:16 +00:00
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
for ( let r = 0; r < row; r++ ) {
|
2015-11-14 02:23:16 +00:00
|
|
|
offset += lines[ r ].length;
|
|
|
|
offset++; // for the newline character
|
|
|
|
}
|
|
|
|
return offset + col;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.editor ) {
|
|
|
|
lines = this.editor.getSession().getDocument().getAllLines();
|
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
const selection = this.editor.getSelection();
|
|
|
|
const isBackwards = selection.isBackwards();
|
|
|
|
const range = selection.getRange();
|
|
|
|
const start = posToOffset( range.start.row, range.start.column );
|
|
|
|
const end = posToOffset( range.end.row, range.end.column );
|
2015-11-14 02:23:16 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
from: isBackwards ? end : start,
|
|
|
|
to: isBackwards ? start : end
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return ve.ui.MWAceEditorWidget.super.prototype.getRange.call( this );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-14 01:48:42 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.selectRange = function ( from, to ) {
|
2015-11-19 03:14:50 +00:00
|
|
|
this.focus();
|
2024-04-30 16:44:25 +00:00
|
|
|
this.loadingPromise.done( () => {
|
2024-05-21 14:22:56 +00:00
|
|
|
const doc = this.editor.getSession().getDocument(),
|
2015-11-14 01:48:42 +00:00
|
|
|
lines = doc.getAllLines();
|
|
|
|
|
|
|
|
to = to || from;
|
|
|
|
|
|
|
|
function offsetToPos( offset ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
let row = 0,
|
2015-11-14 01:48:42 +00:00
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
while ( row < lines.length && pos + lines[ row ].length < offset ) {
|
|
|
|
pos += lines[ row ].length;
|
|
|
|
pos++; // for the newline character
|
|
|
|
row++;
|
|
|
|
}
|
2024-05-21 16:40:36 +00:00
|
|
|
const col = offset - pos;
|
2015-11-14 01:48:42 +00:00
|
|
|
return { row: row, column: col };
|
|
|
|
}
|
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
const fromOffset = offsetToPos( from );
|
|
|
|
const toOffset = offsetToPos( to );
|
2015-11-14 01:48:42 +00:00
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
const selection = this.editor.getSelection();
|
|
|
|
const range = selection.getRange();
|
2015-11-14 01:48:42 +00:00
|
|
|
range.setStart( fromOffset.row, fromOffset.column );
|
|
|
|
range.setEnd( toOffset.row, toOffset.column );
|
|
|
|
selection.setSelectionRange( range );
|
2024-04-30 16:44:25 +00:00
|
|
|
} ).fail( () => {
|
2024-05-01 12:32:49 +00:00
|
|
|
ve.ui.MWAceEditorWidget.super.prototype.selectRange.call( this, from, to );
|
2015-11-14 01:48:42 +00:00
|
|
|
} );
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2015-10-21 15:30:57 +00:00
|
|
|
/**
|
|
|
|
* Handle change events from the Ace editor
|
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.onEditorChange = function () {
|
|
|
|
// Call setValue on the parent to keep the value property in sync with the editor
|
|
|
|
ve.ui.MWAceEditorWidget.super.prototype.setValue.call( this, this.editor.getValue() );
|
|
|
|
};
|
|
|
|
|
2015-10-23 09:34:59 +00:00
|
|
|
/**
|
|
|
|
* Handle resize events from the Ace editor
|
|
|
|
*
|
2024-04-29 18:14:26 +00:00
|
|
|
* @fires ve.ui.MWAceEditorWidget#resize
|
2015-10-23 09:34:59 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.onEditorResize = function () {
|
2015-11-14 02:44:31 +00:00
|
|
|
// On the first setup the editor doesn't resize until the end of the cycle
|
|
|
|
setTimeout( this.emit.bind( this, 'resize' ) );
|
2015-10-23 09:34:59 +00:00
|
|
|
};
|
|
|
|
|
2015-10-30 16:19:25 +00:00
|
|
|
/**
|
|
|
|
* Clear the editor's undo stack
|
|
|
|
*
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {ve.ui.MWAceEditorWidget}
|
2015-10-30 16:19:25 +00:00
|
|
|
* @chainable
|
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.clearUndoStack = function () {
|
2024-04-30 16:44:25 +00:00
|
|
|
this.loadingPromise.done( () => {
|
2024-05-01 12:32:49 +00:00
|
|
|
this.editor.session.setUndoManager(
|
2015-10-30 16:19:25 +00:00
|
|
|
new ace.UndoManager()
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2015-10-21 15:30:57 +00:00
|
|
|
/**
|
|
|
|
* Toggle the visibility of line numbers
|
|
|
|
*
|
2021-06-04 11:58:18 +00:00
|
|
|
* @param {boolean} visible
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {ve.ui.MWAceEditorWidget}
|
2015-10-27 19:02:17 +00:00
|
|
|
* @chainable
|
2015-10-21 15:30:57 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.toggleLineNumbers = function ( visible ) {
|
2024-04-30 16:44:25 +00:00
|
|
|
this.loadingPromise.done( () => {
|
2024-05-01 12:32:49 +00:00
|
|
|
this.editor.setOption( 'showLineNumbers', visible );
|
2015-10-21 15:30:57 +00:00
|
|
|
} );
|
2015-10-27 19:02:17 +00:00
|
|
|
return this;
|
2015-10-21 15:30:57 +00:00
|
|
|
};
|
|
|
|
|
2015-11-18 21:38:41 +00:00
|
|
|
/**
|
|
|
|
* Toggle the visibility of the print margin
|
|
|
|
*
|
2021-06-04 11:58:18 +00:00
|
|
|
* @param {boolean} visible
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {ve.ui.MWAceEditorWidget}
|
2015-11-18 21:38:41 +00:00
|
|
|
* @chainable
|
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.togglePrintMargin = function ( visible ) {
|
2024-04-30 16:44:25 +00:00
|
|
|
this.loadingPromise.done( () => {
|
2024-05-01 12:32:49 +00:00
|
|
|
this.editor.renderer.setShowPrintMargin( visible );
|
2015-11-18 21:38:41 +00:00
|
|
|
} );
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2015-10-21 15:30:57 +00:00
|
|
|
/**
|
|
|
|
* Set the language mode of the editor (programming language)
|
|
|
|
*
|
|
|
|
* @param {string} lang Language
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {ve.ui.MWAceEditorWidget}
|
2015-10-27 19:02:17 +00:00
|
|
|
* @chainable
|
2015-10-21 15:30:57 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.setLanguage = function ( lang ) {
|
2024-04-30 16:44:25 +00:00
|
|
|
this.loadingPromise.done( () => {
|
|
|
|
ace.config.loadModule( 'ace/ext/modelist', ( modelist ) => {
|
2016-10-18 15:38:31 +00:00
|
|
|
if ( !modelist || !modelist.modesByName[ lang ] ) {
|
|
|
|
lang = 'text';
|
|
|
|
}
|
2024-05-01 12:32:49 +00:00
|
|
|
this.editor.getSession().setMode( 'ace/mode/' + lang );
|
2016-10-18 15:38:31 +00:00
|
|
|
} );
|
2015-10-21 15:30:57 +00:00
|
|
|
} );
|
2015-10-27 19:02:17 +00:00
|
|
|
return this;
|
2015-10-21 15:30:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Focus the editor
|
2015-11-18 20:03:17 +00:00
|
|
|
*
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {ve.ui.MWAceEditorWidget}
|
2015-11-18 20:03:17 +00:00
|
|
|
* @chainable
|
2015-10-21 15:30:57 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWAceEditorWidget.prototype.focus = function () {
|
2024-04-30 16:44:25 +00:00
|
|
|
this.loadingPromise.done( () => {
|
2024-05-01 12:32:49 +00:00
|
|
|
this.editor.focus();
|
2024-04-30 16:44:25 +00:00
|
|
|
} ).fail( () => {
|
2024-05-01 12:32:49 +00:00
|
|
|
ve.ui.MWAceEditorWidget.super.prototype.focus.call( this );
|
2015-10-21 15:30:57 +00:00
|
|
|
} );
|
2015-11-18 20:03:17 +00:00
|
|
|
return this;
|
2015-10-21 15:30:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
2022-02-14 15:18:57 +00:00
|
|
|
* @param {boolean} [force=false] Force a resize call on Ace editor
|
2015-10-21 15:30:57 +00:00
|
|
|
*/
|
2015-11-16 20:12:10 +00:00
|
|
|
ve.ui.MWAceEditorWidget.prototype.adjustSize = function ( force ) {
|
2015-10-23 09:34:59 +00:00
|
|
|
// If the editor has loaded, resize events are emitted from #onEditorResize
|
2015-11-16 20:12:10 +00:00
|
|
|
// so do nothing here unless this is a user triggered resize, otherwise call the parent method.
|
|
|
|
if ( force ) {
|
2024-04-30 16:44:25 +00:00
|
|
|
this.loadingPromise.done( () => {
|
2023-11-27 17:58:29 +00:00
|
|
|
// eslint-disable-next-line es-x/no-resizable-and-growable-arraybuffers
|
2024-05-01 12:32:49 +00:00
|
|
|
this.editor.resize();
|
2015-11-16 20:12:10 +00:00
|
|
|
} );
|
|
|
|
}
|
2024-04-30 16:44:25 +00:00
|
|
|
this.loadingPromise.fail( () => {
|
2015-10-23 09:34:59 +00:00
|
|
|
// Parent method
|
2024-05-01 12:32:49 +00:00
|
|
|
ve.ui.MWAceEditorWidget.super.prototype.adjustSize.call( this );
|
2015-10-21 15:30:57 +00:00
|
|
|
} );
|
2015-12-19 10:50:59 +00:00
|
|
|
return this;
|
2015-10-21 15:30:57 +00:00
|
|
|
};
|