Ace: use built-in function indexToPosition

I copied that function from github, but I realised that ace already
includes it, so no reason to have unnecessary function declarations.
Also, this fixes a minor bug that prevents the caret from moving to the
very last character when checking syntax.

Change-Id: Ia243b75803008b801dc24faaacbe7844618ccb45
This commit is contained in:
Daimona Eaytoy 2018-04-12 12:03:52 +02:00
parent 384c70ffc8
commit 94b570673e

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 {