Skip to content

Commit

Permalink
feat(ui): onEndEditing.
Browse files Browse the repository at this point in the history
  • Loading branch information
laosb committed Feb 28, 2024
1 parent 877009a commit 0365b1c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Sources/EasyRichTextUI/ERTRichTextEditContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ERTRichTextEditContext<RichText: ERTRichText>: ObservableObject {
var nsAttributedString: NSMutableAttributedString
var defaultFont: CTFont
var onTextUpdated: ((NSAttributedString) -> ())?
public var onEndEditing: (() -> ())?

let italicSynthesizer: ERTItalicSynthesizer?
let attributedStringBridge: ERTAttributedStringBridge
Expand All @@ -51,10 +52,11 @@ public class ERTRichTextEditContext<RichText: ERTRichText>: ObservableObject {
}
}

func triggerRichTextUpdate() {
func endEditing() {
print("ERTRichTextEditContext triggerRichTextUpdate")
Task { @MainActor in
richText = .init(attributedString: attributedStringBridge.attributedString(for: normalizedNSAttributedString))
onEndEditing?()
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/EasyRichTextUI/ERTTextViewDelegate_AppKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ERTTextViewDelegate<RichText: ERTRichText>: NSObject, NSTextViewDel
}

public func textDidEndEditing(_ notification: Notification) {
context.triggerRichTextUpdate()
context.endEditing()
}

public func textDidChange(_ notification: Notification) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/EasyRichTextUI/ERTTextViewDelegate_UIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ERTTextViewDelegate<RichText: ERTRichText>: NSObject, UITextViewDel
}

public func textViewDidEndEditing(_ textView: UITextView) {
context.triggerRichTextUpdate()
context.endEditing()
}

public func textViewDidChange(_ textView: UITextView) {
Expand Down

0 comments on commit 0365b1c

Please sign in to comment.