- fix: can't paste contents copied from Clion/IDEA/PyCharm

This commit is contained in:
Roy Qu 2022-06-16 09:11:45 +08:00
parent 04311eb8e5
commit c4ca944a15
3 changed files with 45 additions and 43 deletions

View File

@ -3,6 +3,7 @@ Red Panda C++ Version 1.1.1
- change: swap position of problem case's output and expected input controls - 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: 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 - 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 Red Panda C++ Version 1.1.0
- enhancement: when ctrl+mouse cursor hovered an identifier or header name, use underline to highlight it - enhancement: when ctrl+mouse cursor hovered an identifier or header name, use underline to highlight it

View File

@ -4852,7 +4852,13 @@ void MainWindow::on_actionPaste_triggered()
const QMimeData* data = clipboard->mimeData(); const QMimeData* data = clipboard->mimeData();
if (!data) if (!data)
return; return;
if (data->hasUrls()) { if (data->hasText()) {
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
editor->pasteFromClipboard();
editor->activate();
}
} else if (data->hasUrls()) {
QStringList filesToOpen; QStringList filesToOpen;
foreach (const QUrl& url, data->urls()) { foreach (const QUrl& url, data->urls()) {
QString s = url.toLocalFile(); QString s = url.toLocalFile();
@ -4862,12 +4868,6 @@ void MainWindow::on_actionPaste_triggered()
} }
if (!filesToOpen.isEmpty()) if (!filesToOpen.isEmpty())
openFiles(filesToOpen); openFiles(filesToOpen);
} else {
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
editor->pasteFromClipboard();
editor->activate();
}
} }
} }

View File

@ -38,6 +38,8 @@
#include <QDrag> #include <QDrag>
#include <QMimeData> #include <QMimeData>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QTextEdit>
#include <QMimeData>
SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent), SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent),
mDropped(false) mDropped(false)
@ -3016,7 +3018,8 @@ void SynEdit::doPasteFromClipboard()
if (mReadOnly) if (mReadOnly)
return; return;
QClipboard* clipboard = QGuiApplication::clipboard(); QClipboard* clipboard = QGuiApplication::clipboard();
if (clipboard->text().isEmpty()) QString text = clipboard->text();
if (text.isEmpty())
return; return;
doOnPaintTransient(SynTransientType::ttBefore); doOnPaintTransient(SynTransientType::ttBefore);
mUndoList->BeginBlock(); mUndoList->BeginBlock();
@ -3031,46 +3034,44 @@ void SynEdit::doPasteFromClipboard()
SynSelectionMode::smNormal); SynSelectionMode::smNormal);
mUndoList->EndBlock(); mUndoList->EndBlock();
}); });
if (!clipboard->text().isEmpty()) { mUndoList->AddChange(
SynChangeReason::crPasteBegin,
blockBegin(),
blockEnd(),
"",
SynSelectionMode::smNormal);
AddPasteEndMarker = true;
if (selAvail()) {
mUndoList->AddChange( mUndoList->AddChange(
SynChangeReason::crPasteBegin, SynChangeReason::crDelete,
blockBegin(), mBlockBegin,
blockEnd(), mBlockEnd,
"", selText(),
SynSelectionMode::smNormal); mActiveSelectionMode);
AddPasteEndMarker = true; }
if (selAvail()) {
mUndoList->AddChange(
SynChangeReason::crDelete,
mBlockBegin,
mBlockEnd,
selText(),
mActiveSelectionMode);
}
// } else if (!colSelAvail()) // } else if (!colSelAvail())
// setActiveSelectionMode(selectionMode()); // setActiveSelectionMode(selectionMode());
BufferCoord vStartOfBlock = blockBegin(); BufferCoord vStartOfBlock = blockBegin();
BufferCoord vEndOfBlock = blockEnd(); BufferCoord vEndOfBlock = blockEnd();
mBlockBegin = vStartOfBlock; mBlockBegin = vStartOfBlock;
mBlockEnd = vEndOfBlock; mBlockEnd = vEndOfBlock;
setSelTextPrimitive(clipboard->text()); setSelTextPrimitive(text);
if (mActiveSelectionMode == SynSelectionMode::smColumn) { if (mActiveSelectionMode == SynSelectionMode::smColumn) {
mUndoList->AddChange( mUndoList->AddChange(
SynChangeReason::crPaste, SynChangeReason::crPaste,
blockBegin(), blockBegin(),
blockEnd(), blockEnd(),
selText(), selText(),
mActiveSelectionMode); mActiveSelectionMode);
} else { } else {
// setBlockBegin(vStartOfBlock); // setBlockBegin(vStartOfBlock);
// setBlockEnd(caretXY()); // setBlockEnd(caretXY());
mUndoList->AddChange( mUndoList->AddChange(
SynChangeReason::crPaste, SynChangeReason::crPaste,
vStartOfBlock, vStartOfBlock,
blockEnd(), blockEnd(),
selText(), selText(),
mActiveSelectionMode); mActiveSelectionMode);
}
} }
} }