Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐞 Syntax highlights not applied to end of file #142

Closed
thecoolwinter opened this issue Feb 15, 2023 · 2 comments · Fixed by #173
Closed

🐞 Syntax highlights not applied to end of file #142

thecoolwinter opened this issue Feb 15, 2023 · 2 comments · Fixed by #173
Assignees
Labels
bug Something isn't working

Comments

@thecoolwinter
Copy link
Collaborator

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.

@thecoolwinter thecoolwinter added the bug Something isn't working label Feb 15, 2023
@thecoolwinter thecoolwinter moved this from 🆕 New to 📋 Todo in CodeEdit Project Feb 15, 2023
@austincondiff
Copy link
Collaborator

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.

@thecoolwinter
Copy link
Collaborator Author

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.

@austincondiff austincondiff moved this from 📋 Todo to 🏃‍♂️ In Progress in CodeEdit Project Mar 27, 2023
matthijseikelenboom pushed a commit that referenced this issue Apr 4, 2023
<!--- IMPORTANT: If this PR addresses multiple unrelated issues, it will
be closed until separated. -->

### Description

<!--- REQUIRED: Describe what changed in detail -->

This change adds all positive edits to the visible range. The assumption
is that any edits the user may make are going to be visible at some
point in time. If the cursor is not already on the page, it will be
scrolled to and if it extends beyond the viewport it will be scrolled to
be visible as well. In both of those cases the added range will be
overridden immediately due to the scroll. So this fixes the case where
characters are being inserted at the end of a file, but aren't being
scrolled to. This is apparent in the attached screen recordings.

Alternatives considered:
- **Re-calculating the visible set:** Decided against due to the extra
work that would need to be done potentially every keystroke to calculate
a new visible range.
- **Update the visible set only if the edit is actually visible:**
Decided against due to the reasons previously mentioned. Any edit will
eventually be included in the visible set if it is not already in it
when the edit occurs.

### Related Issues

<!--- REQUIRED: Tag all related issues (e.g. * #123) -->
<!--- If this PR resolves the issue please specify (e.g. * closes #123)
-->
<!--- If this PR addresses multiple issues, these issues must be related
to one other -->

* closes #142
* Maybe related to #162

### Checklist

<!--- Add things that are not yet implemented above -->

- [x] I read and understood the [contributing
guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md)
as well as the [code of
conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md)
- [x] The issues this PR addresses are related to each other
- [x] My changes generate no new warnings
- [x] My code builds and runs on my machine
- [x] My changes are all related to the related issue above
- [x] I documented my code

### Screenshots

Before fix. Edits applied to the end of the file are never sent to
tree-sitter for highlighting as they are out of the range of the visible
set. They are only updated when the document is scrolled and
`visibleSet` is recalculated.


https://user-images.githubusercontent.com/35942988/229874599-e2714b72-d51f-4748-89e1-b80ee51bddda.mov

After fix. Edits with positive deltas are always included in the
`visibleSet`.


https://user-images.githubusercontent.com/35942988/229875515-36e96921-71c0-48aa-a62c-75cbd91c52fb.mov


<!--- REQUIRED: if issue is UI related -->

<!--- IMPORTANT: Fill out all required fields. Otherwise we might close
this PR temporarily -->
@github-project-automation github-project-automation bot moved this from 🏃‍♂️ In Progress to 🏁 Complete in CodeEdit Project Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 🏁 Complete
Development

Successfully merging a pull request may close this issue.

2 participants