Skip to content

Commit

Permalink
fix #63301: comma shortcuts now save
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhieuvu committed Mar 22, 2019
1 parent 4b2c943 commit 3bcc078
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions mscore/shortcut.cpp
Expand Up @@ -4050,7 +4050,7 @@ void Shortcut::write(XmlWriter& xml) const
if (_standardKey != QKeySequence::UnknownKey)
xml.tag("std", QString("%1").arg(_standardKey));
for (QKeySequence ks : _keys)
xml.tag("seq", Shortcut::keySeqToString(ks, QKeySequence::PortableText));
xml.tag("seq", Shortcut::keySeqToString(ks, QKeySequence::PortableText, true));
xml.etag();
}

Expand Down Expand Up @@ -4280,7 +4280,7 @@ void Shortcut::reset()
static const QString numPadPrefix("NumPad+");
static const int NUMPADPREFIX_SIZE = 7; // the length in chars of the above string

QString Shortcut::keySeqToString(const QKeySequence& keySeq, QKeySequence::SequenceFormat fmt)
QString Shortcut::keySeqToString(const QKeySequence& keySeq, QKeySequence::SequenceFormat fmt, bool escapeKeyStr /* = false */)
{
QString s;
for (int i = 0; i < KEYSEQ_SIZE; ++i) {
Expand All @@ -4293,8 +4293,12 @@ QString Shortcut::keySeqToString(const QKeySequence& keySeq, QKeySequence::Seque
s += numPadPrefix;
code &= ~Qt::KeypadModifier;
}
QKeySequence kSeq(code);
s += kSeq.toString(fmt);
QString kStr = QKeySequence(code).toString(fmt);
if (escapeKeyStr) {
kStr.replace("\\", "\\\\");
kStr.replace(",", "\\,");
}
s += kStr;
}
return s;
}
Expand All @@ -4305,12 +4309,16 @@ QKeySequence Shortcut::keySeqFromString(const QString& str, QKeySequence::Sequen
for (i = 0; i < KEYSEQ_SIZE; ++i)
code[i] = 0;

QStringList strList = str.split(",", QString::SkipEmptyParts, Qt::CaseSensitive);
QStringList strList = str.split(QRegularExpression("(?<!\\\\),|(?<=\\\\\\\\),"), QString::SkipEmptyParts);
//split based on commas that are not preceded by a single slash; two is okay
//original regex: (?<!\\),|(?<=\\\\),

i = 0;
for (const QString& s : strList) {
QString keyStr = s.trimmed();
if( keyStr.startsWith(numPadPrefix, Qt::CaseInsensitive) ) {
if (keyStr.contains("\\"))
keyStr.remove(keyStr.length() - 2, 1); //remove escaped characters which will always be second to last
if (keyStr.startsWith(numPadPrefix, Qt::CaseInsensitive) ) {
code[i] += Qt::KeypadModifier;
keyStr.remove(0, NUMPADPREFIX_SIZE);
}
Expand Down
2 changes: 1 addition & 1 deletion mscore/shortcut.h
Expand Up @@ -181,7 +181,7 @@ class Shortcut {
static QActionGroup* getActionGroupForWidget(MsWidget w);
static QActionGroup* getActionGroupForWidget(MsWidget w, Qt::ShortcutContext newShortcutContext);

static QString keySeqToString(const QKeySequence& keySeq, QKeySequence::SequenceFormat fmt);
static QString keySeqToString(const QKeySequence& keySeq, QKeySequence::SequenceFormat fmt, bool escapeKeyStr = false);
static QKeySequence keySeqFromString(const QString& str, QKeySequence::SequenceFormat fmt);
};

Expand Down

0 comments on commit 3bcc078

Please sign in to comment.