Tracking Text positions

Hi,

I have this code which inserts some character around a section.

const insertCode = view.state.changeByRange(range => ({
        changes: [{ from: range.from, insert: "§" }, { from: range.to, insert: "§" }],
        range: EditorSelection.range(range.from, range.to + 2),
    }));

If I wanted to keep track of the inserts so the the characters could be removed later if the same text range is selected should I use a rangeSet even though there’s no visual difference. I’d like the ranges to be tracked if other changes happen.

If it’s only 2 positions, directly mapping them with tr.changes.mapPos should be easy enough.

The idea wold be that the special chars would wrap text and appear repeatedly through out the doc. The chars would have to be treated as a pair so they can be removed together when necessary.
Essentially a range with a char at either end?

In the examples when creating a range the value is always a prebuilt Decoration, how would I create a value that doesn’t do anything else expect say it’s a particular type of range that I’ve defined.

Thanks.

class EZRange extends RangeValue {
  eq() {
    return true;
  }
}
1 Like