void (int insertionIndex) { // Merge with previous if necessary. ChangeEntry toMerge = myChanges.get(insertionIndex); if (insertionIndex > 0) { ChangeEntry left = myChanges.get(insertionIndex - 1); if (left.getClientEndOffset() == toMerge.clientStartOffset && left.change.getEnd() == toMerge.change.getStart()) { String text = left.change.getText().toString() + toMerge.change.getText(); left.change = new TextChangeImpl(text, left.change.getStart(), toMerge.change.getEnd()); myChanges.remove(insertionIndex); insertionIndex--; } } // Merge with next if necessary. toMerge = myChanges.get(insertionIndex); if (insertionIndex < myChanges.size() - 1) { ChangeEntry right = myChanges.get(insertionIndex + 1); if (toMerge.getClientEndOffset() == right.clientStartOffset && toMerge.change.getEnd() == right.change.getStart()) { String text = toMerge.change.getText().toString() + right.change.getText(); toMerge.change = new TextChangeImpl(text, toMerge.change.getStart(), right.change.getEnd()); myChanges.remove(insertionIndex + 1); } } }