MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / InsertTextAt

Method InsertTextAt

plugins/Cardinal/src/DearImGuiColorTextEditor/TextEditor.cpp:260–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258}
259
260int TextEditor::InsertTextAt(Coordinates& /* inout */ aWhere, const char * aValue)
261{
262 assert(!mReadOnly);
263
264 int cindex = GetCharacterIndex(aWhere);
265 int totalLines = 0;
266 while (*aValue != '\0')
267 {
268 assert(!mLines.empty());
269
270 if (*aValue == '\r')
271 {
272 // skip
273 ++aValue;
274 }
275 else if (*aValue == '\n')
276 {
277 if (cindex < (int)mLines[aWhere.mLine].size())
278 {
279 auto& newLine = InsertLine(aWhere.mLine + 1);
280 auto& line = mLines[aWhere.mLine];
281 newLine.insert(newLine.begin(), line.begin() + cindex, line.end());
282 line.erase(line.begin() + cindex, line.end());
283 }
284 else
285 {
286 InsertLine(aWhere.mLine + 1);
287 }
288 ++aWhere.mLine;
289 aWhere.mColumn = 0;
290 cindex = 0;
291 ++totalLines;
292 ++aValue;
293 }
294 else
295 {
296 auto& line = mLines[aWhere.mLine];
297 auto d = UTF8CharLength(*aValue);
298 while (d-- > 0 && *aValue != '\0')
299 line.insert(line.begin() + cindex++, Glyph(*aValue++, PaletteIndex::Default));
300 ++aWhere.mColumn;
301 }
302
303 mTextChanged = true;
304 }
305
306 return totalLines;
307}
308
309void TextEditor::AddUndo(UndoRecord& aValue)
310{

Callers 2

UndoMethod · 0.80
RedoMethod · 0.80

Calls 8

UTF8CharLengthFunction · 0.85
GlyphClass · 0.85
insertMethod · 0.80
eraseMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected