mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeEditor
synced 2024-11-23 14:56:43 +00:00
Follow-up Ie3ed681b: Unstub getCaretPosition() as well
It was pointed out in the review of Ie3ed681b that the naive fallback for replaceSelection() was not working because CodeEditor only had a stub getCaretPosition() implementation. So, let's implement that as well in case people want to use it. It seems to work reasonably well locally with the native replaceSelection() disabled. Bug: T342127 Change-Id: I8d3683808394faefa56c7cdff31dc18978c4dd92
This commit is contained in:
parent
2f7ce4dd50
commit
a6030db858
|
@ -781,9 +781,24 @@
|
|||
/**
|
||||
* Gets the position (in resolution of bytes not nessecarily characters) in a textarea
|
||||
* DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Object} [options.startAndEnd=false] Return range of the selection rather than just start
|
||||
* @return {number|number[]} If options.startAndEnd is true, returns an array holding the start and
|
||||
* end of the selection, else returns only the start of the selection as a single number.
|
||||
*/
|
||||
getCaretPosition: function () {
|
||||
mw.log( 'codeEditor stub function getCaretPosition called' );
|
||||
getCaretPosition: function ( options ) {
|
||||
var selection = context.codeEditor.getSelection(),
|
||||
range = selection.getRange(),
|
||||
doc = context.codeEditor.getSession().getDocument(),
|
||||
startOffset = doc.positionToIndex( range.start );
|
||||
|
||||
if ( options.startAndEnd ) {
|
||||
var endOffset = doc.positionToIndex( range.end );
|
||||
return [ startOffset, endOffset ];
|
||||
}
|
||||
|
||||
return startOffset;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue