Column Mode Cut and Paste - UE makes up spaces

Help with writing and running scripts

Column Mode Cut and Paste - UE makes up spaces

Postby qwibbles » Fri Sep 18, 2009 3:34 am

I have 2 data sets

Set 1
Code: Select all
HPWE0187.AverageWeight   102416   
HPWE0187.BatchName       102416   
HPWE0187.BatchNumber     4185+1236

And
Set 2
Code: Select all
HPWE0187.AverageWeight   28+
HPWE0187.BatchName       2918+     
HPWE0187.BatchNumber     44+

In column mode I expect to get the following when inserting before 102416 (as per other text editors like Notepad++ etc)

Code: Select all
HPWE0187.AverageWeight   28+102416   
HPWE0187.BatchName       2918+102416   
HPWE0187.BatchNumber     44+4185+1236

However when i paste UltraEdit 'makes up spaces' after the line ends and therefore I get

Code: Select all
HPWE0187.AverageWeight   28+  102416   
HPWE0187.BatchName       2918+102416   
HPWE0187.BatchNumber     44+  4185+1236

Is there an option to stop this annoying behaviour? I perform this type of editing alot, and having to switch back to using Notepad++ is a little annoying :-)
qwibbles
Newbie
 
Posts: 4
Joined: Fri Sep 18, 2009 3:24 am

Re: Column Mode Cut and Paste - UE makes up spaces

Postby danne » Fri Sep 18, 2009 7:41 am

Since you copy spaces when you select the column with 2918+, you also get them when you paste, which is what I would expect. Since the selection is a "box" and not "free-width-per-line". The length is equal to the longest line in the selection.
User avatar
danne
Basic User
Basic User
 
Posts: 36
Joined: Mon Feb 07, 2005 12:00 am

Re: Column Mode Cut and Paste - UE makes up spaces

Postby qwibbles » Fri Sep 18, 2009 8:02 am

But the spaces do not exist after the <CR><LF>. Ultraedit 'makes them up' to make a box. The normal behaviour in most editors is to copy until the end of a line. Then I could paste this information in correctly.

Is there any way to fix this?
qwibbles
Newbie
 
Posts: 4
Joined: Fri Sep 18, 2009 3:24 am

Re: Column Mode Cut and Paste - UE makes up spaces

Postby qwibbles » Fri Sep 18, 2009 9:18 am

Hi. Support have told me this is not possible currently.

Does anyone know how I could copy in block mode to the clipboard

Execute a macro to take the contents of the clipboard line by line and insert it while trimming off the extra spaces ... still adding the text in the correct place in a column?

Any pointers here would be appreciated <aka Newbie Alert>
qwibbles
Newbie
 
Posts: 4
Joined: Fri Sep 18, 2009 3:24 am

Re: Column Mode Cut and Paste - UE makes up spaces

Postby Mofi » Fri Sep 18, 2009 12:15 pm

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)
}
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Column Mode Cut and Paste - UE makes up spaces

Postby qwibbles » Fri Sep 18, 2009 2:37 pm

I just came back to post an update that I pasted in the block and then used the advanced Search and replace in column to remove the spaces.

Thankyou for the script. This assigned to a key saves me some time while editing.
qwibbles
Newbie
 
Posts: 4
Joined: Fri Sep 18, 2009 3:24 am


Return to Scripts