danielsaidi / RichTextKit

RichTextKit is a Swift SDK that helps you use rich text in Swift and SwiftUI.
MIT License
814 stars 97 forks source link

defining hashtag, links and adding hyperlinks #176

Open RomanKozlovskiy opened 1 month ago

RomanKozlovskiy commented 1 month ago

Good afternoon Please tell me, does the library have a function for determining hashtags and links, as well as adding hyperlinks? I tried to find information in the documentation but couldn't find anything.

danielsaidi commented 1 month ago

Hi @RomanKozlovskiy

@DominikBucher12 started implementing link support, but it's not yet merged.

RomanKozlovskiy commented 1 month ago

thank you very much for the information!

S1D1T1 commented 1 month ago

I am exploring an adjacent feature - where text is some sort of clickable token, like a hashtag. I expect it to be difficult. For starters, I would want to intercept a mouseclick.

DominikBucher12 commented 1 month ago

@S1D1T1 I have mebtions and hashtag locally running as well thats next feature that will be implemented

S1D1T1 commented 1 month ago

@DominikBucher12 I'd be interested to see that. My use isn't for hashtags or mentions, but for a scripting environment, where a variable name is a token. Similar to how variables are displayed in the Mac Shortcuts app- see attached graphic. the tokens should be "atomic" to the text editor - treated like a single character for purposes of cursor movement. I want to execute code when the token is clicked, to present a dialog with the token's properties.

image0

danielsaidi commented 1 month ago

That looks amazing! I'd love to use this library for snippet variables, but have no clue how to get started haha.

S1D1T1 commented 1 month ago

another UI model for handling a text token: address entry in Mail.app. You start out typing text, but when you complete a known address, it becomes an address object. it has a dropdown menu for managing its properties.

DominikBucher12 commented 1 month ago

With TextKit2 this is very possible and actually more easy, I need to merge that PR with textKit2 in order to add those more "complex" features. I will try to sít down and take a look at that this week so I can merge those 2 PRs that are there for months.

S1D1T1 commented 1 month ago

@DominikBucher12, to give a bigger picture, my app is a prompt authoring tool for AI image generation. It currently already supports syntax coloring, parentheses matching. My intention for variable tokens is to take the place of the clauses currently enclosed in { }. In the example below, I want to represent the first clause with a variable "#Genre" whose options can be set elsewhere. (My users have 100's of options to plug in there!)

When this script executes, it creates multiple image prompts, from the different combinations of these variable values, ie; "beautiful watercolor of sparkle and snow" "sharp photograph of sparkle and snow" .. etc..

Screenshot 2024-04-17 at 7 10 11 PM
S1D1T1 commented 1 month ago

@DominikBucher12 Can you tell me more about this change, and textkit 2? I would like to assess whether this will fit my needs. I'm not familiar with textkit2 - I see it's a new text editing library from Apple, but not in SwiftUI? At this point, just being able to intercept a mouse click or a .contextMenu would give me a starting point. I've also considered implementing my "tokens" as embedded Images, making use of RTK's RTF capabilities. That would handle all the cursor movement perfectly, since they're already treated like a single character, and flow with text. But it sounds like your potential change might be better. Feel free to direct me to unfinished products, I'm fine working with a prototype

martindufort commented 1 month ago

Looks like I would also have a need to do this and intercept taps / mouse clicks and apply functions to a link or an image attachment.

In my case, I would like to easily turn a line into a todo item, shown via an square image, by clicking a button. Then when the use clicks the image, the todo will be marked completed by swithching the image to a checkbox.square image.

What is needed to accomplish this in RTK?

danielsaidi commented 1 month ago

I'm a bit overwhelmed by the activity in this project, and would love be able to give it more time and attention. As of now, I however have to focus on some other project and freelance gigs, but can take a look at whatever you come up with.