You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for posting your RegexHighlightView! Really helpful.
I read your code, found your are using CoreText to display the stylized content, and make the textColor in UITextView clear to make sure it won't draw any text, so we can reuse UITextView's other behavior such as cursor, text selection.
But there is a problem(I think it should be a bug for CoreText): the linebreak mode in CoreText works a little different to UITextView. I think both CoreText and UITextView are using the same linebreak mode 'LineBreakByWordWrapping', but they define 'word' differently.
Please see the attached image for example.
So in some condition, the cursor seems 'off' the content. To resolve this issue, I think we have 3 approaches:
Extend the UITextView, leverage the attributedString related properties(Only works for iOS 6):
@Property(nonatomic) BOOL allowsEditingTextAttributes NS_AVAILABLE_IOS(6_0); // defaults to NO @Property(nonatomic,copy) NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0); // default is nil @Property(nonatomic,copy) NSDictionary *typingAttributes NS_AVAILABLE_IOS(6_0); // automatically resets when the selection changes
Extend the UIView, use CoreText to display the content, and add a subView to display the cursor and the selected range.
Set the linebreak mode to LineBreakByCharWrapping. However, the UITextView didn't expose any interfaces to allow us do that, we may have to use some private APIs.
The text was updated successfully, but these errors were encountered:
As I would like to use RegexHighlightView in my project as well and I just discovered the same issue, I'd like to ask if you could explain you possible solutions... I don't get what you mean with possibility one.
Has anybody found a proper solution that might already be working?
I've found exactly the same issue - the wrapping is different and so when a line breaks you have unpredictable results - any thoughts about how we could fix this?
Thanks for posting your
RegexHighlightView
! Really helpful.I read your code, found your are using CoreText to display the stylized content, and make the
textColor
inUITextView
clear to make sure it won't draw any text, so we can reuseUITextView
's other behavior such as cursor, text selection.But there is a problem(I think it should be a bug for CoreText): the linebreak mode in CoreText works a little different to UITextView. I think both CoreText and UITextView are using the same linebreak mode 'LineBreakByWordWrapping', but they define 'word' differently.
Please see the attached image for example.
So in some condition, the cursor seems 'off' the content. To resolve this issue, I think we have 3 approaches:
Extend the UITextView, leverage the attributedString related properties(Only works for iOS 6):
@Property(nonatomic) BOOL allowsEditingTextAttributes NS_AVAILABLE_IOS(6_0); // defaults to NO
@Property(nonatomic,copy) NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0); // default is nil
@Property(nonatomic,copy) NSDictionary *typingAttributes NS_AVAILABLE_IOS(6_0); // automatically resets when the selection changes
Extend the UIView, use CoreText to display the content, and add a subView to display the cursor and the selected range.
Set the linebreak mode to
LineBreakByCharWrapping
. However, the UITextView didn't expose any interfaces to allow us do that, we may have to use some private APIs.The text was updated successfully, but these errors were encountered: