padolsey/findAndReplaceDOMText

indexInMatch always negative of indexInNode

jeffhaessler opened this issue · 2 comments

Hi,

I've noticed that indexInMatch is just returning the negative of indexInNode. Is that the expected behavior? I'm having trouble understanding how to use this to locate the portion within the match.

https://jsfiddle.net/wou9Lxa4/4/

Yep, this is a bug. At the moment indexInMatch only produces a useful number when a match has more than one portion. (When there is only one portion in a match it seems to produce a pointless number)

E.g. of multiple portions:

<div><span>In t<em>h</em>e morning and in the afternoon.</span></div>

The first "the" is split up between three different nodes, and the replace callback is called for each portion, producing an indexInMatch of 0 (t), 1 (h) and 2 (e).

The indexInMatch should definitely be zero for cases of matches with a single portion. I'll have a look into this. Thanks for spotting it!

Fix released in 0.4.6. Sorry for the ridiculous delay.