Gui: avoid code duplication in PythonEditor

This commit is contained in:
wmayer
2025-03-17 14:18:48 +01:00
committed by Ladislav Michl
parent 9497ddf5e1
commit 3888899e7c
3 changed files with 38 additions and 53 deletions

View File

@@ -243,27 +243,7 @@ void PythonEditor::onComment()
void PythonEditor::onUncomment()
{
QTextCursor cursor = textCursor();
int selStart = cursor.selectionStart();
int selEnd = cursor.selectionEnd();
QTextBlock block;
cursor.beginEditBlock();
for (block = document()->begin(); block.isValid(); block = block.next()) {
int pos = block.position();
int off = block.length()-1;
// at least one char of the block is part of the selection
if ( pos >= selStart || pos+off >= selStart) {
if ( pos+1 > selEnd )
break; // end of selection reached
if (block.text().startsWith(QLatin1String("#"))) {
cursor.setPosition(block.position());
cursor.deleteChar();
selEnd--;
}
}
}
cursor.endEditBlock();
remove(QStringLiteral("#"));
}
void PythonEditor::onExecuteInConsole()