Gui: do not allow to remove selected text with drag and drop

This commit is contained in:
wmayer
2022-10-31 18:48:52 +01:00
parent 64ffaa681c
commit 790e785dc0

View File

@@ -1015,8 +1015,29 @@ void PythonConsole::dropEvent (QDropEvent * e)
e->accept();
}
else {
// this will call insertFromMimeData
QPlainTextEdit::dropEvent(e);
// always copy text when doing drag and drop
if (mimeData->hasText()) {
QTextCursor cursor = this->cursorForPosition(e->pos());
QTextCursor inputLineBegin = this->inputBegin();
if (!cursorBeyond( cursor, inputLineBegin )) {
this->moveCursor(QTextCursor::End);
QRect newPos = this->cursorRect();
QDropEvent newEv(QPoint(newPos.x(), newPos.y()), Qt::CopyAction, mimeData, e->mouseButtons(), e->keyboardModifiers());
e->accept();
QPlainTextEdit::dropEvent(&newEv);
}
else {
e->setDropAction(Qt::CopyAction);
QPlainTextEdit::dropEvent(e);
}
}
else {
// this will call insertFromMimeData
QPlainTextEdit::dropEvent(e);
}
}
}