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

Documentation: removeMark() checks data along with type #826

Closed
AlexeiAndreev opened this issue May 18, 2017 · 7 comments
Closed

Documentation: removeMark() checks data along with type #826

AlexeiAndreev opened this issue May 18, 2017 · 7 comments

Comments

@AlexeiAndreev
Copy link

It was not at all clear to me that when you call removeMark(type), it also checks mark's data parameter and will not remove a mark even if it matches the type if the data doesn't match as well.

@AlexeiAndreev
Copy link
Author

The use case here is: the editor is in the readOnly state, but the user can highlight a section and click "add comment". Then I want to add a mark to show the selection. This is a very important feature for my project, but right now there is no way to easily create/get Slate's Selection object.

(By the way, thank you to everyone who is contributing to this project. This is the best editor!)

@SmilinBrian
Copy link
Contributor

See also #873, which evolved into a discussion about this. (Unfortunately without any clear decision)

@danburzo
Copy link
Contributor

danburzo commented Sep 18, 2017

You can also follow this discussion to see the different cases removeMark needs to cover.

The decision so far is to have removeMark remove specific Marks (that is, the type + associated data), and iterating state.marks manually and removing the marks as necessary based on your custom condition.

Slate may eventually get a removeMark(String) that removes all marks of a given type, but I think that's still an open subject.

@samotoo
Copy link

samotoo commented Dec 11, 2017

I understand there's no direct API to remove marks with a certain type. But is there any workaround for this?

I'm using the mark to toggle text colors. I put the color into the data of the mark. And everytime the color is changed, I would like to remove the mark and replace it with a new one with updated data. Is this the right way of implementing such functions in slate? Please help to advise.

Thanks in advance and looking forward to suggestions.

@bengotow
Copy link
Contributor

Hey folks—just wanted to chime in here. Just got bit by this and it took a lot of source exploration to track down. The Slate removeMark and replaceMark methods imply that the arguments can be string types or mark objects, but it turns out you really cannot use the string version of the function if your mark has a data payload, since leaf.marks.has(mark) is always false when comparing the value marks to the inflated just-a-type-and-no-data mark.

In case it's helpful, here's what I was naiively trying to do. I think this API behavior is fine but it should definitely be documented that the string shorthand only works when the mark has no data.

  editor.replaceMark(EMOJI_TYPING_TYPE, {
    type: EMOJI_TYPING_TYPE,
    data: {  // updated data // },
  });

@ianstormtaylor
Copy link
Owner

Open to fixing this if anyone wants to make a PR.

@ianstormtaylor ianstormtaylor mentioned this issue Nov 6, 2019
@ianstormtaylor
Copy link
Owner

As of #3093 (which was just merged), I believe this issue is no longer applicable, because a lot has changed. I'm going through and closing out any potential issues that are not out of date with the overhaul. Thanks for understanding.

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

No branches or pull requests

6 participants