| 527 | PythonTextEditor::~PythonTextEditor() = default; |
| 528 | |
| 529 | void PythonTextEditor::prepend(const QString& str) |
| 530 | { |
| 531 | QTextCursor cursor = textCursor(); |
| 532 | // for each selected block insert a tab or spaces |
| 533 | int selStart = cursor.selectionStart(); |
| 534 | int selEnd = cursor.selectionEnd(); |
| 535 | QTextBlock block; |
| 536 | cursor.beginEditBlock(); |
| 537 | for (block = document()->begin(); block.isValid(); block = block.next()) { |
| 538 | int pos = block.position(); |
| 539 | int off = block.length() - 1; |
| 540 | // at least one char of the block is part of the selection |
| 541 | if (pos >= selStart || pos + off >= selStart) { |
| 542 | if (pos + 1 > selEnd) { |
| 543 | break; // end of selection reached |
| 544 | } |
| 545 | cursor.setPosition(block.position()); |
| 546 | cursor.insertText(str); |
| 547 | selEnd += str.length(); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | cursor.endEditBlock(); |
| 552 | } |
| 553 | |
| 554 | void PythonTextEditor::remove(const QString& str) |
| 555 | { |
no test coverage detected