Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Implement links (finally only links :D ) #143

Closed
wants to merge 4 commits into from

Conversation

DominikBucher12
Copy link
Collaborator

@DominikBucher12 DominikBucher12 commented Feb 13, 2024

  • WIP
  • WIP
  • WIP

We will have a nice call with @danielsaidi on how to polish this so we can merge this ASAP :) dont mind the formatting, this is still WIP

// 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,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use different method with sync.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, before approval :)

@danielsaidi
Copy link
Owner

@DominikBucher12 Is this ready for review?

@DominikBucher12
Copy link
Collaborator Author

I think you can review this, so we can merge it soon... But I would say finishing #154 and #146 before this is needed more I'd say :)

@@ -77,6 +77,8 @@ public enum RichTextAction: Identifiable, Equatable, RichTextLabelValue {

/// Undo the latest change.
case undoLatestChange

case link(url: URL?)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if we keep the alphabetical order for this enum and all switches over it.

@@ -158,6 +161,7 @@ public extension RichTextAction {
case .stepSuperscript(let steps): .actionStepSuperscript(steps)
case .toggleStyle(let style): style.titleKey
case .undoLatestChange: .actionUndoLatestChange
case .link: .actionCopy // TODO: Link
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this image before merging, just add a link image that uses the "link" symbol.

}

public struct CustomLinkAttributes {
init(link: String, color: ColorRepresentable) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call this RichTextLinkAttribute?

Also, what are the properties? Is link the url? If so, by renaming the type as suggested, we could use explicit naming and call this url or urlString.

/// This method takes the range, checks if there are any attributes for link and removes them.
/// After that, sets default typing attributes so we can continue writing as is.
/// Note if nothing is selected, we just set typing attributes so we can continue writing in normal pace
func unsetLinkFromCurrentRichTextStyle() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer use the current term for the component, so I think renaming this to removeLink would be enough.

}

/// Set the current value of a certain rich text style.
func setCurrentRichTextLink(_ link: URL?) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And rename this to addLink(to url: URL?)?

private var subscription: NSObjectProtocol!

#if macOS
func textViewDidChange(_ notification: Notification) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus, this is the exact same code twice.

@@ -53,6 +53,7 @@ public extension Image {
static let richTextStyleItalic = symbol("italic")
static let richTextStyleStrikethrough = symbol("strikethrough")
static let richTextStyleUnderline = symbol("underline")
static let richTextKindLink = symbol("link")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

richTextLink is enough :) Place this in alpha order and use it as instructed above 👍

@@ -183,6 +183,20 @@ open class RichTextView: UITextView, RichTextViewComponent {

// MARK: - Open Functionality

open func renderLinks(in characterRange: NSRange, at origin: CGPoint) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two are almost identical, but should be able to be identical as well, right? If so, can we instead extend the component protocol?

@@ -0,0 +1,53 @@
// PresentationContainer.swift
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding placement of the file, this is not a style so it should be elsewhere. Perhaps add a Presentation root folder?

@@ -41,6 +41,9 @@ public extension RichTextStyle {
self.styles = styles
}

@State private var urlString = ""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link button should not be part of the styles group.

@danielsaidi
Copy link
Owner

@DominikBucher12 I have reviewed the PR in its current state. It will be amazing to get link support, but this PR needs a bit more work before we can merge it.

@martindufort
Copy link
Contributor

What's the current status on having link support integrate into the main branch. Would love to use this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants