CodeEditApp / CodeEditSourceEditor

A code editor view written in Swift powered by tree-sitter.
https://codeeditapp.github.io/CodeEditSourceEditor/documentation/codeeditsourceeditor
MIT License
511 stars 78 forks source link

✨ Auto-indent New Lines #78

Closed austincondiff closed 1 year ago

austincondiff commented 1 year ago

When the user presses return to create a new line, we should auto-indent the new line for them.

The amount of indentation to give the new line will be based on the previous line's indentation, or if the previous line ends in a {, [, (, or <, increase the indent.

If there is a matching }, ], ), or >, we need to add it to a new line underneath the new line and indent it the same amount of indentation as the original line the user was on before they created the new line.

https://user-images.githubusercontent.com/806104/194420921-e340fb32-43b9-40ff-b05b-0c416c3e2cac.mp4

Related

mattmassicotte commented 1 year ago

Could be work a look:

https://github.com/ChimeHQ/TextFormation

Indentation calculation is incredibly complex in the general case. But that library can do some basics, and also be used in combination with a more sophisticated indentation calculation system.

lukepistrol commented 1 year ago

Could be implemented using https://github.com/ChimeHQ/TextFormation