Skip to content

Commit

Permalink
Improve ignore single/no character command
Browse files Browse the repository at this point in the history
Avoids selection-clipboard synchronization and showing a popup for
clipboard/selection with text containing single or no characters.
  • Loading branch information
hluk committed Aug 7, 2022
1 parent 195851e commit 7ab9977
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/common/predefinedcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,39 @@ QVector<Command> predefinedCommands()

c = newCommand(&commands);
c->name = AddCommandDialog::tr("Ignore items with no or single character");
c->input = mimeText;
c->re = QRegularExpression("^\\s*\\S?\\s*$");
c->icon = QString(QChar(IconExclamationCircle));
c->remove = true;
c->automatic = true;
c->cmd = R"(function hasEmptyOrSingleCharText() {
if (hasData(mimeText)) {
var text = str(data(mimeText));
if (text.match(/^\s*.?\s*$/)) {
return true;
}
}
return false;
}
var onClipboardChanged_ = onClipboardChanged;
onClipboardChanged = function() {
if (!hasEmptyOrSingleCharText()) {
onClipboardChanged_();
}
}
var synchronizeFromSelection_ = synchronizeFromSelection;
synchronizeFromSelection = function() {
if (!hasEmptyOrSingleCharText()) {
synchronizeFromSelection_();
}
}
var synchronizeToSelection_ = synchronizeToSelection;
synchronizeToSelection = function() {
if (!hasEmptyOrSingleCharText()) {
synchronizeToSelection_();
}
}
)";
c->isScript = true;

c = newCommand(&commands);
c->name = AddCommandDialog::tr("Open in &Browser");
Expand Down

0 comments on commit 7ab9977

Please sign in to comment.