From c4ca944a15b6db7900dfb1a1a86129d4592d5534 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 16 Jun 2022 09:11:45 +0800 Subject: [PATCH] - fix: can't paste contents copied from Clion/IDEA/PyCharm --- NEWS.md | 1 + RedPandaIDE/mainwindow.cpp | 14 +++--- RedPandaIDE/qsynedit/SynEdit.cpp | 73 ++++++++++++++++---------------- 3 files changed, 45 insertions(+), 43 deletions(-) diff --git a/NEWS.md b/NEWS.md index d764ba96..7e78f3ba 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ Red Panda C++ Version 1.1.1 - change: swap position of problem case's output and expected input controls - enhancement: when problem case panel is positioned at right, problem case's input, output and expected controls is layouted vertically - enhancement: add ignore spaces checkbox in problem cases panel + - fix: can't paste contents copied from Clion/IDEA/PyCharm Red Panda C++ Version 1.1.0 - enhancement: when ctrl+mouse cursor hovered an identifier or header name, use underline to highlight it diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index fd1b028c..ce06b626 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -4852,7 +4852,13 @@ void MainWindow::on_actionPaste_triggered() const QMimeData* data = clipboard->mimeData(); if (!data) return; - if (data->hasUrls()) { + if (data->hasText()) { + Editor * editor = mEditorList->getEditor(); + if (editor != NULL ) { + editor->pasteFromClipboard(); + editor->activate(); + } + } else if (data->hasUrls()) { QStringList filesToOpen; foreach (const QUrl& url, data->urls()) { QString s = url.toLocalFile(); @@ -4862,12 +4868,6 @@ void MainWindow::on_actionPaste_triggered() } if (!filesToOpen.isEmpty()) openFiles(filesToOpen); - } else { - Editor * editor = mEditorList->getEditor(); - if (editor != NULL ) { - editor->pasteFromClipboard(); - editor->activate(); - } } } diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 4d033e70..7b8ab6aa 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -38,6 +38,8 @@ #include #include #include +#include +#include SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent), mDropped(false) @@ -3016,7 +3018,8 @@ void SynEdit::doPasteFromClipboard() if (mReadOnly) return; QClipboard* clipboard = QGuiApplication::clipboard(); - if (clipboard->text().isEmpty()) + QString text = clipboard->text(); + if (text.isEmpty()) return; doOnPaintTransient(SynTransientType::ttBefore); mUndoList->BeginBlock(); @@ -3031,46 +3034,44 @@ void SynEdit::doPasteFromClipboard() SynSelectionMode::smNormal); mUndoList->EndBlock(); }); - if (!clipboard->text().isEmpty()) { + mUndoList->AddChange( + SynChangeReason::crPasteBegin, + blockBegin(), + blockEnd(), + "", + SynSelectionMode::smNormal); + AddPasteEndMarker = true; + if (selAvail()) { mUndoList->AddChange( - SynChangeReason::crPasteBegin, - blockBegin(), - blockEnd(), - "", - SynSelectionMode::smNormal); - AddPasteEndMarker = true; - if (selAvail()) { - mUndoList->AddChange( - SynChangeReason::crDelete, - mBlockBegin, - mBlockEnd, - selText(), - mActiveSelectionMode); - } + SynChangeReason::crDelete, + mBlockBegin, + mBlockEnd, + selText(), + mActiveSelectionMode); + } // } else if (!colSelAvail()) // setActiveSelectionMode(selectionMode()); - BufferCoord vStartOfBlock = blockBegin(); - BufferCoord vEndOfBlock = blockEnd(); - mBlockBegin = vStartOfBlock; - mBlockEnd = vEndOfBlock; - setSelTextPrimitive(clipboard->text()); - if (mActiveSelectionMode == SynSelectionMode::smColumn) { - mUndoList->AddChange( - SynChangeReason::crPaste, - blockBegin(), - blockEnd(), - selText(), - mActiveSelectionMode); - } else { + BufferCoord vStartOfBlock = blockBegin(); + BufferCoord vEndOfBlock = blockEnd(); + mBlockBegin = vStartOfBlock; + mBlockEnd = vEndOfBlock; + setSelTextPrimitive(text); + if (mActiveSelectionMode == SynSelectionMode::smColumn) { + mUndoList->AddChange( + SynChangeReason::crPaste, + blockBegin(), + blockEnd(), + selText(), + mActiveSelectionMode); + } else { // setBlockBegin(vStartOfBlock); // setBlockEnd(caretXY()); - mUndoList->AddChange( - SynChangeReason::crPaste, - vStartOfBlock, - blockEnd(), - selText(), - mActiveSelectionMode); - } + mUndoList->AddChange( + SynChangeReason::crPaste, + vStartOfBlock, + blockEnd(), + selText(), + mActiveSelectionMode); } }