Can we store metadata on every words and let user modify it and still keep it?

Hi, I’m new to ProseMirror and I’m developing annotation tool for speech-to-text.

I have used draftjs. I use entity and decorator to store and manage metadata on each words. every single words are entities and each entity has timestamp as metadata.

example: I have a cat

" I ", " have ", " a ", " cat " are entities.

entity data of cat is like

offset: 12,
length: 5,
data: {
 original_word: 'cat',
 start: 4.2,
 end: 4,6,

So when user select a word and modify the word cat into kitten, I can still get start and end timestamps.

Do you think I can develop similar thing with ProseMirror?

It’s okay for metadata to break when user delete multiple words at a time… No need to be perfect because I need to migrate to some editor library from draftjs anyway sooner or later…

Thanks in advance.

Yes, this is possible. Document positions can be ‘mapped’ for changes to the document to find the new corresponding position, and you could keep your annotations either in a custom data structure that updates them on each transaction, or in a decoration set, which comes with an efficient method to map all the ranges inside it.

Thank you so much. I’ll try decoration set.