Pops up a dialogue box to ask you for a character number (position), validates it, then moves the cursor to the character at that position in the current document.
Useful for eg a SQL statement where you have an "error at character 3456"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | komodo.assertMacroVersion(2);
if (komodo.view && komodo.view.scintilla) { komodo.view.scintilla.focus(); }
// Get the editor object into a variable. It's used in the validator function.
var editor = ko.views.manager.currentView.scimoz;
var buffer_length = editor.length;
// Ask the user for the character position.
var response = ko.dialogs.prompt( 'Go to character', 'Enter character number', buffer_length, 'Go to character',
'mruName1', validate_new_pos, false );
// If they entered one, go to that position. We know it'll be valid because of the validator.
if ( response != null ) {
response = response.toString();
response = parseInt( response, 10 );
editor.gotoPos( response );
}
// Function to validate the entry. First, it must be an integer; then it must be between 0 and
// <length of buffer>. If it's invalid, tell the user why.
function validate_new_pos( p_unknown, p_value ) {
var ret_val = true;
if ( p_value != parseInt(p_value, 10 ).toString() ) {
ret_val = false;
} else {
l_value = parseInt(p_value, 10 );
if ( l_value < 0 || l_value > buffer_length ) {
ret_val = false;
}
}
if ( ! ret_val ) {
alert( 'You must enter an integer between 0 and ' + buffer_length );
}
return ret_val;
}
|