File indexing completed on 2024-05-12 16:41:02
0001 // Replace a surrounding LaTeX font command with another font command, when the cursor is placed inside the texgroup. 0002 // Relative cursor position will not be changed. 0003 // 0004 // \textbf{abc} --> \textit{abc} 0005 0006 var fontCommands = new Array("\\textbf","\\textit","\\textsl","\\texttt","\\textsc","\\textrm","\\textsf","\\emph"); 0007 0008 var range = document.texgroupRange(false); 0009 //print( "range = " + range.toString() ); 0010 if ( range.isValid() ) { 0011 replaceFontCommand(range); 0012 } 0013 else { 0014 kile.alert.sorry("No surrounding TeX group found."); 0015 } 0016 0017 function replaceFontCommand(r) 0018 { 0019 var c = view.cursorPosition(); 0020 // print( "c = " + c.toString() ); 0021 0022 document.editBegin(); 0023 view.setCursorPosition(r.start); 0024 var cmd = document.latexCommand(); 0025 var index = fontCommands.indexOf(cmd); 0026 // print( "cmd = " + cmd); 0027 // print( "index = " + index); 0028 if ( index >= 0 ) { 0029 var cmdRange = document.latexCommandRange(); 0030 // print( "cmdRange = " + cmdRange.toString() ); 0031 if ( cmdRange.isValid() ) { 0032 var newcommand = kile.input.getListboxItem("Choose","Choose font command:",buildCmdList(cmd)); 0033 if ( newcommand != "" ) { 0034 document.replaceText(cmdRange,newcommand); 0035 c.column = c.column - (cmd.length - newcommand.length); 0036 } 0037 } 0038 // print( "c = " + c.toString() ); 0039 view.setCursorPosition(c); 0040 } 0041 else { 0042 kile.alert.sorry("No surrounding font command found."); 0043 } 0044 document.editEnd(); 0045 } 0046 0047 function buildCmdList(current) 0048 { 0049 var result = new Array(); 0050 //var commands = new Array("\\textbf","\\textit","\\texttt","\\emph"); 0051 for ( i=0; i<fontCommands.length; ++i ) { 0052 if ( fontCommands[i] != current ) { 0053 result.push(fontCommands[i]); 0054 } 0055 } 0056 return result; 0057 } 0058