Page 1 of 1
get text from multi selection
Posted: 10.10.2023 01:51
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 (2.05 KiB) Viewed 604 times
Re: get text from multi selection
Posted: 11.10.2023 17:04
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).
Re: get text from multi selection
Posted: 11.10.2023 17:08
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
Re: get text from multi selection
Posted: 12.10.2023 14:34
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?
Re: get text from multi selection
Posted: 13.10.2023 08:20
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.