Gui: avoid code duplication in PythonEditor
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user