Skip to content

Commit

Permalink
Fix strange attribute behaviour (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-divyesh-v authored Dec 4, 2024
1 parent c4cc566 commit 0675992
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Sources/RichEditorSwiftUI/BaseFoundation/RichTextCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ open class RichTextCoordinator: NSObject {
}

open func textViewDidChangeSelection(_ notification: Notification) {
replaceCurrentAttributesIfNeeded()
context.onTextViewEvent(
.didChangeSelection(
selectedRange: textView.selectedRange,
Expand Down Expand Up @@ -272,6 +273,19 @@ extension RichTextCoordinator {
if textView.hasSelectedRange { return }
let attributes = textView.richTextAttributes
textView.setRichTextAttributes(attributes)
#endif
}

/**
On macOS, we have to update the typingAttributes when we
move the text input cursor and there's no selected text.
So that the current attributes will set again for updated location.
*/
func replaceCurrentAttributesIfNeeded() {
#if macOS
if textView.hasSelectedRange { return }
let attributes = textView.richTextAttributes
textView.setNewRichTextAttributes(attributes)
#endif
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,11 @@ public extension RichTextViewComponent {
setRichTextAttribute(attribute, to: value)
}
}

func setNewRichTextAttributes(
_ attributes: RichTextAttributes
) {
typingAttributes = attributes
}
}

0 comments on commit 0675992

Please sign in to comment.