- 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
- 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

View File

@ -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();
}
}
}

View File

@ -38,6 +38,8 @@
#include <QDrag>
#include <QMimeData>
#include <QDesktopWidget>
#include <QTextEdit>
#include <QMimeData>
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);
}
}