If I have two strings:
"Hello, this is a string!"
and
"Hello world, this is a string!"
And I track a highlighted word with { index: 13, length: 4 }
, how can I diff the two strings such that I can know to add 6 to the index since it's moved over 6 characters? I have a basic diffing algorithm that tells me that ADD: ' world' takes place at count 5.
The diff function I have would output:
[
{ count: 5, value: 'Hello' },
{ count: 6, added: true, value: ' world' },
...
]
It is as simple as tracking those changes and adding it to the index, or am I missing something?