Column Mode Cut and Paste - UE makes up spaces

Column Mode Cut and Paste - UE makes up spaces

4
NewbieNewbie
4

    Sep 18, 2009#1

    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 :-)

    36
    Basic UserBasic User
    36

      Sep 18, 2009#2

      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.

      4
      NewbieNewbie
      4

        Sep 18, 2009#3

        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?

          Sep 18, 2009#4

          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>

          6,682583
          Grand MasterGrand Master
          6,682583

            Sep 18, 2009#5

            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();
               if (typeof(UltraEdit.columnModeOn) == "function") UltraEdit.columnModeOn();
               else if (typeof(UltraEdit.activeDocument.columnModeOn) == "function") UltraEdit.activeDocument.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)
            }
            Best regards from an UC/UE/UES for Windows user from Austria

            4
            NewbieNewbie
            4

              Sep 18, 2009#6

              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.