# If I want to implement the comment function, is mark the best way?

**URL:** https://discuss.prosemirror.net/t/if-i-want-to-implement-the-comment-function-is-mark-the-best-way/3831
**Category:** Uncategorized
**Created:** [June 15, 2021, 11:59am UTC](https://discuss.prosemirror.net/t/if-i-want-to-implement-the-comment-function-is-mark-the-best-way/3831 "2021-06-15T11:59:19Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![milu2003](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/milu2003/32/2063_2.png) [@milu2003](https://discuss.prosemirror.net/u/milu2003)
#### Post date: [June 15, 2021, 11:59am UTC](https://discuss.prosemirror.net/t/if-i-want-to-implement-the-comment-function-is-mark-the-best-way/3831/1 "2021-06-15T11:59:19Z")

</div>

[https://prosemirror.net/docs/ref/#model.Mark](https://prosemirror.net/docs/ref/#model.Mark)

like this:

 ![image](https://discuss.prosemirror.net/uploads/secondsite/original/2X/2/26949a359cba46a6eddd46c7c183fc53a85e63c4.jpeg)

I need to comment on a text or an figure

---

<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: [June 16, 2021, 8:14am UTC](https://discuss.prosemirror.net/t/if-i-want-to-implement-the-comment-function-is-mark-the-best-way/3831/2 "2021-06-16T08:14:36Z")

</div>

Keeping the comments in a data structure outside of the doc and showing them as decorations might make them easier to manage when they can cross block boundaries. But using marks should also work, especially if you want them to be part of the document and automatically included in collaborative editing and the undo history.

---

<div class="post-metadata">

### Author: ![milu2003](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/milu2003/32/2063_2.png) [@milu2003](https://discuss.prosemirror.net/u/milu2003)
#### Post date: [June 16, 2021, 10:09am UTC](https://discuss.prosemirror.net/t/if-i-want-to-implement-the-comment-function-is-mark-the-best-way/3831/3 "2021-06-16T10:09:52Z")

</div>

Can mark customize a view? Similar to nodeview

---

<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: [June 16, 2021, 10:34am UTC](https://discuss.prosemirror.net/t/if-i-want-to-implement-the-comment-function-is-mark-the-best-way/3831/4 "2021-06-16T10:34:49Z")

</div>

No, marks can’t do most of the things nodeview can. You can only change the element used to render the mark.

---

<div class="post-metadata">

### Author: ![milu2003](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/milu2003/32/2063_2.png) [@milu2003](https://discuss.prosemirror.net/u/milu2003)
#### Post date: [June 16, 2021, 10:37am UTC](https://discuss.prosemirror.net/t/if-i-want-to-implement-the-comment-function-is-mark-the-best-way/3831/5 "2021-06-16T10:37:45Z")

</div>

Well, thank you for your work. It’s easy to realize these requirements.

---

<div class="post-metadata">

### Author: ![milu2003](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/milu2003/32/2063_2.png) [@milu2003](https://discuss.prosemirror.net/u/milu2003)
#### Post date: [June 16, 2021, 10:39am UTC](https://discuss.prosemirror.net/t/if-i-want-to-implement-the-comment-function-is-mark-the-best-way/3831/6 "2021-06-16T10:39:10Z")

</div>

I feel that although this framework is good, the cost of learning is too high. I would be very grateful if the government could give more examples, which will also help to promote the popularization of this project.

---

<div class="post-metadata">

### Author: ![milu2003](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/milu2003/32/2063_2.png) [@milu2003](https://discuss.prosemirror.net/u/milu2003)
#### Post date: [June 16, 2021, 10:40am UTC](https://discuss.prosemirror.net/t/if-i-want-to-implement-the-comment-function-is-mark-the-best-way/3831/7 "2021-06-16T10:40:02Z")

</div>

Although your framework is good, I can hardly find relevant people in China to discuss it.

---

<div class="post-metadata">

### Author: ![milu2003](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/milu2003/32/2063_2.png) [@milu2003](https://discuss.prosemirror.net/u/milu2003)
#### Post date: [June 16, 2021, 3:24pm UTC](https://discuss.prosemirror.net/t/if-i-want-to-implement-the-comment-function-is-mark-the-best-way/3831/8 "2021-06-16T15:24:07Z")

</div>

If I want to click each mark, a window will pop up. So where is a good place to listen for click events?

```javascript
document.querySelectorAll('span.comment').forEach((el, i) => {
  el.addEventListener('click', e => {
      //do something
  });
});

```

I’m doing it now, but it’s not good enough

* * *

i know，use handleClick

---

<div class="post-metadata">

### Author: ![ViktorVaczi](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/viktorvaczi/32/1919_2.png) [@ViktorVaczi](https://discuss.prosemirror.net/u/ViktorVaczi)
#### Post date: [June 19, 2021, 5:22pm UTC](https://discuss.prosemirror.net/t/if-i-want-to-implement-the-comment-function-is-mark-the-best-way/3831/9 "2021-06-19T17:22:46Z")

</div>

Hey,

In my experience it’s best to move this functionality “out” from ProseMirror, a mark just stores the threadId, and make a plugin which captures clicks in the editor, checks if the click was on a “thread” mark, if that’s the case then it sets it’s internal state the thread’s id & position. Then you watch editorState changes, and if the “thread” plugin is signaling that you’ve clicked on the mark then you display the thread component in whatever framework you’re using.

I’ve left out some details ( cleaning up the internal state when you click out etc… ), but you get the idea. You will need posAtCoords / coordsAtPos to determine the thread component’s position / to get if the click was inside a thread mark. Good luck!

---

<div class="post-metadata">

### Author: ![yinran100](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/yinran100/32/2535_2.png) [@yinran100](https://discuss.prosemirror.net/u/yinran100)
#### Post date: [December 21, 2021, 2:38am UTC](https://discuss.prosemirror.net/t/if-i-want-to-implement-the-comment-function-is-mark-the-best-way/3831/10 "2021-12-21T02:38:59Z")

</div>

我也在看，哥们，这个编辑器有方案吗

---

<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: [December 21, 2021, 9:42am UTC](https://discuss.prosemirror.net/t/if-i-want-to-implement-the-comment-function-is-mark-the-best-way/3831/11 "2021-12-21T09:42:10Z")

</div>

Let’s keep the forum in English, please, even if that means running your reply through an automatic translation service before posting.
