From 94b570673e409d015e960e6bae2bc8cdcf0a553b Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Thu, 12 Apr 2018 12:03:52 +0200 Subject: [PATCH] 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 --- modules/ext.abuseFilter.edit.js | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/modules/ext.abuseFilter.edit.js b/modules/ext.abuseFilter.edit.js index fb6f35c75..43d67b5eb 100644 --- a/modules/ext.abuseFilter.edit.js +++ b/modules/ext.abuseFilter.edit.js @@ -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 {