mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 00:30:44 +00:00
Merge "AceEditorWidget: Implement selectRange"
This commit is contained in:
commit
370a060ffc
|
@ -131,6 +131,46 @@ ve.ui.MWAceEditorWidget.prototype.setEditorValue = function ( value ) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWAceEditorWidget.prototype.selectRange = function ( from, to ) {
|
||||
var widget = this;
|
||||
this.loadingPromise.done( function () {
|
||||
var fromOffset, toOffset, selection, range,
|
||||
doc = widget.editor.getSession().getDocument(),
|
||||
lines = doc.getAllLines();
|
||||
|
||||
to = to || from;
|
||||
|
||||
function offsetToPos( offset ) {
|
||||
var row = 0,
|
||||
col = 0,
|
||||
pos = 0;
|
||||
|
||||
while ( row < lines.length && pos + lines[ row ].length < offset ) {
|
||||
pos += lines[ row ].length;
|
||||
pos++; // for the newline character
|
||||
row++;
|
||||
}
|
||||
col = offset - pos;
|
||||
return { row: row, column: col };
|
||||
}
|
||||
|
||||
fromOffset = offsetToPos( from );
|
||||
toOffset = offsetToPos( to );
|
||||
|
||||
selection = widget.editor.getSelection();
|
||||
range = selection.getRange();
|
||||
range.setStart( fromOffset.row, fromOffset.column );
|
||||
range.setEnd( toOffset.row, toOffset.column );
|
||||
selection.setSelectionRange( range );
|
||||
} ).fail( function () {
|
||||
ve.ui.MWAceEditorWidget.super.prototype.selectRange.call( widget, from, to );
|
||||
} );
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle change events from the Ace editor
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue