MCPcopy Create free account
hub / github.com/ErrorAtLine0/infinipaint / remove

Method remove

src/RichText/TextBox.cpp:1139–1184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1137}
1138
1139TextPosition 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
1186TextPosition TextBox::byte_text_pos_to_render_text_pos(TextPosition pos) {
1187 pos = move(Movement::NOWHERE, pos);

Callers 1

input_android_text_boxFunction · 0.45

Calls 4

sizeMethod · 0.45
eraseMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected