File indexing completed on 2024-05-19 04:00:08

0001 var katescript = {
0002     "author": "Alan Prescott",
0003     "license": "LGPL-2.0-or-later",
0004     "revision": 2,
0005     "kate-version": "5.1",
0006     "functions": ["jumpIndentUp", "jumpIndentDown"],
0007     "actions": [
0008         {   "function": "jumpIndentUp",
0009             "name": "Move Cursor to Previous Matching Indent",
0010             "shortcut": "Alt+Shift+Up",
0011             "category": "Navigation"
0012         },
0013         {   "function": "jumpIndentDown",
0014             "name": "Move Cursor to Next Matching Indent",
0015             "shortcut": "Alt+Shift+Down",
0016             "category": "Navigation"
0017         }
0018     ]
0019 }; // kate-script-header, must be at the start of the file without comments, pure json
0020 
0021 /**
0022  * Move cursor to next/previous line with an equal indent - especially useful
0023  * for moving around blocks of Python code.
0024  *
0025  * A first attempt at a kate script created by modifying the jump.js script
0026  * written by Dzikri Aziz.
0027  * I've been looking for this feature in an editor ever since I came across it
0028  * in an old MS-DOS editor called Edwin.
0029  */
0030 
0031 // required katepart js libraries
0032 require ("range.js");
0033 
0034 function jumpIndentDown() {
0035   return _jumpIndent();
0036 }
0037 
0038 function jumpIndentUp() {
0039   return _jumpIndent( true );
0040 }
0041 
0042 function help( cmd ) {
0043   if (cmd == 'jumpIndentUp') {
0044     return i18n("Move cursor to previous matching indent");
0045   }
0046   else if (cmd == 'jumpIndentDown') {
0047     return i18n("Move cursor to next matching indent");
0048   }
0049 }
0050 
0051 function _jumpIndent( up ) {
0052   var iniLine = view.cursorPosition().line,
0053       iniCol = view.cursorPosition().column,
0054       lines  = document.lines(),
0055       indent, target;
0056 
0057   indent = document.firstColumn(iniLine);
0058   target = iniLine;
0059 
0060   if ( up === true ) {
0061     if ( target > 0 ) {
0062       target--;
0063       while ( target > 0 && document.firstColumn(target) != indent ) {
0064         target--;
0065       }
0066     }
0067   }
0068 
0069   else {
0070     if ( target < lines ) {
0071       target++;
0072       while ( target < lines && document.firstColumn(target) != indent ) {
0073         target++;
0074       }
0075     }
0076   }
0077 
0078   view.setCursorPosition(target, iniCol);
0079 }