kyle-n / HighlightedTextEditor

A SwiftUI view for dynamically highlighting user input
MIT License
719 stars 68 forks source link

Respect the current formatting for new text entry #80

Open jbmorley opened 3 months ago

jbmorley commented 3 months ago

I've been seeing text jumping during typing after applying formatting with different font sizes. Reproducing this is a little fiddly, but seems to stem from the fact that the typing attributes don't reliably pick up the style from the underlying NSAttributedString.

This change explicitly sets the typing attributes to match the attributes at the insertion point, failing over to the default editor font if the editor is empty.

jbmorley commented 3 months ago

Here's the behavior I've been seeing (thanks to @gingerbeardman for the bug report and video):

https://github.com/kyle-n/HighlightedTextEditor/assets/220887/cf468c1a-01cb-4002-97af-668ba4ab5309