start and end line of a selection?

start and end line of a selection?

232
Basic UserBasic User
232

    Jun 04, 2023#1

    How can I actually determine the start and end line of a selection?
    I am a bit stumped

    greetings Frank
    (Translated with DeepL)
    Win11 (64bit) 23H2 - UE 2024.0.0.35 64bit

    6,687587
    Grand MasterGrand Master
    6,687587

      Jun 04, 2023#2

      The line and column number at beginning of a selection and at end of a selection cannot be easily determined as there are no UltraEdit document properties which hold the relevant numbers. There are also three different types of selections: selection in normal text edit mode, a rectangular selection in column editing mode, and a selection in hex edit mode. It makes also a difference if a selection is made from top left to bottom right (normal direction) or from bottom right to top left (reverse direction).

      I recommend to look on the code and especially the comments of the UltraEdit script file FindSelectInnerOuter.js with the two functions FindSelectInner and FindSelectOuter. There is written in the comments for a selection in normal text edit mode inside function FindSelectInner:
      • The line number as stored in UltraEdit document property currentLineNum is always the line number at beginning of the found and selected string independent on how this selection was made before and in which direction. So it is necessary to find out if end of found string is on same line or a different line below to determine the line number at end of found string.
      • The caret is at end of the found string and this position is also needed for the selection made later, except Perl regular expression engine is active and UE for Windows < v14.00 or UES < v6.50 executed the search. In this case the caret is at beginning of found string.
        The column number stored in the UltraEdit document property currentColumnNum is the column number at end of a selection which was made from top to bottom as usually done here. The column number at beginning of the selection is stored in property currentColumnNum for a selection made from bottom to top with caret blinking at beginning of selection.
        So the current column number is the column number at beginning of the selection to create later by this function with the exception as written above.
      There is a simple method to get the line and column number at beginning of a selection and at end of a selection if it is possible to temporarily modify the file with the selection. The selection is cut to one of the user clipboards resulting in caret being at beginning of the former selection and the UltraEdit document properties currentLineNum and currentColumnNum can be used now to get line and column number at beginning of the selection. Next the cut text is pasted back into the file resulting in caret being at end of the former selection and the properties currentLineNum and currentColumnNum can be used to to get line and column number at end of the former selection.

      The referenced script file uses different code to determine the beginning and end of the selection without temporarily modifying the file.

      Please note that horizontal tabs in file makes any calculation of column numbers incorrect without knowing which tab stop value is configured for the active file and without knowing how many horizontal tabs are in first line of a selection left to the beginning of the selection without moving around the caret temporarily in the file and determine the column numbers.
      Best regards from an UC/UE/UES for Windows user from Austria

      232
      Basic UserBasic User
      232

        Jun 04, 2023#3

        Hi Mofi,

        the tip with the cutting into the clipboard is indeed the easiest.

        I could actually have figured that out on my own. 
        You have really helped me

        greetings
        Frank
        (Translated with DeepL)
        Win11 (64bit) 23H2 - UE 2024.0.0.35 64bit