Deselect mark after applied to selection

Hi I’m tasked with adding support for variables to our prosemirror implementation. So far when a user selects a piece of text a context menu shows up. The user then clicks on the option to make that current selection a variable. This then gets added to the DB along with the ranges etc. A decoration then gets added to the initially selected text. Now 2 things should happen which I can’t seem to fix.

1: the variable mark should be deselected after it has been applied. Right now whatever you type after applying will be part of the variable. I tried adding transaction.setStoredMarks(null) after the inital mark transaction but with no success.

  1. when the user modifies the variable in any way it should remove the entire mark and update the db. Right now I added the initial selection as metaData on the mark to be able to perform the comparisons. However Im not sure if im approaching it the right way.

Sounds like the inclusive mark spec property might help you in the first case—it controls whether content inserted directly after such a mark gets the mark. Alternatively, if you do want to use setStoredMarks, you should set it to [], not null, since the latter means ‘no stored marks, use default behavior’.

The second seems like it needs an appendTransaction plugin that inspects each step to see whether it touches a variable, and if so, removes the variable. You’d do that by iterating over the step maps in the transaction to build up a changed range (in the final document produced by the transaction), and then iterating over that part of the document to scan for variable marks.

1 Like

Thank you so much Marijn, you are a champ. Honestly you do not get enough credit for all the effort you put in. :wink: