Skip to content

Commit c6c81e7

Browse files
committed
X11: Fix selection sync in predefined command
Avoids synchronizing empty text or single character from/to X11 selection with "Ignore items with no or single character" predefined command.
1 parent b6ef63d commit c6c81e7

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/common/predefinedcommands.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,27 @@ QVector<Command> predefinedCommands()
4848
c->icon = QString(QChar(IconCircleExclamation));
4949
c->cmd = R"(function hasEmptyOrSingleCharText() {
5050
if (dataFormats().includes(mimeText)) {
51-
var text = str(data(mimeText));
52-
if (text.match(/^\s*.?\s*$/)) {
51+
const text = str(data(mimeText));
52+
if (/^\s*.?\s*$/.test(text)) {
5353
serverLog('Ignoring text with single or no character');
5454
return true;
5555
}
5656
}
5757
return false;
5858
}
5959
60-
var onClipboardChanged_ = onClipboardChanged;
61-
onClipboardChanged = function() {
62-
if (!hasEmptyOrSingleCharText()) {
63-
onClipboardChanged_();
64-
}
65-
}
66-
67-
var synchronizeFromSelection_ = synchronizeFromSelection;
68-
synchronizeFromSelection = function() {
69-
if (!hasEmptyOrSingleCharText()) {
70-
synchronizeFromSelection_();
60+
function overrideFunction(fn) {
61+
const oldFn = global[fn];
62+
global[fn] = function() {
63+
if (!hasEmptyOrSingleCharText()) {
64+
oldFn();
65+
}
7166
}
7267
}
7368
74-
var synchronizeToSelection_ = synchronizeToSelection;
75-
synchronizeToSelection = function() {
76-
if (!hasEmptyOrSingleCharText()) {
77-
synchronizeToSelection_();
78-
}
79-
}
69+
overrideFunction('onClipboardChanged');
70+
overrideFunction('provideClipboard');
71+
overrideFunction('provideSelection');
8072
)";
8173
c->isScript = true;
8274

0 commit comments

Comments
 (0)