Skip to content

Commit 713794c

Browse files
committed
fix #71: Fix special key handling
1 parent fa5135c commit 713794c

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/projectscene.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ void ProjectScene::handleKeyPress(Qt::Key key, const QString &text)
7676
m_pressedKeys.insert(key);
7777

7878
if (m_engine) {
79-
if (!text.isEmpty()) {
80-
auto it = SPECIAL_KEY_MAP.find(key);
79+
auto it = SPECIAL_KEY_MAP.find(key);
8180

82-
if (it == SPECIAL_KEY_MAP.cend())
81+
if (it == SPECIAL_KEY_MAP.cend()) {
82+
if (!text.isEmpty())
8383
m_engine->setKeyState(text.toStdString(), true);
84-
else {
85-
KeyEvent event(it->second);
86-
m_engine->setKeyState(event.name(), true);
87-
}
84+
} else {
85+
KeyEvent event(it->second);
86+
// TODO: Use event instead of even.name()
87+
m_engine->setKeyState(event.name(), true);
8888
}
8989

9090
m_engine->setAnyKeyPressed(!m_pressedKeys.empty());
@@ -96,15 +96,15 @@ void ProjectScene::handleKeyRelease(Qt::Key key, const QString &text)
9696
m_pressedKeys.erase(key);
9797

9898
if (m_engine) {
99-
if (!text.isEmpty()) {
100-
auto it = SPECIAL_KEY_MAP.find(key);
99+
auto it = SPECIAL_KEY_MAP.find(key);
101100

102-
if (it == SPECIAL_KEY_MAP.cend())
101+
if (it == SPECIAL_KEY_MAP.cend()) {
102+
if (!text.isEmpty())
103103
m_engine->setKeyState(text.toStdString(), false);
104-
else {
105-
KeyEvent event(it->second);
106-
m_engine->setKeyState(event.name(), false);
107-
}
104+
} else {
105+
KeyEvent event(it->second);
106+
// TODO: Use event instead of even.name()
107+
m_engine->setKeyState(event.name(), false);
108108
}
109109

110110
if (m_pressedKeys.empty()) // avoid setting 'true' when a key is released

test/projectscene/projectscene_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ TEST(ProjectSceneTest, HandleKeyPressAndRelease)
8282
KeyEvent event(scratchKey);
8383
EXPECT_CALL(engine, setKeyState(event.name(), true));
8484
EXPECT_CALL(engine, setAnyKeyPressed(true));
85-
scene.handleKeyPress(qtKey, "test");
85+
scene.handleKeyPress(qtKey, "");
8686

8787
EXPECT_CALL(engine, setKeyState(event.name(), false));
8888
EXPECT_CALL(engine, setAnyKeyPressed(false));
89-
scene.handleKeyRelease(qtKey, "test");
89+
scene.handleKeyRelease(qtKey, "");
9090
}
9191

9292
EXPECT_CALL(engine, setKeyState("a", true));

0 commit comments

Comments
 (0)