diff --git a/lib/utility.dart b/lib/utility.dart index 0052816..bd775bc 100644 --- a/lib/utility.dart +++ b/lib/utility.dart @@ -66,13 +66,13 @@ class Utility { newIndex++; if (oldIndex < oldWords.length && newIndex < newWords.length) { + var nextOldWord = oldWords[oldIndex]; var newSubIndex = newIndex; var oldSubIndex = oldIndex; while (newSubIndex < newWords.length && - newWords[newSubIndex].text != oldWords[oldSubIndex].text) { - //nextOldWord was not incremented in the loop hence used indexing for nextOldWord + newWords[newSubIndex].text != nextOldWord.text) { WordDelta wordDelta = - WordDelta(old: oldWords[oldSubIndex], modified: newWords[newSubIndex]); + WordDelta(old: nextOldWord, modified: newWords[newSubIndex]); delta.wordDeltas.add(wordDelta); newSubIndex++; oldSubIndex++; diff --git a/test/utlity_test.dart b/test/utlity_test.dart index 07ca10e..b51d5a3 100644 --- a/test/utlity_test.dart +++ b/test/utlity_test.dart @@ -109,7 +109,7 @@ void main() { expect(deltas[0].wordDeltas[0].modified!.text, "zbc"); expect(deltas[0].wordDeltas[1].old!.text, "def"); expect(deltas[0].wordDeltas[1].modified!.text, "dkf"); - expect(deltas[0].wordDeltas[2].old!.text, "ghi"); + expect(deltas[0].wordDeltas[2].old!.text, "def"); expect(deltas[0].wordDeltas[2].modified!.text, "gha"); }); }