CodeEditApp/CodeEditSourceEditor

๐Ÿž Syntax highlights not applied to end of file

thecoolwinter opened this issue ยท 2 comments

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

  • Open a blank code file (or one you can see the bottom of without scrolling)
  • Type some code, you'll notice there's no fonts/colors being applied.

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

Screen.Recording.2023-02-14.at.8.07.12.PM.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.

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

Screen.Recording.2023-03-04.at.10.43.04.AM.mov

Although I see two more bugs here...

  • Scroll position does not follow cursor, so if I type new lines that are out of view, the scroll position does not adjust so that the cursor is in view.
  • There are some strange alignment issues.

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.