diff --git a/src/libs/solutions/terminal/terminalview.cpp b/src/libs/solutions/terminal/terminalview.cpp index aeaede23d57..2025b4e7546 100644 --- a/src/libs/solutions/terminal/terminalview.cpp +++ b/src/libs/solutions/terminal/terminalview.cpp @@ -283,6 +283,8 @@ void TerminalView::copyToClipboard() qCDebug(selectionLog) << "Copied to clipboard: " << text; setClipboard(text); + + clearSelection(); } void TerminalView::pasteFromClipboard() @@ -310,7 +312,7 @@ std::optional TerminalView::selection() const void TerminalView::clearSelection() { setSelection(std::nullopt); - d->m_surface->sendKey(Qt::Key_Escape); + //d->m_surface->sendKey(Qt::Key_Escape); } void TerminalView::zoomIn() diff --git a/src/plugins/terminal/shortcutmap.cpp b/src/plugins/terminal/shortcutmap.cpp index 72023e808a0..436757fd256 100644 --- a/src/plugins/terminal/shortcutmap.cpp +++ b/src/plugins/terminal/shortcutmap.cpp @@ -9,6 +9,7 @@ #include +#include #include #include #include @@ -216,8 +217,6 @@ QKeySequence::SequenceMatch ShortcutMap::state() */ bool ShortcutMap::tryShortcut(QKeyEvent *e) { - Q_D(ShortcutMap); - if (e->key() == Qt::Key_unknown) return false; @@ -234,14 +233,8 @@ bool ShortcutMap::tryShortcut(QKeyEvent *e) // but we need to say we did, so that we get the follow-up key-presses. return true; case QKeySequence::ExactMatch: { - // Save number of identical matches before dispatching - // to keep ShortcutMap and tryShortcut reentrant. - const int identicalMatches = d->identicals.size(); resetState(); - dispatchEvent(e); - // If there are no identicals we've only found disabled shortcuts, and - // shouldn't say that we handled the event. - return identicalMatches > 0; + return dispatchEvent(e); } } #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) @@ -510,11 +503,11 @@ QList ShortcutMap::matches() const /*! \internal Dispatches QShortcutEvents to widgets who grabbed the matched key sequence. */ -void ShortcutMap::dispatchEvent(QKeyEvent *e) +bool ShortcutMap::dispatchEvent(QKeyEvent *e) { Q_D(ShortcutMap); if (!d->identicals.size()) - return; + return false; const QKeySequence &curKey = d->identicals.at(0)->keyseq; if (d->prevSequence != curKey) { @@ -541,7 +534,7 @@ void ShortcutMap::dispatchEvent(QKeyEvent *e) // Don't trigger shortcut if we're autorepeating and the shortcut is // grabbed with not accepting autorepeats. if (!next || (e->isAutoRepeat() && !next->autorepeat)) - return; + return false; // Dispatch next enabled if (lcShortcutMap().isDebugEnabled()) { if (ambiguousShortcuts.size() > 1) { @@ -559,6 +552,12 @@ void ShortcutMap::dispatchEvent(QKeyEvent *e) } QShortcutEvent se(next->keyseq, next->id, enabledShortcuts > 1); QCoreApplication::sendEvent(const_cast(next->owner), &se); + + QAction *action = qobject_cast(next->owner); + if (action) + return action->isEnabled(); + + return true; } } // namespace Terminal::Internal diff --git a/src/plugins/terminal/shortcutmap.h b/src/plugins/terminal/shortcutmap.h index 956c3b5c9e7..3433a4d172d 100644 --- a/src/plugins/terminal/shortcutmap.h +++ b/src/plugins/terminal/shortcutmap.h @@ -40,7 +40,7 @@ public: private: void resetState(); QKeySequence::SequenceMatch nextState(QKeyEvent *e); - void dispatchEvent(QKeyEvent *e); + bool dispatchEvent(QKeyEvent *e); QKeySequence::SequenceMatch find(QKeyEvent *e, int ignoredModifiers = 0); QKeySequence::SequenceMatch matches(const QKeySequence &seq1, const QKeySequence &seq2) const; diff --git a/src/plugins/terminal/terminalwidget.cpp b/src/plugins/terminal/terminalwidget.cpp index c648406e39c..7e4987e3794 100644 --- a/src/plugins/terminal/terminalwidget.cpp +++ b/src/plugins/terminal/terminalwidget.cpp @@ -605,13 +605,21 @@ void TerminalWidget::initActions() moveCursorWordRight.setText(Tr::tr("Move Cursor Word Right")); close.setText(Tr::tr("Close Terminal")); - ActionManager::registerAction(©, Constants::COPY, context) - ->setDefaultKeySequences({QKeySequence( - HostOsInfo::isMacHost() ? QLatin1String("Ctrl+C") : QLatin1String("Ctrl+Shift+C"))}); + auto copyCmd = ActionManager::registerAction(©, Constants::COPY, context); + auto pasteCmd = ActionManager::registerAction(&paste, Constants::PASTE, context); - ActionManager::registerAction(&paste, Constants::PASTE, context) - ->setDefaultKeySequences({QKeySequence( - HostOsInfo::isMacHost() ? QLatin1String("Ctrl+V") : QLatin1String("Ctrl+Shift+V"))}); + if (HostOsInfo::isMacHost()) { + copyCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+C"))); + pasteCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+V"))); + } else if (HostOsInfo::isLinuxHost()) { + copyCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+Shift+C"))); + pasteCmd->setDefaultKeySequence(QKeySequence(QLatin1String("Ctrl+Shift+V"))); + } else if (HostOsInfo::isWindowsHost()) { + copyCmd->setDefaultKeySequences( + {QKeySequence(QLatin1String("Ctrl+C")), QKeySequence(QLatin1String("Ctrl+Shift+C"))}); + pasteCmd->setDefaultKeySequences( + {QKeySequence(QLatin1String("Ctrl+V")), QKeySequence(QLatin1String("Ctrl+Shift+V"))}); + } ActionManager::registerAction(&clearSelection, Constants::CLEARSELECTION, context);