edit icon indicating copy to clipboard operation
edit copied to clipboard

handle logic to auto close and delete brackets

Open lunargon opened this issue 6 months ago • 5 comments

Handle Auto Close Parentheses, Braces, Brackets

To solved https://github.com/microsoft/edit/issues/488 I add logic to handle:

  • Auto close: If you type '(' or '[' or '{' with have auto close that and cursor will go between these.
  • Auto delete: For example: You have (|) ( this is parentheses with cursor between, if you delete - type BACK both open and close will be delele)

lunargon avatar Jun 20 '25 05:06 lunargon

@microsoft-github-policy-service agree

lunargon avatar Jun 20 '25 05:06 lunargon

Could this feature be made optional?

For me this is one of the most annoying features in other editors, frequently causing me to write things like [2]] or if (some_thing) { do_something(); } )}). And with the auto-delete it makes it even harder to prevent because when I then delete the closing bracket it also deletes the opening one. Another example is retro-actively adding a () around an existing condition.

Some more general remarks:

  • It leaks syntax of the language written into the editor itself.
  • There are cases were you just want a single opening bracket, for example in multi line comments or strings.

Consolatis avatar Jun 25 '25 04:06 Consolatis

@Consolatis You can try my ver first. Because delete only auto delete if between that is empty. For example:

  • [|] -> if your cursor is between and you type BACK button -> will auto delete both open and close
  • [some thing]| -> if your cursor is right close and you type BACK button -> you just delete close one.

My auto just delete with not thing between open and close. Can you check that first. If still annoy for you I will add some change to make that to optional or remove that feature.

lunargon avatar Jun 25 '25 04:06 lunargon

I'm not entirely sure about merging this logic just yet without having a settings model allowing users to turn this behavior off. I'll continue to let this PR sit for a while longer but try to keep it in the back of my mind.

lhecker avatar Aug 12 '25 11:08 lhecker

@lhecker If needed, I’ll update with the settings ( from project) later. I see that my PR is currently out of date with the main branch.

lunargon avatar Aug 15 '25 02:08 lunargon