CodeEditApp / CodeEditSourceEditor

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

Highlight Ignored Indexes #114

Closed thecoolwinter closed 1 year ago

thecoolwinter commented 1 year ago

Description

Tracks indexes that were not given an explicit color and highlights them as normal text. This fixes problems where certain characters would change color (eg: they were put in a comment) and then need to change back, but were skipped.

This also fixes the problem in #99 where text was not given an explicit highlight on paste. Since STTextView does not add default attributes to pasted text by default (see the useTypingAttributes: false in that method call).

Doing this also seems to have an effect on the annoying glitching that was caused when entering text in an empty line (see the comment screen recording)

This PR also adds a helper for converting from an NSRange to a Range<Int> and gets rid of a bunch of ugly force unwraps that existed before. It also adds some convenience methods for modifying IndexSets using indexes from NSRange objects.

Related Issues

UI Fixes

Paste Text (Old)

https://user-images.githubusercontent.com/35942988/212186310-ee50dcaa-ebec-4e21-905b-562fc2cdf940.mov

Paste Text (new)

https://user-images.githubusercontent.com/35942988/212186342-402ceb89-2122-4431-88ac-2363e6452323.mov

Multi-Line comment (old)

https://user-images.githubusercontent.com/35942988/212186411-dc77744f-270b-4615-80c6-ed02e7c38e80.mov

Multi-Line comment (new)

https://user-images.githubusercontent.com/35942988/212186437-ba014944-fa6c-4de9-8ad3-c8105a655418.mov

Closes #99