Skip to content

Commit

Permalink
Issue 917: Cannot map <C-Space> on Linux
Browse files Browse the repository at this point in the history
Linux sends text as "\u0000" in this scenario.

This messes up our detection logic for Issue#864. Add cleanup logic.
  • Loading branch information
jgehrig committed Aug 14, 2021
1 parent 19b08c4 commit 56ad7e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/gui/input.cpp
Expand Up @@ -174,6 +174,11 @@ QString convertKey(const QKeyEvent& ev) noexcept
return keypadKeys.value(key).arg(GetModifierPrefix(mod));
}

// Issue#917: On Linux, Control + Space sends text as "\u0000"
if (key == Qt::Key_Space && text.size() > 0 && !text.at(0).isPrint()) {
text = " ";
}

// Issue#864: Some international layouts insert accents (~^`) on Key_Space
if (key == Qt::Key_Space && !text.isEmpty() && text != " ") {
if (mod != Qt::NoModifier) {
Expand Down
8 changes: 8 additions & 0 deletions test/tst_input_unix.cpp
Expand Up @@ -13,6 +13,7 @@ private slots:
void CtrlCaretWellFormed() noexcept;
void ShiftModifierLetter() noexcept;
void GermanKeyboardLayout() noexcept;
void ControlSpace() noexcept;
};

void TestInputUnix::LessThanModifierKeys() noexcept
Expand Down Expand Up @@ -97,5 +98,12 @@ void TestInputUnix::GermanKeyboardLayout() noexcept
QCOMPARE(NeovimQt::Input::convertKey(evOptionPlus), QString{ "~" });
}

void TestInputUnix::ControlSpace() noexcept
{
// Intentionally written with QStringLiteral, other alternatives do not create the same QKeyEvent
QKeyEvent evControlSpace{ QEvent::KeyPress, Qt::Key_Space, Qt::ControlModifier, QStringLiteral( "\u0000" ) };
QCOMPARE(NeovimQt::Input::convertKey(evControlSpace), QString{ "<C-Space>" });
}

#include "tst_input_unix.moc"
QTEST_MAIN(TestInputUnix)

0 comments on commit 56ad7e5

Please sign in to comment.