+ if(additional.length > 0) {
+ for(int i = 0; i < fs.formats.count(); i++) {
+ int oldend = fs.formats[i].start + fs.formats[i].length - 1;
+ int addend = additional.start + additional.length - 1;
+ if(oldend < additional.start) continue;
+ fs.formats[i].length = additional.start - fs.formats[i].start;
+ QTextLayout::FormatRange addfmtrng = fs.formats[i];
+ addfmtrng.format.merge(additional.format);
+ addfmtrng.start = additional.start;
+ addfmtrng.length = qMin(oldend, addend) - additional.start + 1;
+ fs.formats.insert(++i, addfmtrng);
+ if(addend == oldend) break;
+ if(addend < oldend) {
+ QTextLayout::FormatRange restfmtrng = fs.formats[i-1];
+ restfmtrng.start = addend + 1;
+ restfmtrng.length = oldend - addend;
+ fs.formats.insert(++i, restfmtrng);
+ break;
+ }
+ }
+ }
+