private void insertAndCheck(MConstText src, int srcStart, int srcLimit,
MText target, int start, int limit) {
// p-style after insertion
AttributeMap after;
if (limit == target.length() && srcLimit > srcStart) {
after = src.paragraphStyleAt(srcLimit);
}
else {
after = target.paragraphStyleAt(limit);
}
AttributeMap before;
boolean srcHasPBreak = false;
for (int i=srcStart; i < srcLimit; i++) {
if (isParagraphBreak(src.at(i))) {
srcHasPBreak = true;
break;
}
}
if (start > 0 && isParagraphBreak(target.at(start-1))) {
before = target.paragraphStyleAt(start-1);
}
else {
before = srcHasPBreak? src.paragraphStyleAt(srcStart) : after;
}
boolean stylePropogated = !before.equals(target.paragraphStyleAt(Math.max(0, start-1)));
target.resetDamagedRange();
target.replace(start, limit, src, srcStart, srcLimit);
final int damageLimit = (start==limit && srcStart==srcLimit)?
Integer.MIN_VALUE : start + (srcLimit-srcStart);
if (target.damagedRangeLimit() != damageLimit) {
logln("limit: " + damageLimit + "; target.limit: " +
target.damagedRangeLimit());
errln("Damaged range limit is incorrect");
}
final int damageStart = (damageLimit==Integer.MIN_VALUE)? Integer.MAX_VALUE :
(stylePropogated? target.paragraphStart(Math.max(0, start-1)) : start);
if (target.damagedRangeStart() > damageStart) {
logln("start: " + damageStart + "; target.start: " +
target.damagedRangeStart());
errln("Damaged range start is incorrect");
}
verifyParagraphCount(target);
// check endpoints
if (!before.equals(target.paragraphStyleAt(Math.max(start-1, 0)))) {
errln("Incorrect paragraph style before modified range");
}
int lengthDelta = (srcLimit-srcStart) - (limit-start);
int indexAfterInsert = Math.min(target.length(), limit + lengthDelta);