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

Read and reassign selected text marks when editing a link #238

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

Conversation

maatMa
Copy link

@maatMa maatMa commented Jun 25, 2024

Pull request related to the issue #237

@sjdemartini
Copy link
Owner

@maatMa Thanks for looking into this. You mentioned here #237 (comment)

Unfortunately, editing the Text is not possible anymore. It looks like the marks are overriding the updated Text.

Is that still true of this solution? I haven't had a chance to test this out.


At first glance, this seems like it may work in a large number of cases, though I'm not sure if it will work 100% of the time. For instance, if the link has part of the text in bold and part not, what will happen to the resulting link? Based on the code, I'd guess it'll end up being either all bold or all not bold, even though users will likely expect the original styling to be preserved. Tricky, and still perhaps an improvement over the behavior today!


Also side note that the TS type-checking failed on this branch (with a minor issue related to Tiptap generics); see the build result.

@maatMa
Copy link
Author

maatMa commented Jun 26, 2024

Yes, the Text Edit Problem is still the case. I can't think of a good soulution there.


At first glance, this seems like it may work in a large number of cases, though I'm not sure if it will work 100% of the time. For instance, if the link has part of the text in bold and part not, what will happen to the resulting link?

Multiple marks are supported, the function reads every existing text mark and reassign it to the edited link. I allready tested this with multiple marks and it looks like it works.

Thats why it is so hard to implement the text changes. I don't know how to assign the changed text inside the mark array.

@maatMa
Copy link
Author

maatMa commented Jun 26, 2024

I tried to fix the Typescript errors. Looks like I've got some more issues in my code regarding the mapping between the node and content marks.
I hope to find time this week to take a look into that.

@maatMa
Copy link
Author

maatMa commented Jun 27, 2024

Thanks to @semanticist21 the text update is working now.

@maatMa
Copy link
Author

maatMa commented Jul 3, 2024

@sjdemartini Is this Pull request fine, or do you need some more intormations, testing, refactoring, etc.

@sjdemartini
Copy link
Owner

@maatMa I'll play around with this when I get some time and will follow up once I do. As you've seen through a couple of the iterations here, link editing/creation is quite finicky in Tiptap, so I'd like to make sure there isn't any regression in behavior.

@maatMa
Copy link
Author

maatMa commented Jul 3, 2024

@sjdemartini Sure, no problem. Just wanted to make sure you're not waiting for me.

@maatMa
Copy link
Author

maatMa commented Aug 21, 2024

@sjdemartini Did you had time to test the pull-request?

@sjdemartini
Copy link
Owner

@maatMa Sorry for the delay. I haven't had time to test this out yet but plan to soon. (I want to be thorough to try to ensure we avoid any bugs, since I've found this to be a delicate piece of functionality.) Thanks for your patience.

@sjdemartini sjdemartini changed the title Read and reassign selected text marks Read and reassign selected text marks when editing a link Sep 23, 2024
Copy link
Owner

@sjdemartini sjdemartini left a comment

Choose a reason for hiding this comment

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

Thanks again for the work on this and your patience. I haven't had a chance to try to run through various scenarios and test this extensively/manually since I have a lot of other things on my plate. I think it will probably be worth adding unit tests for this sort of functionality, given how many edge cases and scenarios there are, and how brittle this sort of behavior in Tiptap can be. If only setLink() were sufficient!

By the way, Tiptap just recently added somewhat similar logic related to toggling the heading type, where they copy over / preserve attributes ueberdosis/tiptap#5489, which may be useful to reference. Maybe we can use similar logic here? Their unit-tests may also be handy as a place to get started.

const resolvedPos = state.doc.resolve(selection.from);
const nodeAfter = resolvedPos.nodeAfter;

if (nodeAfter?.isText) {
Copy link
Owner

Choose a reason for hiding this comment

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

Why is it we only use this logic below if specifically the next node is text?

And what if there are multiple nodes within the selection, not just two?

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.

Link Edit removes marks (font size, bold, italics, etc) for selected link
2 participants