How to get the line above the selected block from within a script?

How to get the line above the selected block from within a script?

1
NewbieNewbie
1

    Jun 11, 2014#1

    I have created script to populate an array based on the the activeDocument.selection. What I would like to do is include the previous line as part of the array as well. I'm not familiar of how to get the offset or previous line to the selection.

    Code: Select all

    Line#   Text
       1       This is the first line
       2       This is the second line                 //This is the activeDocument.selection
    Example:

    Code: Select all

    myArray[x]= UltraEdit.activeDocument.selection     //This line works
    
         Result = This is the second line
    What I would like to achieve:

    Code: Select all

    myArray[x]= UltraEdit.activeDocument.selection + "," + UltraEdit.activeDocument.selection.previousline   
    
        Result = This is the second line,This is the first line
    Regards,
    John

    6,686585
    Grand MasterGrand Master
    6,686585

      Jun 13, 2014#2

      UltraEdit.activeDocument.currentLineNum contains the number of the line at which the selection begins in UE v21.10.0.1032 independent on where the caret is currently blinking in the file, at bottom right edge of the selection as usual or at top left edge of the selection with making the selecting from bottom right to top left (reverse direction).

      Therefore this little code should produce what you want in normal text editing mode (column mode not enabled).

      Code: Select all

      if (UltraEdit.document.length > 0)  // Is any file opened?
      {
         // Is anything selected in active file?
         if (UltraEdit.activeDocument.isSel())
         {
            // Get number of the line on which the selection begins.
            var nLine = UltraEdit.activeDocument.currentLineNum;
            // Get the selected block into a string variable.
            var sText = UltraEdit.activeDocument.selection;
            // Does the selection not start at top of the file?
            if (nLine > 1)
            {
               // Move caret to line above the beginning of the selection.
               UltraEdit.activeDocument.gotoLine(--nLine,1);
               // Select this line with the line termination.
               UltraEdit.activeDocument.selectLine();
               // Append a comma and this line to previously selected text.
               sText += "," + UltraEdit.activeDocument.selection;
            }
         }
      }
      
      Best regards from an UC/UE/UES for Windows user from Austria