File indexing completed on 2024-05-12 16:41:02
0001 // Replace a surrounding TeX command with another, when the cursor is placed inside the texgroup. 0002 // Relative cursor position will not be changed. 0003 // 0004 // \texcommand{abc} --> \anothercommand{abc} 0005 0006 var range = document.texgroupRange(false); 0007 //print( "range = " + range.toString() ); 0008 if ( range.isValid() ) { 0009 var cmd = kile.input.getLatexCommand("Choose","Choose new LaTeX command:"); 0010 // print("cmd: "+ cmd); 0011 if ( cmd != "" ) { 0012 replaceTexCommand("\\"+cmd,range); 0013 } 0014 } 0015 else { 0016 kile.alert.sorry("No surrounding TeX group found."); 0017 } 0018 0019 function replaceTexCommand(newcommand,r) 0020 { 0021 var c = view.cursorPosition(); 0022 // print( "c = " + c.toString() ); 0023 0024 document.editBegin(); 0025 view.setCursorPosition(r.start); 0026 var cmd = document.latexCommand(); 0027 // print( "cmd = " + cmd); 0028 0029 var cmdRange = document.latexCommandRange(); 0030 // print( "cmdRange = " + cmdRange.toString() ); 0031 if ( cmdRange.isValid() ) { 0032 document.replaceText(cmdRange,newcommand); 0033 c.column = c.column - (cmd.length - newcommand.length); 0034 } 0035 // print( "c = " + c.toString() ); 0036 view.setCursorPosition(c); 0037 document.editEnd(); 0038 } 0039