Skip to content

Commit

Permalink
Fix Issue #386: Clipboard usage on WebAssembly
Browse files Browse the repository at this point in the history
  • Loading branch information
federicovilla55 committed Jan 30, 2025
1 parent c0b34a6 commit f0315ae
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include <QScrollBar>

#include <QClipboard>
#include <QGuiApplication>

namespace Ripes {

Console::Console(QWidget *parent) : QPlainTextEdit(parent) {
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f0315ae

Please sign in to comment.