| 258 | } |
| 259 | |
| 260 | int 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 | |
| 309 | void TextEditor::AddUndo(UndoRecord& aValue) |
| 310 | { |