Add autocomplete options to AceEditorWidget config options

Bug: T119549
Change-Id: I57db44c876c5cb0487bda6a72e36fedaccb532b5
This commit is contained in:
Thalia 2015-11-24 16:35:26 -08:00
parent 0e30e328ba
commit 3d98b1d291

View file

@ -24,11 +24,16 @@
*
* @constructor
* @param {Object} [config] Configuration options
* @cfg {string} [autocomplete='none'] Symbolic name of autocomplete
* mode: 'none', 'basic' (requires the user to press Ctrl-Space) or
* 'live' (shows a list of suggestions as the user types)
*/
ve.ui.MWAceEditorWidget = function VeUiMWAceEditorWidget( config ) {
// Configuration
config = config || {};
this.autocomplete = config.autocomplete || 'none';
this.$ace = $( '<div dir="ltr">' );
this.editor = null;
// Initialise to a rejected promise for the setValue call in the parent constructor
@ -98,7 +103,9 @@ ve.ui.MWAceEditorWidget.prototype.setupEditor = function () {
this.editor = ace.edit( this.$ace[ 0 ] );
this.editor.setOptions( {
minLines: this.minRows || 3,
maxLines: this.autosize ? this.maxRows : this.minRows || 3
maxLines: this.autosize ? this.maxRows : this.minRows || 3,
enableBasicAutocompletion: this.autocomplete !== 'none' ? true : false,
enableLiveAutocompletion: this.autocomplete === 'live' ? true : false
} );
this.editor.getSession().on( 'change', this.onEditorChange.bind( this ) );
this.editor.renderer.on( 'resize', this.onEditorResize.bind( this ) );
@ -106,6 +113,23 @@ ve.ui.MWAceEditorWidget.prototype.setupEditor = function () {
this.editor.resize();
};
/**
* Set the autocomplete property
*
* @param {string} mode Symbolic name of autocomplete mode
*/
ve.ui.MWAceEditorWidget.prototype.setAutocomplete = function ( mode ) {
var widget = this;
this.autocomplete = mode;
this.loadingPromise.done( function () {
widget.editor.renderer.setOptions( {
enableBasicAutocompletion: widget.autocomplete !== 'none' ? true : false,
enableLiveAutocompletion: widget.autocomplete === 'live' ? true : false
} );
} );
return this;
};
/**
* @inheritdoc
*/