# Shouldn't ReplaceSelectionWith merge the marks when inheriting?

**URL:** https://discuss.prosemirror.net/t/shouldnt-replaceselectionwith-merge-the-marks-when-inheriting/3630
**Category:** Uncategorized
**Created:** [March 26, 2021, 4:14am UTC](https://discuss.prosemirror.net/t/shouldnt-replaceselectionwith-merge-the-marks-when-inheriting/3630 "2021-03-26T04:14:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![andrews](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@andrews](https://discuss.prosemirror.net/u/andrews)
#### Post date: [March 26, 2021, 4:14am UTC](https://discuss.prosemirror.net/t/shouldnt-replaceselectionwith-merge-the-marks-when-inheriting/3630/1 "2021-03-26T04:14:05Z")

</div>

I was trying to insert a link using [replaceSelectionWith](https://github.com/ProseMirror/prosemirror-state/blob/389bb702247283b1d4da2656f46c0b1bcadf89e1/src/transaction.js#L136) and saw that my link was lost. I saw other posts like [Insert a text with a link](https://discuss.prosemirror.net/t/insert-a-text-with-a-link/2350) that had a similar issue and the resolution being to pass false for the inheritMarks optional 2nd parameter of that method. However I don’t understand why when true (the default) it doesn’t _merge_ any marks in the node being inserted with the inherited marks instead of just discarding the marks on the node being inserted? For example if I had replaceSelectionWith a node that has a mark (in my case a link) and the selection has strikeout (odd but just an example) I would expect that the result is a text node with a link and strikeout like what might happen in Word. If there were a conflict (i.e. an instance of the same mark in the marks to inherit) then I would expect the one on the node would win.

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)
#### Post date: [March 26, 2021, 7:29am UTC](https://discuss.prosemirror.net/t/shouldnt-replaceselectionwith-merge-the-marks-when-inheriting/3630/2 "2021-03-26T07:29:35Z")

</div>

The idea is that it’s a toggle between using the node’s marks or using the context marks. I guess there are valid arguments for either way it could work, but at this point changing the behavior would be a breaking change so it’s pretty much not possible, so you’ll have to work with the current behavior.

---

<div class="post-metadata">

### Author: ![andrews](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@andrews](https://discuss.prosemirror.net/u/andrews)
#### Post date: [March 26, 2021, 12:31pm UTC](https://discuss.prosemirror.net/t/shouldnt-replaceselectionwith-merge-the-marks-when-inheriting/3630/3 "2021-03-26T12:31:00Z")

</div>

Ok. Thanks for the reply. Yes I can understand not wanting to introduce any regressions as its hard to tell if someone is relying on this behavior. I was thinking that someone is likely creating a node to pass in but if they are getting a node from another location and using this as sort of a “keep text only” type insertion then they would want to discard the node’s state and so there are probably other scenarios I wasn’t thinking of. And it wasn’t hard to implement in my code since I only needed to replicate the little bit about gathering the marks to inherit and then use the existing addToSet to merge in those of the node being injected. Thanks again.
