Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Fix pasting into Type Tool edit box

manongjohndc44edb30165
diff --git a/toonz/sources/tnztools/typetool.cpp b/toonz/sources/tnztools/typetool.cpp
index 3b7c9d2cc..0eb3455bf 100644
--- a/toonz/sources/tnztools/typetool.cpp
+++ b/toonz/sources/tnztools/typetool.cpp
@@ -35,6 +35,9 @@
// For Qt translation support
#include <QCoreApplication>
+#include <QClipboard>
+#include <QApplication>
+#include <QMimeData>
//#include "tw/message.h"
@@ -1511,6 +1514,20 @@ void TypeTool::deleteKey() {
bool TypeTool::keyDown(QKeyEvent *event) {
QString text = event->text();
if ((event->modifiers() & Qt::ShiftModifier)) text.toUpper();
+
+ std::string keyStr =
+ QKeySequence(event->key() + event->modifiers()).toString().toStdString();
+ QAction *action = CommandManager::instance()->getActionFromShortcut(keyStr);
+ if (action) {
+ std::string actionId = CommandManager::instance()->getIdFromAction(action);
+ if (actionId == "MI_Paste") {
+ QClipboard *clipboard = QApplication::clipboard();
+ const QMimeData *mimeData = clipboard->mimeData();
+ if (!mimeData->hasText()) return true;
+ text = mimeData->text().replace('\n', '\r');
+ }
+ }
+
std::wstring unicodeChar = text.toStdWString();
// per sicurezza
@@ -1618,9 +1635,10 @@ bool TypeTool::keyDown(QKeyEvent *event) {
default:
if (unicodeChar.empty()) return false;
replaceText(unicodeChar, m_cursorIndex, m_cursorIndex);
- m_cursorIndex++;
- m_preeditRange = std::make_pair(m_cursorIndex, m_cursorIndex);
- updateCharPositions(m_cursorIndex - 1);
+ int startIndex = m_cursorIndex + 1;
+ m_cursorIndex += unicodeChar.size();
+ m_preeditRange = std::make_pair(startIndex, m_cursorIndex);
+ updateCharPositions(startIndex - 1);
}
invalidate();