Skip to content

Commit

Permalink
fix autotype custom attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheZ3ro committed Mar 4, 2018
1 parent d3a8051 commit 3d61efa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/autotype/AutoType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,14 +659,15 @@ bool AutoType::checkSyntax(const QString& string)
QString delay = "DELAY=\\d+";
QString beep = "BEEP\\s\\d+\\s\\d+";
QString vkey = "VKEY(?:-[EN]X)?\\s\\w+";
QString customAttributes = "S:(?:[^\\{\\}])+";

// these chars aren't in parentheses
QString shortcutKeys = "[\\^\\%~\\+@]";
// a normal string not in parentheses
QString fixedStrings = "[^\\^\\%~\\+@\\{\\}]*";

QRegularExpression autoTypeSyntax("^(?:" + shortcutKeys + "|" + fixedStrings + "|\\{(?:" + normalCommands + "|" + specialLiterals +
"|" + functionKeys + "|" + numpad + "|" + delay + "|" + beep + "|" + vkey + ")\\})*$",
"|" + functionKeys + "|" + numpad + "|" + delay + "|" + beep + "|" + vkey + ")\\}|\\{" + customAttributes + "\\})*$",
QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch match = autoTypeSyntax.match(string);
return match.hasMatch();
Expand Down
9 changes: 9 additions & 0 deletions tests/TestAutoType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ void TestAutoType::testAutoTypeSyntaxChecks()

QCOMPARE(true, AutoType::checkSyntax("{NUMPAD1 3}"));

QCOMPARE(true, AutoType::checkSyntax("{S:SPECIALTOKEN}"));
QCOMPARE(true, AutoType::checkSyntax("{S:SPECIAL TOKEN}"));
QCOMPARE(true, AutoType::checkSyntax("{S:SPECIAL_TOKEN}"));
QCOMPARE(true, AutoType::checkSyntax("{S:SPECIAL-TOKEN}"));
QCOMPARE(true, AutoType::checkSyntax("{S:SPECIAL:TOKEN}"));
QCOMPARE(true, AutoType::checkSyntax("{S:SPECIAL_TOKEN}{ENTER}"));
QCOMPARE(true, AutoType::checkSyntax("{S:FOO}{S:HELLO WORLD}"));
QCOMPARE(false, AutoType::checkSyntax("{S:SPECIAL_TOKEN{}}"));

QCOMPARE(true, AutoType::checkSyntax("{BEEP 3 3}"));
QCOMPARE(false, AutoType::checkSyntax("{BEEP 3}"));

Expand Down

0 comments on commit 3d61efa

Please sign in to comment.