Skip to content

Commit bf9b364

Browse files
committed
Fix removal of link
1 parent e67b12c commit bf9b364

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

Sources/RichEditorSwiftUI/BaseFoundation/RichTextCoordinator.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,34 +90,34 @@
9090
}
9191

9292
open func textViewDidChange(_ textView: UITextView) {
93-
syncWithTextView()
9493
context.onTextViewEvent(
9594
.didChange(
9695
selectedRange: textView.selectedRange,
9796
text: textView.attributedText
9897
)
9998
)
99+
syncWithTextView()
100100
}
101101

102102
open func textViewDidChangeSelection(_ textView: UITextView) {
103-
syncWithTextView()
104103
context.onTextViewEvent(
105104
.didChangeSelection(
106105
selectedRange: textView.selectedRange,
107106
text: textView.attributedText
108107
)
109108
)
109+
syncWithTextView()
110110
}
111111

112112
open func textViewDidEndEditing(_ textView: UITextView) {
113-
syncWithTextView()
114113
context.onTextViewEvent(
115114
.didEndEditing(
116115
selectedRange: textView.selectedRange,
117116
text: textView.attributedText
118117
)
119118
)
120119
context.isEditingText = false
120+
syncWithTextView()
121121
}
122122
#endif
123123

Sources/RichEditorSwiftUI/Data/Models/RichAttributes.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ extension RichAttributes {
201201
? (byAdding ? att.background! : nil) : self.background),
202202
align: (att.align != nil
203203
? (byAdding ? att.align! : nil) : self.align),
204-
link: (att.link != nil ? (byAdding ? att.link! : nil) : self.link)
204+
///nil link indicates removal as well so removing link if `byAdding == false && att.link == nil`
205+
link: (att.link != nil ? (byAdding ? att.link! : nil) : (att.link == nil && !byAdding) ? nil : self.link)
205206
)
206207
}
207208
}

Sources/RichEditorSwiftUI/UI/Context/RichEditorState+Link.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ extension RichEditorState {
1111
func insertLink(value: Bool) {
1212
if link != nil {
1313
alertController.showAlert(
14-
title: "Want to remove link", message: "It will remove link",
14+
title: "Remove link", message: "It will remove link from selected text",
1515
onOk: { [weak self] in
1616
guard let self else { return }
17-
self.updateStyle(style: .link(self.link))
17+
self.updateStyle(style: .link())
1818
},
1919
onCancel: {
2020
return

Sources/RichEditorSwiftUI/UI/Editor/RichEditorState+Spans.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ extension RichEditorState {
189189
addStyle = alignment != self.textAlignment || alignment != .left
190190
}
191191
case .link(let link):
192-
addStyle = self.link != link
192+
addStyle = link != nil
193193
default:
194194
return addStyle
195195
}

0 commit comments

Comments
 (0)