How can I avoid pasting 2 line breaks instead of 1 with text copied with Citrix viewer to clipboard?

How can I avoid pasting 2 line breaks instead of 1 with text copied with Citrix viewer to clipboard?

5
NewbieNewbie
5

    Mar 05, 2019#1

    When I copy some text from other applications (e.g. connected to some Windows machine through Citrix) to UltraEdit for MAC, single line breaks are transformed to double line breaks.
    I see some configuration options in UltraEdit documentation, but I think that these options are not available in UltraEdit for MAC.
    Any idea to solve this?

    6,605548
    Grand MasterGrand Master
    6,605548

      Mar 05, 2019#2

      I suggest this script as workaround for this issue.

      Code: Select all

      if (UltraEdit.document.length > 0)  // Is any file opened?
      {
         // The column mode property is a property of the UltraEdit object in
         // UltraEdit for Windows and UEStudio, but a property of the document
         // object in UltraEdit for Linux and for Mac.
         var bColumnMode = false;
         if (typeof(UltraEdit.columnMode) == "boolean") bColumnMode = UltraEdit.columnMode;
         else if (typeof(UltraEdit.activeDocument.columnMode) == "boolean") bColumnMode = UltraEdit.activeDocument.columnMode;
      
         // Is neither column nor hex mode editing enabled?
         if (!bColumnMode && !UltraEdit.activeDocument.hexMode)
         {
            // Define line termination string according to line termination
            // used by active file with default being just line-feed (UNIX).
            var sLineTerm = "\n";
            if (typeof(UltraEdit.activeDocument.lineTerminator) == "number")
            {
               if (UltraEdit.activeDocument.lineTerminator < 1) sLineTerm = "\r\n";
               else if (UltraEdit.activeDocument.lineTerminator > 1) sLineTerm = "\r";
            }
            // Replace all carriage return + line-feed pairs or all line-feeds
            // or all carriage returns by the line termination of active file.
            UltraEdit.clipboardContent = UltraEdit.clipboardContent.replace(/\r\n|\n|\r/g,sLineTerm);
         }
         
         // Paste content of clipboard into the file.
         UltraEdit.activeDocument.paste();
      }
      
      I don't know if this script works at all with UltraEdit for Mac.
      Best regards from an UC/UE/UES for Windows user from Austria

      5
      NewbieNewbie
      5

        Mar 06, 2019#3

        Hi!

        Thank you for this script! It doesn't work exactly as you wrote it (I don't know why), but I use the script like this:

        Code: Select all

        if (UltraEdit.document.length > 0)  // Is any file opened?
        {
           var sLineTerm = "\n";
           // The column mode property is a property of the UltraEdit object in
           // UltraEdit for Windows and UEStudio, but a property of the document
           // object in UltraEdit for Linux and for Mac.
           var bColumnMode = false;
           if (typeof(UltraEdit.columnMode) == "boolean") bColumnMode = UltraEdit.columnMode;
           else if (typeof(UltraEdit.activeDocument.columnMode) == "boolean") bColumnMode = UltraEdit.activeDocument.columnMode;
        
           // Is neither column nor hex mode editing enabled?
           if (!bColumnMode  && !UltraEdit.activeDocument.hexMode)
           {
              // Define line termination string according to line termination
              // used by active file with default being just line-feed (UNIX).
              
              // if (typeof(UltraEdit.activeDocument.lineTerminator) == "number")
              // {
              //    if (UltraEdit.activeDocument.lineTerminator < 1) sLineTerm = "\r\n";
              //    else if (UltraEdit.activeDocument.lineTerminator > 1) sLineTerm = "\r";
              // }
              // Replace all carriage return + line-feed pairs or all line-feeds
              // or all carriage returns by the line termination of active file.
              UltraEdit.clipboardContent = UltraEdit.clipboardContent.replace(/\r\n|\n\n|\n|\r/g,sLineTerm);
           }
           UltraEdit.clipboardContent = UltraEdit.clipboardContent.replace(/\r\n|\n\n|\n|\r/g,sLineTerm);
           // Paste content of clipboard into the file.
           UltraEdit.activeDocument.paste();
        }
        Replace only works for me outside the IF question and I needed to add replacement for "\n\n" also.

        Its possible to add a new functionality to this script to trim trailing spaces in clipboard?

        Thanks!

        6,605548
        Grand MasterGrand Master
        6,605548

          Mar 06, 2019#4

          For removing trailing normal spaces and horizontal tabs from the lines in clipboard before pasting the clipboard content into the file replace in your script file

          Code: Select all

          UltraEdit.clipboardContent = UltraEdit.clipboardContent.replace(/\r\n|\n\n|\n|\r/g,sLineTerm);
          by

          Code: Select all

          UltraEdit.clipboardContent = UltraEdit.clipboardContent.replace(/[\t ]*(?:\r\n|\n\n|\n|\r)/g,sLineTerm);
          It is interesting to read that you need to replace \n\n in clipboard by just \n to get the clipboard content copied on a Windows machine via Citrix correct pasted into text file on Mac. This could mean that the software used to copy text in a Windows text file on a Windows machine into Windows clipboard and next transmit the Windows clipboard content to Mac and copy it to clipboard of Mac replaces wrong all \r by \n instead of all \r\n by just \n. That is simply a wrong DOS/Windows to UNIX (and new MAC) line ending conversion done by this software. In this case the feature controlled in UltraEdit for Windows with configuration setting On paste convert line endings to destination type (Unix/Mac/DOS) would be of no help on Mac as \n\n must be interpreted by any text editor on Mac as two line terminations.

          The clipboard content is pasted into a file in UltraEdit always without any modification byte-by-byte on pasting the clipboard content in hex edit mode. Please would you open a new file, insert a space, switch to hex edit mode showing now only 20 at top and paste the clipboard content into the file.

          Are there really 0A 0A (or UTF-16 encoded 0A 00 0A 00) instead of OD 0A (or UTF-16 encoded 0D 00 0A 00) for each line termination in pasted byte stream?

          Please note: You should not have the replace two times in the script. The clipboard content should not be modified on pasting clipboard content into a file opened in hex editing mode as in this case it is possible to paste also binary data into a file. A modification of the clipboard content with the replace function before paste would damage the binary data. It is also not recommended to modify clipboard content on pasting it into a text file with column mode editing currently enabled. This could result on wrong pasting behavior in column mode. The second clipboard content replace outside the IF condition should be removed for these reasons.
          Best regards from an UC/UE/UES for Windows user from Austria

          5
          NewbieNewbie
          5

            Mar 06, 2019#5

            Hi,

            If I paste in hex mode, I can see double "0D" :-O
            If I only put replace command inside IF block, paste does not work ... and now I know why.

            This is my script now.

            Code: Select all

            if (UltraEdit.document.length > 0)  // Is any file opened?
            {
               var sLineTerm = "\n";
               // The column mode property is a property of the UltraEdit object in
               // UltraEdit for Windows and UEStudio, but a property of the document
               // object in UltraEdit for Linux and for Mac.
               var bColumnMode = false;
               if (typeof(UltraEdit.columnMode) == "boolean") bColumnMode = UltraEdit.columnMode;
               else if (typeof(UltraEdit.activeDocument.columnMode) == "boolean") bColumnMode = UltraEdit.activeDocument.columnMode;
            
               // Is neither column nor hex mode editing enabled?
               if (!UltraEdit.columnMode && !UltraEdit.activeDocument.hexMode)
               {
                  UltraEdit.clipboardContent = UltraEdit.clipboardContent.replace(/[\t ]*(?:\r\n|\r\r|\n|\r)/g,sLineTerm);
               }
               // Paste content of clipboard into the file.
               UltraEdit.activeDocument.paste();
            }
            I replace double "0D" with a "0A". I will only use this "paste" when I need it. (I assign to "Ctrl+V", like Windows style.) Otherwise I will use normal "paste" for MAC (Command-V).

            Thanks!
            hex-paste.png (244.13KiB)

            6,605548
            Grand MasterGrand Master
            6,605548

              Mar 06, 2019#6

              Wow, that is really strange. I have never seen before an application which transfers data from one machine to another machine with replacing \r\n by \r\r. Standard is \r\n replaced by \n and \n replaced by \r\n. I have often seen the issue on which a user configured for FTP the ASCII transfer mode and the text files on server contain \r\n instead of just \n resulting after download in local text files containing \r\r\n. But a replacement of \r\n by \r\r on text transfer is really new for me.

              It looks like the used software interprets your Mac as a Mac running OS 9 or an even earlier OS version as in this case I would partly understand why all \n are replaced by \r on text transfer. There is perhaps a preferences setting to configure how line endings should be converted on text transfer from remote machine to local machine.

              I suggest to remove from regular expression |\n because it does not make sense to replace each line-feed by a line-feed. But it is fine that this special issue could be solved with the small script executed only when needed.
              Best regards from an UC/UE/UES for Windows user from Austria

              5
              NewbieNewbie
              5

                Mar 06, 2019#7

                It seems a Citrix Viewer bug....
                https://discussions.citrix.com/topic/40 ... ank-lines/

                It's similar, but maybe not the same issue.... I wait for the next release of Citrix Viewer.

                  Mar 29, 2019#8

                  Hi, new Citrix Viewer version has solved this issue! :-)
                  This new version is: Citrix Viewer 19.3.0.21 (1903)

                  Workaround is not longer necessary. Thank you very much for your help.