Commit 94d36078 authored by Lukas Holecek's avatar Lukas Holecek Committed by hjk

fakevim: Better input key comparison

Change-Id: I47ca07f8ef54f8f7f38d467ea0aa2c087ee95a37
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 0a5e392a
......@@ -1632,7 +1632,7 @@ void FakeVimPlugin::test_map()
data.doCommand("noremap l k|noremap k j|noremap j h");
KEYS("ikkk<esc>", "kk" X "k");
KEYS("rj", "kk" X "j");
data.doCommand("unmap l k|unmap k j|unmap j h");
data.doCommand("unmap l|unmap k|unmap j");
NOT_IMPLEMENTED
// <C-o>
......
......@@ -601,7 +601,7 @@ public:
m_key = x.toUpper().unicode();
}
Input(int k, int m, const QString &t)
Input(int k, int m, const QString &t = QString())
: m_key(k), m_modifiers(cleanModifier(m)), m_text(t)
{
// On Mac, QKeyEvent::text() returns non-empty strings for
......@@ -610,6 +610,13 @@ public:
// FIXME: Check the real conditions.
if (m_text.size() == 1 && m_text.at(0).unicode() < ' ')
m_text.clear();
// Set text only if input is ascii key without control modifier.
if (m_text.isEmpty() && k <= 0x7f && (m & (HostOsInfo::controlModifier())) == 0) {
QChar c = QChar::fromAscii(k);
m_text = QString((m & ShiftModifier) != 0 ? c.toUpper() : c.toLower());
}
// m_xkey is only a cache.
m_xkey = (m_text.size() == 1 ? m_text.at(0).unicode() : m_key);
}
......@@ -661,18 +668,24 @@ public:
return m_modifiers == Qt::ShiftModifier && m_xkey == c;
}
bool operator==(const Input &a) const
bool operator<(const Input &a) const
{
return m_key == a.m_key && m_modifiers == a.m_modifiers;
if (m_key != a.m_key)
return m_key < a.m_key;
// Text for some mapped key cannot be determined (e.g. <C-J>) so if text is not set for
// one of compared keys ignore it.
if (!m_text.isEmpty() && !a.m_text.isEmpty())
return m_text < a.m_text;
return m_modifiers < a.m_modifiers;
}
bool operator!=(const Input &a) const { return !operator==(a); }
bool operator<(const Input &a) const
bool operator==(const Input &a) const
{
return m_key < a.m_key || m_modifiers < a.m_modifiers;
return !(*this < a || a < *this);
}
bool operator!=(const Input &a) const { return !operator==(a); }
QString text() const { return m_text; }
QChar asChar() const
......@@ -843,14 +856,14 @@ static Input parseVimKeyName(const QString &keyName)
if (key.length() == 1) {
// simple character
QChar c = key.at(0).toUpper();
return Input(c.unicode(), mods, QString(c));
return Input(c.unicode(), mods);
}
// find key name
static const QMap<QString, int> k = vimKeyNames();
QMap<QString, int>::ConstIterator it = k.constFind(key.toUpper());
if (it != k.end())
return Input(*it, mods, *it <= 0x7f ? QString(QChar::fromLatin1(*it)) : QString(""));
return Input(*it, mods);
}
return Input();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment