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

Handle link click in editor #194

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Wavesonics
Copy link
Contributor

@Wavesonics Wavesonics commented Feb 3, 2024

I don't think this is ready to merge yet, but take a look at the current approach.

I added a new listener: RichSpanClickListener

Which gets clicks on all RichSpans, and lets the user sort them out.

I have an example in RichEditorContent.kt using this new listener to show a popup simulating a spellchecker.

However getRichSpanByOffset() only seems to work in the BasicRichTextEditor, The Outline variant which I think has extra padding maybe? The clicks return the wrong span. It appears to me to be offset by maybe the amount of padding? Not sure.

In order to make all of this work I had to make more classes public, which might be fine? But if we decide we don't want to expose all of those internal workings, maybe we'd have some stripped down classes to return instead in the click listener?

This update introduces a callback function `onRichSpanClick` to allow apps to handle clicks on RichSpans in the RichTextEditor. The updates also modify the visibility of some classes and properties to support this- `RichSpan`, `ParagraphType` and `getRichSpanByOffset` method in `RichTextState` are now publicly visible.
@Wavesonics
Copy link
Contributor Author

Wavesonics commented Nov 13, 2024

I got this working again, however it suffers from the same problem as outlined in #421

So if there is line wrapping, then it will select the wrong span of text.

The bug is separate from this PR, so I think this is ready for review now.

I had to make some decisions because of the new strict API checking on what to make public VS internal, so not sure what you think about the choices I made there. Importantly, RichSpanStyle needs to be a public, open, class now so that custom spans can be applied.

@Wavesonics Wavesonics marked this pull request as ready for review November 13, 2024 05:16
@Wavesonics Wavesonics mentioned this pull request Nov 14, 2024
@Wavesonics
Copy link
Contributor Author

Wavesonics commented Nov 22, 2024

Okay, I'm understanding the code base quite a bit better than before, I refactored things so I no longer have to make RichParagraph or RichSpan public.

) {
newParagraphFirstRichSpan.spanStyle = currentSpanStyle
newParagraphFirstRichSpan.richSpanStyle = currentRichSpanStyle
newParagraph.getFirstNonEmptyChild()?.let { newParagraphFirstRichSpan ->
Copy link
Contributor Author

@Wavesonics Wavesonics Nov 22, 2024

Choose a reason for hiding this comment

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

Handling a nullable, not sure why this isn't a problem in the main branch?

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.

1 participant