Page 3 of 3

Posted: 04.09.2021 12:14
by LuNik700
Thx Alexey. I'm anxious to see the optimizations you will make. To see what you'll change is a good way to learn ...

Best wishes to you and Kvichans
Ludger

Posted: 04.09.2021 12:21
by main Alexey
a) I will replace "for crt in carets" with "for (x, y, x1, y1) in carets". crt[0] with x, crt[1] with y.
b) I will remove from "carets" the carets placed on the same line, i.e. (not tested)

Code: Select all

for i in reversed(range(len(carets))):
  if (i>0) and (carets[i][1]==carets[i-1][1]):
    del carets[i]
c) we should disable the action if any carets has a selection.
d) we should change the carets to a new locations (even if some are deleted). ed.set_caret(...).

Posted: 04.09.2021 12:48
by LuNik700
main Alexey wrote:I see some places can/must be changed a little (we will change them, don;'t worry); I posted the request to @kvichans on Github.
I just looked at your request for Kvichans on Github...
>>> стоит удалить из списка carets каретки стоящие на одной строке (кроме самой правой)

You are absolutly right! This has to be changed, I didn't test that case :(
Align_by_caret21.png
Align_by_caret21.png (10.16 KiB) Viewed 2574 times
Align_by_caret22.png
Align_by_caret22.png (10.54 KiB) Viewed 2574 times

Posted: 06.09.2021 08:34
by LuNik700
Hi Alexey,
I think I fixed most of the things you mentioned. Please find the new source attached.

Especially the issue with more than one caret in a line is solved:
It has to be discussed which of carets have to be skipped - I prefer to skip all carets except the rightmost in a line but it would be a valid approach to process only the leftmost and skip all further carets to the right.
LuNik700 wrote:c) we should disable the action if any carets has a selection.
Up to now I didn't care about this ... To be honest at the moment I wouldn't know how to set multiple carets with one or more having a selection ...

I'm quite sure you'll find an optimization for the code but it really was fun to dive deeper into Python ...

Best regards
Ludger

Posted: 06.09.2021 14:04
by main Alexey
thanks. small notes:
>> #is it correct to set x ynd y to -1 when id=CARET_DELETE_ALL? It seems to work this way
I just added info about this to the API wiki (only in Github yet).
>> spaces = ""
for i in range(max_pos_x - x):
spaces += ' '
Shorter way is: spaces = ' ' * (max_pos_x - x)

How to check - do we have a selection -

Code: Select all

for (x, y, x1, y1) in crts:
  if y1>=0:
    return msg_status(_('This command cannot handle selection(s)'))

Posted: 06.09.2021 14:08
by main Alexey
del.

Posted: 06.09.2021 16:08
by LuNik700
main Alexey wrote: Shorter way is: spaces = ' ' * (max_pos_x - x)
I didn't know that there is an operator for String repetition in Python. Good to know. Changed it!

I included the check for selections.

What do you think does make more sense if there is more than one caret in a line: keep the rightmost and skip those more left or vice versa? I'm really not sure. Code for both alternatives is included now ...

Thx for your comments and support, Alexey!

Posted: 06.09.2021 17:28
by main Alexey
>keep the rightmost and skip those more left or vice versa?
Yes, keep the rightmost one.

Posted: 17.09.2021 19:44
by main Alexey
Patch is applied,
https://github.com/kvichans/cuda_ext/co ... f25df0d6de
Will be released soon.

Posted: 23.09.2021 16:59
by LuNik700
Thx!