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

🐞 Syntax highlights not applied to end of file #142

Closed thecoolwinter closed 1 year ago

thecoolwinter commented 1 year ago

Description

When appending text to the end of a file the highlighter doesn't apply fonts. If you resize the window or scroll away it will apply the fonts. After some investigation it looks like the visibleSet isn't being updated with new characters, so new characters are being removed from any actionable sets when highlights are being applied.

An easy fix would be to recalculate the visible set every edit, but that would be quite inefficient. A possible solution may be to check whether an edit is being applied to the end of the visible set, and if it's exactly on the end extend the visible set.

To Reproduce

Expected behavior

Should apply fonts/colors to edits made at the end of the file.

Version information

CodeEditTextView: [main] macOS: [e.g. 13.2] Xcode: [e.g. 14.2]

Additional context

https://user-images.githubusercontent.com/35942988/218909123-aad56d20-c6e1-44f6-812c-7d729f75281f.mov

This video shows the issue. I deleted exactly 5 characters from the file (4 lines and a tab) before typing this. So the visible set originally included the class text. After that the visible set no longer contains the edited indices.

austincondiff commented 1 year ago

Can this be closed? Syntax highlights for me at the bottom of the file...

https://user-images.githubusercontent.com/806104/222918219-ef76ab36-44db-4cd3-8319-c4b2a5f0e6b7.mov

Although I see two more bugs here...

thecoolwinter commented 1 year ago

Those alignment issues are the highlighter not finding those characters and applying a style to them. I have a fix ready for this that I'll push asap.