| 1137 | } |
| 1138 | |
| 1139 | TextPosition TextBox::remove(TextPosition p1, TextPosition p2) { |
| 1140 | auto [start, end] = get_start_end_text_pos(p1, p2); |
| 1141 | |
| 1142 | if(start == end || start.fParagraphIndex == paragraphs.size()) |
| 1143 | return start; |
| 1144 | if(start.fParagraphIndex == end.fParagraphIndex) { |
| 1145 | assert(end.fTextByteIndex > start.fTextByteIndex); |
| 1146 | paragraphs[start.fParagraphIndex].text.erase(start.fTextByteIndex, end.fTextByteIndex - start.fTextByteIndex); |
| 1147 | } |
| 1148 | else { |
| 1149 | assert(end.fParagraphIndex < paragraphs.size()); |
| 1150 | auto& paragraph = paragraphs[start.fParagraphIndex]; |
| 1151 | paragraph.text.erase(start.fTextByteIndex, paragraph.text.size() - start.fTextByteIndex); |
| 1152 | paragraph.text.insert(start.fTextByteIndex, paragraphs[end.fParagraphIndex].text.substr(end.fTextByteIndex)); |
| 1153 | paragraphs.erase(paragraphs.begin() + start.fParagraphIndex + 1, paragraphs.begin() + end.fParagraphIndex + 1); |
| 1154 | } |
| 1155 | |
| 1156 | for(int32_t i = 0; i < static_cast<int32_t>(tStyleMods.size()); i++) { |
| 1157 | PositionedTextStyleMod& tStyleMod = tStyleMods[i]; |
| 1158 | auto& p = tStyleMod.pos; |
| 1159 | if(p > start) { |
| 1160 | if(end > p) |
| 1161 | p = start; |
| 1162 | else if(start.fParagraphIndex == p.fParagraphIndex) |
| 1163 | p.fTextByteIndex -= (end.fTextByteIndex - start.fTextByteIndex); |
| 1164 | else if(end.fParagraphIndex == p.fParagraphIndex) { |
| 1165 | p.fParagraphIndex = start.fParagraphIndex; |
| 1166 | p.fTextByteIndex = start.fTextByteIndex + (p.fTextByteIndex - end.fTextByteIndex); |
| 1167 | } |
| 1168 | else |
| 1169 | p.fParagraphIndex -= (end.fParagraphIndex - start.fParagraphIndex); |
| 1170 | } |
| 1171 | if(i > 0 && tStyleMods[i - 1].pos == p) { |
| 1172 | auto& tStyleModsToMergeWith = tStyleMods[i - 1].mods; |
| 1173 | for(auto& [modType, tStyle] : tStyleMod.mods) |
| 1174 | tStyleModsToMergeWith[modType] = tStyle; |
| 1175 | tStyleMods.erase(tStyleMods.begin() + i); |
| 1176 | i--; |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | remove_duplicate_text_style_mods(); |
| 1181 | needsRebuild = true; |
| 1182 | |
| 1183 | return start; |
| 1184 | } |
| 1185 | |
| 1186 | TextPosition TextBox::byte_text_pos_to_render_text_pos(TextPosition pos) { |
| 1187 | pos = move(Movement::NOWHERE, pos); |
no test coverage detected