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

How to get attributed string (Highlight) #18

Open
user723 opened this issue May 10, 2021 · 10 comments
Open

How to get attributed string (Highlight) #18

user723 opened this issue May 10, 2021 · 10 comments
Labels
question Further information is requested

Comments

@user723
Copy link

user723 commented May 10, 2021

I can get the string with editorView.getSelectedText, but how can I get attributed string( if it's bold, italic, etc.) ?

@Andrew-Chen-Wang
Copy link
Owner

Does getSelectedHref work?

@Andrew-Chen-Wang Andrew-Chen-Wang added the question Further information is requested label May 10, 2021
@user723
Copy link
Author

user723 commented May 11, 2021

I don't use any url in my project, that's why I didnt check.

@user723
Copy link
Author

user723 commented May 11, 2021

I checked it now , getSelectedHref works

@user723
Copy link
Author

user723 commented May 11, 2021

But how can I get attributed string?

@user723
Copy link
Author

user723 commented May 11, 2021

I can get String and URL, but I cannot get attributed string!?

@Andrew-Chen-Wang
Copy link
Owner

Ah that's... strange. Typically you can just convert your string to an attributed string like NSAttributedString(string: string)

@user723
Copy link
Author

user723 commented May 11, 2021

In your example :
editorView.html = "What I'll usually do for focus and unfocus is similar to what Google Docs does. The insert link functionality is similar to Reddit's except I use a UIAlertController. There are some added and altered functionality like running your custom JS; you will just have to learn what goes on with this package, but it's a quick learn. Good luck! If you have any issues, Yoom will help out, so long as those issues are opened in this repo. Credits still go out to cjwirth and C. Bess"

"Good luck!" is bold. When I use getSelectedText, I get the text as String, but I want to get attributed string, then I can know selected text is bold, italic, underline and/or etc.

@Andrew-Chen-Wang
Copy link
Owner

Andrew-Chen-Wang commented May 11, 2021

Did you try using NSAttributedString(string: editorView.getSelectedHref())?

I'll check on it. Gimme a sec. Edit: ok so it looks like the method is just half-ass broken. I'll probably find some code to replace it from somewhere like TinyMCE.

@user723
Copy link
Author

user723 commented May 11, 2021

Thanks.

If you add this function like this, when the user selected some text or moved the cursor to a different position can get attributed string.

  • func editor(_ editor: TextEditorView, selectedTextAttributeDidChange attribute: TextAttribute)

You can check this link (https://github.com/OneupNetwork/SQRichTextEditor).

@Andrew-Chen-Wang
Copy link
Owner

It's definitely possible, but to make this fix actually work, there's a bit of discussion that I'd have to read over since there's multiple ways "getSelectedHref" can work: cjwirth/RichEditorView#25

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

No branches or pull requests

2 participants