Gui: avoid code duplication in PythonEditor

This commit is contained in:
Benjamin Bræstrup Sayoc
2025-03-01 14:59:04 +01:00
parent 3f9ad28acf
commit 2ebb951bb1
3 changed files with 32 additions and 38 deletions

View File

@@ -238,25 +238,7 @@ void PythonEditor::keyPressEvent(QKeyEvent* e)
void PythonEditor::onComment()
{
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
cursor.setPosition(block.position());
cursor.insertText(QLatin1String("#"));
selEnd++;
}
}
cursor.endEditBlock();
prepend(QStringLiteral("#"));
}
void PythonEditor::onUncomment()