Copying a rectangular block is quite simple. Enable column mode with Alt+C, select the block and execute copy with Ctrl+C.
Here is a little script which works for your example. You have to copy the rectangular block into the clipboard and position the cursor where you want to insert the block without spaces.
Note: The script is written to simply delete all spaces in the copied/pasted block, not just the spaces UltraEdit adds to really paste a block in column mode as most users need when working in column mode.
You are the first user requiring such a mixed mode copy/paste as far as I know. Of course you can change the script and write the strings in string array asInClipboard line by line at initial column position into the file (best in column mode) when you want to paste also columns with spaces. But that produces lots of undo steps while my solution produces only 2 undo steps. The strings in the clipboard do not contain the trailing spaces. So it is also possible to replace all spaces in the clipboard or the string array by a special character normally not used and after deleting all spaces with the replace all command use a second replace all command to replace this special character back to a space in the entire block. That would produce only 3 undo steps.
- Code: Select all
// This script should only do something if a file is open and the clipboard contains data.
if ((UltraEdit.document.length > 0) && (UltraEdit.clipboardContent.length > 0)) {
// Get the number of lines in the clipboard by splitting the string.
var asInClipboard = UltraEdit.clipboardContent.split("\r\n");
// But really needed is the array index of the last line.
var nLineCount = asInClipboard.length - 1;
// If the last line does not contain data, decrease line counter by 1.
// This is the case when in column mode a multi-line block was copied.
if (!asInClipboard[nLineCount].length) nLineCount--;
// Next look for the longest string in the strings list to get number of copied columns.
var nNumberOfColumns = 0;
for (var nIndex = 0; nIndex <= nLineCount; nIndex++)
{
if (asInClipboard[nIndex].length > nNumberOfColumns)
{
nNumberOfColumns = asInClipboard[nIndex].length;
}
}
// Get current line and column number.
var nLineNumber = UltraEdit.activeDocument.currentLineNum;
var nColumnNumber = UltraEdit.activeDocument.currentColumnNum;
if (typeof(UltraEdit.activeDocumentIdx) == "undefined") nColumnNumber++;
// Enable column mode and insert mode.
UltraEdit.insertMode();
UltraEdit.columnModeOn();
// Paste the data in the clipboard.
UltraEdit.activeDocument.paste();
// Reselect the just pasted block.
UltraEdit.activeDocument.gotoLineSelect(nLineNumber+nLineCount,nColumnNumber+nNumberOfColumns);
// Delete ALL spaces in this block and not only the trailing spaces.
UltraEdit.ueReOn();
UltraEdit.activeDocument.findReplace.mode=1;
UltraEdit.activeDocument.findReplace.matchCase=false;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=false;
UltraEdit.activeDocument.findReplace.searchAscii=false;
UltraEdit.activeDocument.findReplace.searchDown=true;
UltraEdit.activeDocument.findReplace.searchInColumn=false;
UltraEdit.activeDocument.findReplace.preserveCase=false;
UltraEdit.activeDocument.findReplace.replaceAll=true;
UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
UltraEdit.activeDocument.findReplace.replace(" ","");
UltraEdit.activeDocument.gotoLine(nLineNumber,nColumnNumber)
}