diff --git a/klipper/history.cpp b/klipper/history.cpp index 9640c23b0..36b00e90e 100644 --- a/klipper/history.cpp +++ b/klipper/history.cpp @@ -140,8 +140,19 @@ void History::slotMoveToTop(QAction* action) { } void History::slotMoveToTop(const QByteArray& uuid) { + const QModelIndex item = m_model->indexOf(uuid); + if (item.isValid() && item.row() == 0) { + // The item is already at the top, but it still may be not be set as the actual clipboard + // contents, normally this happens if the item is only in the X11 mouse selection but + // not in the Ctrl+V clipboard. + emit topChanged(); + m_topIsUserSelected = true; + emit topIsUserSelectedSet(); + return; + } m_model->moveToTop(uuid); m_topIsUserSelected = true; + emit topIsUserSelectedSet(); } void History::setMaxSize( unsigned max_size ) { diff --git a/klipper/history.h b/klipper/history.h index 7690ffdc1..7001450fc 100644 --- a/klipper/history.h +++ b/klipper/history.h @@ -136,6 +136,7 @@ Q_SIGNALS: */ void topChanged(); + void topIsUserSelectedSet(); private: /** diff --git a/klipper/klipper.cpp b/klipper/klipper.cpp index 4703227ef..30f3e5815 100644 --- a/klipper/klipper.cpp +++ b/klipper/klipper.cpp @@ -117,6 +117,7 @@ Klipper::Klipper(QObject* parent, const KSharedConfigPtr& config, KlipperMode mo m_popup = new KlipperPopup(m_history); m_popup->setShowHelp(m_mode == KlipperMode::Standalone); connect(m_history, &History::changed, m_popup, &KlipperPopup::slotHistoryChanged); + connect(m_history, &History::topIsUserSelectedSet, m_popup, &KlipperPopup::slotTopIsUserSelectedSet); // we need that collection, otherwise KToggleAction is not happy :} m_collection = new KActionCollection( this ); diff --git a/klipper/klipperpopup.cpp b/klipper/klipperpopup.cpp index 12d3205d9..e0d35e56c 100644 --- a/klipper/klipperpopup.cpp +++ b/klipper/klipperpopup.cpp @@ -175,6 +175,13 @@ void KlipperPopup::rebuild( const QString& filter ) { m_dirty = false; } +void KlipperPopup::slotTopIsUserSelectedSet() { + if ( !m_dirty && m_nHistoryItems > 0 && history()->topIsUserSelected() ) { + actions().at(TOP_HISTORY_ITEM_INDEX)->setCheckable(true); + actions().at(TOP_HISTORY_ITEM_INDEX)->setChecked(true); + } +} + void KlipperPopup::plugAction( QAction* action ) { m_actions.append(action); } diff --git a/klipper/klipperpopup.h b/klipper/klipperpopup.h index 3ba3d97b3..cf70ab977 100644 --- a/klipper/klipperpopup.h +++ b/klipper/klipperpopup.h @@ -61,6 +61,7 @@ public: } public Q_SLOTS: void slotHistoryChanged() { m_dirty = true; } + void slotTopIsUserSelectedSet(); void slotAboutToShow(); /** * set the top history item active, to easy kb navigation