From f0315ae4847fcee316df748f1987a6a821a69e90 Mon Sep 17 00:00:00 2001 From: federicovilla55 Date: Thu, 30 Jan 2025 16:54:06 +0100 Subject: [PATCH] Fix Issue #386: Clipboard usage on WebAssembly --- src/console.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/console.cpp b/src/console.cpp index 80adab8f..b050a81b 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -5,6 +5,9 @@ #include +#include +#include + namespace Ripes { Console::Console(QWidget *parent) : QPlainTextEdit(parent) { @@ -70,6 +73,27 @@ void Console::backspace() { } void Console::keyPressEvent(QKeyEvent *e) { + QClipboard *clipboard = QGuiApplication::clipboard(); + + if (e->modifiers() & Qt::ControlModifier) { + switch (e->key()) { + case Qt::Key_C: + if (textCursor().hasSelection()) { + clipboard->setText(textCursor().selectedText()); + } + return; + + case Qt::Key_V: + QString clipboardText = clipboard->text(); + if (!clipboardText.isEmpty()) { + m_buffer += clipboardText; + if (m_localEchoEnabled) + putData(clipboardText.toUtf8()); + } + return; + } + } + switch (e->key()) { case Qt::Key_Left: case Qt::Key_Right: