Verified Commit 3baa2aa8 authored by Jonah Brüchert's avatar Jonah Brüchert 🌳
Browse files

Revert "TerminalDisplay: Extract copying related functions"

This reverts commit 1a2867c8.
parent dfda7d53
......@@ -184,8 +184,8 @@ set(konsoleprivate_SRCS ${windowadaptors_SRCS}
terminalDisplay/TerminalScrollBar.cpp
terminalDisplay/TerminalColor.cpp
terminalDisplay/TerminalFonts.cpp
terminalDisplay/TerminalClipboard.cpp
terminalDisplay/TerminalBell.cpp
terminalDisplay/TerminalPasting.cpp
widgets/TerminalDisplayAccessible.cpp
widgets/TerminalHeaderBar.cpp
......
......@@ -75,7 +75,7 @@
#include "TerminalScrollBar.h"
#include "TerminalColor.h"
#include "TerminalFonts.h"
#include "TerminalClipboard.h"
#include "TerminalPasting.h"
using namespace Konsole;
......@@ -1568,7 +1568,7 @@ void TerminalDisplay::processMidButtonClick(QMouseEvent* ev)
if (_middleClickPasteMode == Enum::PasteFromX11Selection) {
pasteFromX11Selection(appendEnter);
} else if (_middleClickPasteMode == Enum::PasteFromClipboard) {
doPaste(terminalClipboard::pasteFromClipboard(), appendEnter);
doPaste(terminalPasting::pasteFromClipboard(), appendEnter);
} else {
Q_ASSERT(false);
}
......@@ -2120,7 +2120,7 @@ void TerminalDisplay::doPaste(QString text, bool appendReturn)
}
}
auto unsafeCharacters = terminalClipboard::checkForUnsafeCharacters(text);
auto unsafeCharacters = terminalPasting::checkForUnsafeCharacters(text);
if (!unsafeCharacters.isEmpty()) {
int result = KMessageBox::warningYesNoCancelList(window(),
......@@ -2143,7 +2143,7 @@ void TerminalDisplay::doPaste(QString text, bool appendReturn)
case KMessageBox::Cancel:
return;
case KMessageBox::Yes: {
text = terminalClipboard::sanitizeString(text);
text = terminalPasting::sanitizeString(text);
}
case KMessageBox::No:
break;
......@@ -2152,7 +2152,7 @@ void TerminalDisplay::doPaste(QString text, bool appendReturn)
}
}
auto pasteString = terminalClipboard::prepareStringForPasting(text, appendReturn, bracketedPasteMode());
auto pasteString = terminalPasting::prepareStringForPasting(text, appendReturn, bracketedPasteMode());
if (pasteString.has_value()) {
// perform paste by simulating keypress events
QKeyEvent e(QEvent::KeyPress, 0, Qt::NoModifier, text);
......@@ -2181,11 +2181,26 @@ void TerminalDisplay::copyToX11Selection()
return;
}
const auto &text = _copyTextAsHTML ?
_screenWindow->selectedText(currentDecodingOptions() | Screen::ConvertToHtml)
: _screenWindow->selectedText(currentDecodingOptions());
terminalClipboard::copyToX11Selection(text, _copyTextAsHTML, _autoCopySelectedText);
const QString &text = _screenWindow->selectedText(currentDecodingOptions());
if (text.isEmpty()) {
return;
}
auto mimeData = new QMimeData;
mimeData->setText(text);
if (_copyTextAsHTML) {
mimeData->setHtml(_screenWindow->selectedText(currentDecodingOptions() | Screen::ConvertToHtml));
}
if (QApplication::clipboard()->supportsSelection()) {
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Selection);
}
if (_autoCopySelectedText) {
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
}
}
void TerminalDisplay::copyToClipboard()
......@@ -2650,7 +2665,7 @@ void TerminalDisplay::setSessionController(SessionController* controller)
{
_sessionController = controller;
connect(_sessionController, &Konsole::SessionController::pasteFromClipboardRequested, [this] {
doPaste(terminalClipboard::pasteFromClipboard(), false);
doPaste(terminalPasting::pasteFromClipboard(), false);
});
_headerBar->finishHeaderSetup(controller);
}
......
......@@ -17,9 +17,10 @@
#include <KShell>
#include <KLocalizedString>
#include "TerminalClipboard.h"
#include "TerminalPasting.h"
namespace Konsole::terminalClipboard {
namespace Konsole {
namespace terminalPasting {
// Most code in Konsole uses UTF-32. We're filtering
// UTF-16 here, as all control characters can be represented
......@@ -141,26 +142,5 @@ bool isUnsafe(const QChar c) {
return (c.category() == QChar::Category::Other_Control && std::find(ALLOWLIST.begin(), ALLOWLIST.end(), c.unicode()) != ALLOWLIST.end());
}
void copyToX11Selection(const QString &textToCopy, bool isHtml, bool autoCopySelectedText)
{
if (textToCopy.isEmpty()) {
return;
}
auto mimeData = new QMimeData;
mimeData->setText(textToCopy);
if (isHtml) {
mimeData->setHtml(textToCopy);
}
if (QApplication::clipboard()->supportsSelection()) {
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Selection);
}
if (autoCopySelectedText) {
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
}
}
}
......@@ -15,7 +15,8 @@ class QStringList;
#include <optional>
namespace Konsole::terminalClipboard {
namespace Konsole {
namespace terminalPasting {
/**
* Retrieves the content of the clipboard and preprocesses it for pasting
......@@ -47,6 +48,5 @@ QStringList checkForUnsafeCharacters(const QString &text);
*/
bool isUnsafe(const QChar c);
void copyToX11Selection(const QString &textToCopy, bool copyAsHtml, bool autoCopySelectedText);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment