From de8cd3dfa2f61dffb802b95cdc43e98a7c9f8d55 Mon Sep 17 00:00:00 2001 From: Zeev Rotshtein Date: Tue, 12 May 2026 13:39:39 +0300 Subject: [PATCH] Add option to clear selection on copy This adds an option to the settings to clear the selection after copying. This is useful for when copy is bound to Ctrl-C (smart copy) and you want to restore the regular Ctrl-C action after copying. Without this, it can be confusing when the selection is hidden in the scroll-back buffer and Ctrl-C doesn't seem to work. --- src/profile/Profile.cpp | 1 + src/profile/Profile.h | 2 ++ src/terminalDisplay/TerminalDisplay.cpp | 5 +++++ src/terminalDisplay/TerminalDisplay.h | 1 + src/widgets/EditProfileDialog.cpp | 9 ++++++++- src/widgets/EditProfileDialog.h | 1 + src/widgets/EditProfileMousePage.ui | 10 ++++++++++ 7 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/profile/Profile.cpp b/src/profile/Profile.cpp index 0a13d555f..2f91b9960 100644 --- a/src/profile/Profile.cpp +++ b/src/profile/Profile.cpp @@ -172,6 +172,7 @@ const std::vector Profile::DefaultProperties = { {CopyTextAsHTML, "CopyTextAsHTML", INTERACTION_GROUP, true}, {TrimLeadingSpacesInSelectedText, "TrimLeadingSpacesInSelectedText", INTERACTION_GROUP, false}, {TrimTrailingSpacesInSelectedText, "TrimTrailingSpacesInSelectedText", INTERACTION_GROUP, false}, + {ClearSelectionOnCopy, "ClearSelectionOnCopy", INTERACTION_GROUP, false}, {PasteFromSelectionEnabled, "PasteFromSelectionEnabled", INTERACTION_GROUP, true}, {PasteFromClipboardEnabled, "PasteFromClipboardEnabled", INTERACTION_GROUP, false}, {MiddleClickPasteMode, "MiddleClickPasteMode", INTERACTION_GROUP, Enum::PasteFromX11Selection}, diff --git a/src/profile/Profile.h b/src/profile/Profile.h index 75e398f8b..e33c8c9bb 100644 --- a/src/profile/Profile.h +++ b/src/profile/Profile.h @@ -263,6 +263,8 @@ public: TrimLeadingSpacesInSelectedText, /** (bool) If true, trailing spaces are trimmed in selected text */ TrimTrailingSpacesInSelectedText, + /** (bool) If true, selection is cleared after copying */ + ClearSelectionOnCopy, /** (bool) If true, then dropped URLs will be pasted as text without asking */ DropUrlsAsText, /** (bool) If true, middle mouse button pastes from X Selection */ diff --git a/src/terminalDisplay/TerminalDisplay.cpp b/src/terminalDisplay/TerminalDisplay.cpp index 18a39d292..e1f751ea1 100644 --- a/src/terminalDisplay/TerminalDisplay.cpp +++ b/src/terminalDisplay/TerminalDisplay.cpp @@ -2608,6 +2608,10 @@ void TerminalDisplay::copyToClipboard(Screen::DecodingOptions options) } QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard); + + if (_clearSelection) { + clearSelection(); + } } void TerminalDisplay::pasteFromClipboard(bool appendEnter) @@ -3327,6 +3331,7 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile) _semanticInputClick = profile->semanticInputClick(); _trimLeadingSpaces = profile->property(Profile::TrimLeadingSpacesInSelectedText); _trimTrailingSpaces = profile->property(Profile::TrimTrailingSpacesInSelectedText); + _clearSelection = profile->property(Profile::ClearSelectionOnCopy); _openLinksByDirectClick = profile->property(Profile::OpenLinksByDirectClickEnabled); setMiddleClickPasteMode(Enum::MiddleClickPasteModeEnum(profile->property(Profile::MiddleClickPasteMode))); setCopyTextAsHTML(profile->property(Profile::CopyTextAsHTML)); diff --git a/src/terminalDisplay/TerminalDisplay.h b/src/terminalDisplay/TerminalDisplay.h index e11de4723..75815e4c8 100644 --- a/src/terminalDisplay/TerminalDisplay.h +++ b/src/terminalDisplay/TerminalDisplay.h @@ -802,6 +802,7 @@ private: bool _trimLeadingSpaces = false; // trim leading spaces in selected text bool _trimTrailingSpaces = false; // trim trailing spaces in selected text + bool _clearSelection = false; // clear selection after copying bool _mouseWheelZoom = false; // enable mouse wheel zooming or not int _margin = 1; // the contents margin diff --git a/src/widgets/EditProfileDialog.cpp b/src/widgets/EditProfileDialog.cpp index c171ef80c..3d1653814 100644 --- a/src/widgets/EditProfileDialog.cpp +++ b/src/widgets/EditProfileDialog.cpp @@ -1936,6 +1936,8 @@ void EditProfileDialog::setupMousePage(const Profile::Ptr &profile) connect(_mouseUi->trimLeadingSpacesButton, &QPushButton::toggled, this, &EditProfileDialog::toggleTrimLeadingSpacesInSelectedText); _mouseUi->trimTrailingSpacesButton->setChecked(profile->property(Profile::TrimTrailingSpacesInSelectedText)); connect(_mouseUi->trimTrailingSpacesButton, &QPushButton::toggled, this, &EditProfileDialog::toggleTrimTrailingSpacesInSelectedText); + _mouseUi->clearSelectionButton->setChecked(profile->property(Profile::ClearSelectionOnCopy)); + connect(_mouseUi->clearSelectionButton, &QPushButton::toggled, this, &EditProfileDialog::toggleClearSelectionOnCopy); _mouseUi->openLinksByDirectClickButton->setChecked(profile->property(Profile::OpenLinksByDirectClickEnabled)); connect(_mouseUi->openLinksByDirectClickButton, &QPushButton::toggled, this, &EditProfileDialog::toggleOpenLinksByDirectClick); _mouseUi->dropUrlsAsText->setChecked(profile->property(Profile::DropUrlsAsText)); @@ -2267,6 +2269,11 @@ void EditProfileDialog::toggleTrimTrailingSpacesInSelectedText(bool enable) updateTempProfileProperty(Profile::TrimTrailingSpacesInSelectedText, enable); } +void EditProfileDialog::toggleClearSelectionOnCopy(bool enable) +{ + updateTempProfileProperty(Profile::ClearSelectionOnCopy, enable); +} + void EditProfileDialog::pasteFromX11Selection() { updateTempProfileProperty(Profile::MiddleClickPasteMode, Enum::PasteFromX11Selection); @@ -2372,7 +2379,7 @@ void EditProfileDialog::toggleIgnoreWcWidth(bool ignore) void EditProfileDialog::toggleBadgeEnabled(bool enable) { updateTempProfileProperty(Profile::BadgeEnabled, enable); - + // Enable/disable badge controls based on badge enabled state _appearanceUi->badge_label_1->setEnabled(enable); _appearanceUi->badgeTextEdit->setEnabled(enable); diff --git a/src/widgets/EditProfileDialog.h b/src/widgets/EditProfileDialog.h index 291c3678b..97c003c7e 100644 --- a/src/widgets/EditProfileDialog.h +++ b/src/widgets/EditProfileDialog.h @@ -213,6 +213,7 @@ private Q_SLOTS: void toggleCopyTextAsHTML(bool); void toggleTrimLeadingSpacesInSelectedText(bool); void toggleTrimTrailingSpacesInSelectedText(bool); + void toggleClearSelectionOnCopy(bool); void pasteFromX11Selection(); void pasteFromClipboard(); void toggleAlternateScrolling(bool enable); diff --git a/src/widgets/EditProfileMousePage.ui b/src/widgets/EditProfileMousePage.ui index b4fb82abd..3cf184a2e 100644 --- a/src/widgets/EditProfileMousePage.ui +++ b/src/widgets/EditProfileMousePage.ui @@ -230,6 +230,16 @@ + + + + Clear selection after copying + + + Clear selection + + +