Merge "Ace: use built-in function indexToPosition"

This commit is contained in:
jenkins-bot 2018-06-25 10:41:42 +00:00 committed by Gerrit Code Review
commit 40e7f440e6

View file

@ -53,31 +53,6 @@
.data( 'syntaxOk', syntaxOk );
}
/**
* Converts index (used in textareas) in position {row, column} for ace
*
* @author danyaPostfactum (https://github.com/ajaxorg/ace/issues/1162)
*
* @param {string} index Part of data returned from the AJAX request
* @return {Object} row and column
*/
function indexToPosition( index ) {
var lines = filterEditor.session.getDocument().$lines,
newLineChar = filterEditor.session.doc.getNewLineCharacter(),
currentIndex = 0,
row, length;
for ( row = 0; row < lines.length; row++ ) {
length = filterEditor.session.getLine( row ).length;
if ( currentIndex + length >= index ) {
return {
row: row,
column: index - currentIndex
};
}
currentIndex += length + newLineChar.length;
}
}
/**
* Switch between Ace Editor and classic textarea
*/
@ -120,7 +95,8 @@
if ( useAce ) {
filterEditor.focus();
position = indexToPosition( data.character );
// Convert index (used in textareas) in position {row, column} for ace
position = filterEditor.session.getDocument().indexToPosition( data.character );
filterEditor.navigateTo( position.row, position.column );
filterEditor.scrollToRow( position.row );
} else {