| 218 | } |
| 219 | |
| 220 | void TextEditor::DeleteRange(const Coordinates & aStart, const Coordinates & aEnd) |
| 221 | { |
| 222 | assert(aEnd >= aStart); |
| 223 | assert(!mReadOnly); |
| 224 | |
| 225 | //printf("D(%d.%d)-(%d.%d)\n", aStart.mLine, aStart.mColumn, aEnd.mLine, aEnd.mColumn); |
| 226 | |
| 227 | if (aEnd == aStart) |
| 228 | return; |
| 229 | |
| 230 | auto start = GetCharacterIndex(aStart); |
| 231 | auto end = GetCharacterIndex(aEnd); |
| 232 | |
| 233 | if (aStart.mLine == aEnd.mLine) |
| 234 | { |
| 235 | auto& line = mLines[aStart.mLine]; |
| 236 | auto n = GetLineMaxColumn(aStart.mLine); |
| 237 | if (aEnd.mColumn >= n) |
| 238 | line.erase(line.begin() + start, line.end()); |
| 239 | else |
| 240 | line.erase(line.begin() + start, line.begin() + end); |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | auto& firstLine = mLines[aStart.mLine]; |
| 245 | auto& lastLine = mLines[aEnd.mLine]; |
| 246 | |
| 247 | firstLine.erase(firstLine.begin() + start, firstLine.end()); |
| 248 | lastLine.erase(lastLine.begin(), lastLine.begin() + end); |
| 249 | |
| 250 | if (aStart.mLine < aEnd.mLine) |
| 251 | firstLine.insert(firstLine.end(), lastLine.begin(), lastLine.end()); |
| 252 | |
| 253 | if (aStart.mLine < aEnd.mLine) |
| 254 | RemoveLine(aStart.mLine + 1, aEnd.mLine + 1); |
| 255 | } |
| 256 | |
| 257 | mTextChanged = true; |
| 258 | } |
| 259 | |
| 260 | int TextEditor::InsertTextAt(Coordinates& /* inout */ aWhere, const char * aValue) |
| 261 | { |