From a5d700807a35fc6ad97f7dfe51156f82dc91e6bf Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 13 Nov 2015 18:23:16 -0800 Subject: [PATCH] AceEditorWidget: Implement getRange Depends on I109a666679 in OOUI. Change-Id: Ie40a30a3743237c1c1cd59dd2165d313363e04cb --- .../ui/widgets/ve.ui.MWAceEditorWidget.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWAceEditorWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWAceEditorWidget.js index 5253e8670b..83449ca766 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWAceEditorWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWAceEditorWidget.js @@ -131,6 +131,40 @@ ve.ui.MWAceEditorWidget.prototype.setEditorValue = function ( value ) { } }; +/** + * @inheritdoc + */ +ve.ui.MWAceEditorWidget.prototype.getRange = function () { + var selection, range, lines, start, end, isBackwards; + + function posToOffset( row, col ) { + var r, offset = 0; + + for ( r = 0; r < row; r++ ) { + offset += lines[ r ].length; + offset++; // for the newline character + } + return offset + col; + } + + if ( this.editor ) { + lines = this.editor.getSession().getDocument().getAllLines(); + + selection = this.editor.getSelection(); + isBackwards = selection.isBackwards(); + range = selection.getRange(); + start = posToOffset( range.start.row, range.start.column ); + end = posToOffset( range.end.row, range.end.column ); + + return { + from: isBackwards ? end : start, + to: isBackwards ? start : end + }; + } else { + return ve.ui.MWAceEditorWidget.super.prototype.getRange.call( this ); + } +}; + /** * @inheritdoc */