Alexey-T / CudaText

Cross-platform text editor, written in Free Pascal
Mozilla Public License 2.0
2.51k stars 173 forks source link

How should auto_close_brackets work? #3219

Closed xcme closed 3 years ago

xcme commented 3 years ago

Type text and then put bracket ( directly in front of it and ) directly behind. You will get (text). Then put another pair of brackets () in the same way. You will get ((text) because the right ')' is ignored. The same behaviour is in Sublime. But why? I like autoclosing but find this approach a bit annoying. But true coders might be OK with that because they know something I don't know. Could anyone, please, explain?

Alexey-T commented 3 years ago

do you mean that typing (|(text) must give you ()(text) ? it doesnt do it, because auto-closing is blocked at that position (|(.

Alexey-T commented 3 years ago

and 'why it's blocked'-- code thinks that you type some complex code, it ignores ALL after current+next char ((.

xcme commented 3 years ago

No, I mean if my current state is (|text) where | means current cursor position and I press ( it gives me ((|text) as expected. But if my current state is (text|) and I press ) then editor ignores it and gives me (text)|

Alexey-T commented 3 years ago

that was made "like in other apps", ie auto-close-code checks next char, and if it's 'bad char' is don't auto-close. it's typing of (.

Alexey-T commented 3 years ago

on typing ) auto-close-code doesn't work.

Alexey-T commented 3 years ago

ah, typing ). yes - it skips chars depending on next char.

xcme commented 3 years ago

ah, typing ). yes - it skips chars depending on next char.

But is it the right way? If you have func1(val) and then decide to edit it to get func1(func2(val)) you go inside the brackets, put the caret before val and type func2(. Then you place the caret after val and type ) but nothing happens. To make it work you have to put the caret behind the bracket ) before closing it.

If you have something like func1(func2(val1), func3(val3, val2))) it's very easy to get confused here and lost one 'right' bracket. I see no reason to skip ) because in that way auto close works as auto ignore :) And I'm asking if anyone sees it.

Alexey-T commented 3 years ago

will think. BTW, other editors, how do they work (maybe VScode,Atom, EmEditor, Subl)?

xcme commented 3 years ago

Notepad++ doesn't skip right ), so I get ((test)). Auto-close works

Alexey-T commented 3 years ago

Made a fix! now if f(|) it skips the ), if f(text|) it do not skip.

xcme commented 3 years ago

But what do you personally think? Why ST skips right ) to? We can ask other guys for that @kvichans @JairoMartinezA @OlehL @tmsg-gh @halfbrained

Alexey-T commented 3 years ago

ST skips right ) maybe like Cud before-- they didnot get report about it

halfbrained commented 3 years ago

Maybe because if you are just typing f(arg).field, without skipping you will get an extra bracket f(arg).field)?

xcme commented 3 years ago

Maybe because if you are just typing f(arg).field, without skipping you will get an extra bracket f(arg).field)?

Hmm. Good point! But if you really type it that way you don't really need auto-completion then, do you?

halfbrained commented 3 years ago

Hmm. Good point! But if you really type it that way you don't really need auto-completion then, do you?

I do and I do :) (kisses himself) But still this 'smart behavior' hinders me more then helps :D so I'm quite happy with the change

Alexey-T commented 3 years ago

@xcme done in 1.128.5. is it working ok?

JairoMartinezA commented 3 years ago

Scenario:

1 - Select many carets as follow:

image

2 - Write (, CT just puts the pairs of brackets in the first position: image

xcme commented 3 years ago

@JairoMartinezA, yes but it isn't a new issue. Old versions have the same behaviour. It makes decision for the first line and then applies it for all the rest.

xcme commented 3 years ago

@Alexey-T now it's OK but can we also fix the issue above?

Alexey-T commented 3 years ago

Thanks for reporting, will try to fix

Alexey-T commented 3 years ago

@JairoMartinezA Pls post your user.json. I cannot repro this- I got ths Screenshot from 2021-03-09 22-17-32

did carets have selections? my picture- not.

Pls new issue.

xcme commented 3 years ago

@Alexey-T try put caret exactly as you see on the first screenshot. It depends on if the whitespace at left or at right.

Alexey-T commented 3 years ago

beta in http://uvviewsoft.com/c/

JairoMartinezA commented 3 years ago

Beta version is: image

Alexey-T commented 3 years ago

updated beta again. That's why Jairo's picture was, when carets 2...max didn't enter (. code found AT LEAST one caret which gave auto-close. if it was found, normal typing of '(' is blocked. not sure how to change logic here.

Alexey-T commented 3 years ago

OK,I fixed it. Jairo's picture case--solved now. Bt updated!

JairoMartinezA commented 3 years ago

The current way to deal with autocomplete is ok for me, when there are only trailing spaces, CT autocompletes with closing brackets, but when there is a mix of spaces and chars after carets ignore autocompletes. 👍

Alexey-T commented 3 years ago

current code makes pair () for all carets or nothing.

xcme commented 3 years ago

not sure how to change logic here.

Another idea:

As far I understand the goal of auto closing, it helps type CODE which could be performed quickly. On the other hand, multi-selection is needed for editing TEXT and is usually performed much slowly and accurate. So, it's OK to disable all busters for multi editing.

What do you think?

And another idea:

So, if all the lines have the same pattern then auto close works according user settings. If not, it should be disabled. If it's too difficult to analyze each line - just disable it with multi-selection (first idea here).

Alexey-T commented 3 years ago

Made a change, agree that auto-pair is not needed for mul-carets

Beta updated

xcme commented 3 years ago

Checked the behaviour in last beta an for me it looks good.

Alexey-T commented 3 years ago

Thanks for finding this. seems solved.