get text from multi selection

Post Reply
SamC
Posts: 207
Joined: 12.08.2023 00:49

get text from multi selection

Post by SamC »

Hello, when using ed.get_text_sel() to get column selection, it just return '2', is any other method to get the all text of multi-selection?
upadate:
I've read the wiki for CudaAPI, it just return first carset position.
And for multi selection, it seems we need to use get_carets() and get_text_substr() to get all the text?
20231010094917117.jpg
20231010094917117.jpg (2.05 KiB) Viewed 609 times
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Re: get text from multi selection

Post by main Alexey »

get_text_sel() gets selection of only 1st caret, while you have 3 carets.
> it seems we need to use get_carets() and get_text_substr() to get all the text?
yes, right.
note: when calling get_text_substr(), you must put SORTED coords:
>Returns substring from position (x1, y1) to bigger position (x2, y2).
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Re: get text from multi selection

Post by main Alexey »

how to get sorted coords for i-th caret

Code: Select all

        carets = ed.get_carets()
        x0, y0, x1, y1 = carets[i]
        if (y0, x0) >= (y1, x1): #note that y first
            x0, y0, x1, y1 = x1, y1, x0, y0
SamC
Posts: 207
Joined: 12.08.2023 00:49

Re: get text from multi selection

Post by SamC »

main Alexey wrote: 11.10.2023 17:08 how to get sorted coords for i-th caret

Code: Select all

        carets = ed.get_carets()
        x0, y0, x1, y1 = carets[i]
        if (y0, x0) >= (y1, x1): #note that y first
            x0, y0, x1, y1 = x1, y1, x0, y0
Thanks, I also find this in wiki page. I test it and find (y0, x0) >= (y1, x1) is always ture for the selection in one line(y0==y1)? When it will be false?
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Re: get text from multi selection

Post by main Alexey »

you have 2 cases: selection goes to the left, or it goes to the rigght. so x0 can be less or more than x1.
Post Reply