From 790e785dc08649e08fbd238174bbfdd1a17820d8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 31 Oct 2022 18:48:52 +0100 Subject: [PATCH] Gui: do not allow to remove selected text with drag and drop --- src/Gui/PythonConsole.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Gui/PythonConsole.cpp b/src/Gui/PythonConsole.cpp index a3ed4ccb43..791d3acb93 100644 --- a/src/Gui/PythonConsole.cpp +++ b/src/Gui/PythonConsole.cpp @@ -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); + } } }