Output window overwrites current selection instead of appending to end of document
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
When the output window receives new text it typically appends this text to the end of the output window.
However: If a user selects a new cursor position or selects any text in the output window, and THEN new text is added to the output window, this new text will output at the cursor position, and replace the selection if there was one.
The offending code appears to be this, in pqConsoleWidget.cxx
void pqConsoleWidget::printString(const QString& Text) { this->Implementation->textCursor().movePosition(QTextCursor::End); this->Implementation->textCursor().insertText(Text); this->Implementation->InteractivePosition = this->Implementation->documentEnd(); this->Implementation->ensureCursorVisible(); }
The problem is that textCursor() returns a COPY of the text cursor, so although the text is still inserted (I think because it has a pointer to the text document), the effects of movePosition(QTextCursor::End) are lost.
I have had success by replacing that code with this:
void pqConsoleWidget::printString(const QString& Text) { this->Implementation->append(Text); this->Implementation->InteractivePosition = this->Implementation->documentEnd(); this->Implementation->ensureCursorVisible(); }
It works because this->Implementation is a QTextEdit, and QTextEdit has an append method which does what was intended by the former code block.
Alternatively, I guess you could make a local variable of textCursor(), then call this->Implementation->setTextCursor() as well.