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.
This commit is contained in:
Zeev Rotshtein
2026-05-12 13:39:39 +03:00
committed by Christoph Cullmann
parent a428d65fe2
commit de8cd3dfa2
7 changed files with 28 additions and 1 deletions

View File

@@ -172,6 +172,7 @@ const std::vector<Profile::PropertyInfo> 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},

View File

@@ -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 */

View File

@@ -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<bool>(Profile::TrimLeadingSpacesInSelectedText);
_trimTrailingSpaces = profile->property<bool>(Profile::TrimTrailingSpacesInSelectedText);
_clearSelection = profile->property<bool>(Profile::ClearSelectionOnCopy);
_openLinksByDirectClick = profile->property<bool>(Profile::OpenLinksByDirectClickEnabled);
setMiddleClickPasteMode(Enum::MiddleClickPasteModeEnum(profile->property<int>(Profile::MiddleClickPasteMode)));
setCopyTextAsHTML(profile->property<bool>(Profile::CopyTextAsHTML));

View File

@@ -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

View File

@@ -1936,6 +1936,8 @@ void EditProfileDialog::setupMousePage(const Profile::Ptr &profile)
connect(_mouseUi->trimLeadingSpacesButton, &QPushButton::toggled, this, &EditProfileDialog::toggleTrimLeadingSpacesInSelectedText);
_mouseUi->trimTrailingSpacesButton->setChecked(profile->property<bool>(Profile::TrimTrailingSpacesInSelectedText));
connect(_mouseUi->trimTrailingSpacesButton, &QPushButton::toggled, this, &EditProfileDialog::toggleTrimTrailingSpacesInSelectedText);
_mouseUi->clearSelectionButton->setChecked(profile->property<bool>(Profile::ClearSelectionOnCopy));
connect(_mouseUi->clearSelectionButton, &QPushButton::toggled, this, &EditProfileDialog::toggleClearSelectionOnCopy);
_mouseUi->openLinksByDirectClickButton->setChecked(profile->property<bool>(Profile::OpenLinksByDirectClickEnabled));
connect(_mouseUi->openLinksByDirectClickButton, &QPushButton::toggled, this, &EditProfileDialog::toggleOpenLinksByDirectClick);
_mouseUi->dropUrlsAsText->setChecked(profile->property<bool>(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);

View File

@@ -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);

View File

@@ -230,6 +230,16 @@
</property>
</widget>
</item>
<item row="12" column="1">
<widget class="QCheckBox" name="clearSelectionButton">
<property name="toolTip">
<string>Clear selection after copying</string>
</property>
<property name="text">
<string>Clear selection</string>
</property>
</widget>
</item>
</layout>
</item>
<item>