Skip to content

Commit

Permalink
Fix code after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikBucher12 committed Feb 20, 2024
1 parent 95bc4b2 commit ee4919b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ extension RichTextCoordinator {
case .undoLatestChange:
textView.undoLatestChange()
syncContextWithTextView()
case .link(let url):
textView.setCurrentRichTextLink(url)
}
}
}
Expand Down
35 changes: 18 additions & 17 deletions Sources/RichTextKit/Coordinator/RichTextCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,25 @@ extension RichTextCoordinator {
let style = styles.hasStyle($0)
context.setStyleInternal($0, to: style)

// IMPORTANT:
// When we set custom RichTextAttributes, those are available only for parsing.
// That means when UITextView renders the attributed text, it automatically removes
// all undocumented attributes from itself and keeps only the documented ones
// (In customLinks case - `.link` and `.foregroundColor`
// This is probably hack because it intervenes with other links (mentions implementation in future)
if let linkString = textView.richTextAttributes[.link] as? String,
let color = textView.richTextAttributes[.foregroundColor] as? ColorRepresentable,
color == ColorRepresentable.green {
richTextContext.setLink(URL(string: linkString))
} else {
richTextContext.setLink(nil)
// TODO: Set attribute to nil
// textView.setRichTextAttribute(.richTextLink, to: nil)
// textView.setRichTextAttribute(.link, to: nil)
}
// IMPORTANT:
// When we set custom RichTextAttributes, those are available only for parsing.
// That means when UITextView renders the attributed text, it automatically removes
// all undocumented attributes from itself and keeps only the documented ones
// (In customLinks case - `.link` and `.foregroundColor`
// This is probably hack because it intervenes with other links (mentions implementation in future)
if let linkString = textView.richTextAttributes[.link] as? String,
let color = textView.richTextAttributes[.foregroundColor] as? ColorRepresentable,
color == ColorRepresentable.green {
richTextContext.setLink(URL(string: linkString))
} else {
richTextContext.setLink(nil)
// TODO: Set attribute to nil
// textView.setRichTextAttribute(.richTextLink, to: nil)
// textView.setRichTextAttribute(.link, to: nil)
}

updateTextViewAttributesIfNeeded()
updateTextViewAttributesIfNeeded()
}
}

/// Sync the text binding with the text view.
Expand Down

0 comments on commit ee4919b

Please sign in to comment.