Skip to content

Commit

Permalink
Issue 170: Send <C-6> as <C-^>
Browse files Browse the repository at this point in the history
The key event <C-6> should be sent as <C-^>. When other modifiers are present
(Shift, Meta) they should be ignored. For example, <C-S-^> should be <C-^>
instead.
  • Loading branch information
jgehrig committed Apr 16, 2020
1 parent 9c21aef commit 414d97b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/gui/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ QString convertKey(const QKeyEvent& ev) noexcept
return ToKeyString(GetModifierPrefix(modNoShift), "lt");
}

// Issue#170: Normalize modifiers, CTRL+^ always sends as <C-^>
const bool isCaretKey{ key == Qt::Key_6 || key == Qt::Key_AsciiCircum };
if (isCaretKey && mod & ControlModifier()) {
const Qt::KeyboardModifiers modNoShiftMeta{
mod & ~Qt::KeyboardModifier::ShiftModifier & ~CmdModifier() };
return ToKeyString(GetModifierPrefix(modNoShiftMeta), "^");
}

if (text == "\\") {
return ToKeyString(GetModifierPrefix(mod), "Bslash");
}
Expand Down
14 changes: 14 additions & 0 deletions test/tst_input_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ private slots:
void LessThanModifierKeys() noexcept;
void SpecialKeys() noexcept;
void KeyboardLayoutUnicodeHexInput() noexcept;
void CtrlCaretWellFormed() noexcept;
};

void TestInputMac::AltSpecialCharacters() noexcept
Expand Down Expand Up @@ -75,5 +76,18 @@ void TestInputMac::KeyboardLayoutUnicodeHexInput() noexcept
QCOMPARE(NeovimQt::Input::convertKey(evCtrlAltShiftA), QString{ "<C-A-A>" });
}

void TestInputMac::CtrlCaretWellFormed() noexcept
{
QKeyEvent evCtrl6{ QEvent::KeyPress, Qt::Key_6, Qt::MetaModifier };
QCOMPARE(NeovimQt::Input::convertKey(evCtrl6), QString{ "<C-^>" });

QKeyEvent evCtrlShift6{ QEvent::KeyPress, Qt::Key_AsciiCircum, Qt::MetaModifier | Qt::ShiftModifier };
QCOMPARE(NeovimQt::Input::convertKey(evCtrlShift6), QString{ "<C-^>" });

QKeyEvent evCtrlShiftMeta6{ QEvent::KeyPress, Qt::Key_AsciiCircum,
Qt::MetaModifier | Qt::ShiftModifier | Qt::ControlModifier };
QCOMPARE(NeovimQt::Input::convertKey(evCtrlShiftMeta6), QString{ "<C-^>" });
}

#include "tst_input_mac.moc"
QTEST_MAIN(TestInputMac)
14 changes: 14 additions & 0 deletions test/tst_input_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TestInputUnix : public QObject
private slots:
void LessThanModifierKeys() noexcept;
void SpecialKeys() noexcept;
void CtrlCaretWellFormed() noexcept;
};

void TestInputUnix::LessThanModifierKeys() noexcept
Expand Down Expand Up @@ -43,5 +44,18 @@ void TestInputUnix::SpecialKeys() noexcept
}
}

void TestInputUnix::CtrlCaretWellFormed() noexcept
{
QKeyEvent evCtrl6{ QEvent::KeyPress, Qt::Key_6, Qt::ControlModifier, { "\u001E" } };
QCOMPARE(NeovimQt::Input::convertKey(evCtrl6), QString{ "<C-^>" });

QKeyEvent evCtrlShift6{ QEvent::KeyPress, Qt::Key_AsciiCircum, Qt::ControlModifier | Qt::ShiftModifier, { "\u001E" } };
QCOMPARE(NeovimQt::Input::convertKey(evCtrlShift6), QString{ "<C-^>" });

QKeyEvent evCtrlShiftMeta6{ QEvent::KeyPress, Qt::Key_AsciiCircum,
Qt::MetaModifier | Qt::ShiftModifier | Qt::ControlModifier , { "\u001E" } };
QCOMPARE(NeovimQt::Input::convertKey(evCtrlShiftMeta6), QString{ "<C-^>" });
}

#include "tst_input_unix.moc"
QTEST_MAIN(TestInputUnix)
10 changes: 10 additions & 0 deletions test/tst_input_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TestInputWin32 : public QObject
private slots:
void LessThanModifierKeys() noexcept;
void SpecialKeys() noexcept;
void CtrlCaretWellFormed() noexcept;
};

void TestInputWin32::LessThanModifierKeys() noexcept
Expand Down Expand Up @@ -43,5 +44,14 @@ void TestInputWin32::SpecialKeys() noexcept
}
}

void TestInputWin32::CtrlCaretWellFormed() noexcept
{
QKeyEvent evCtrl6{ QEvent::KeyPress, Qt::Key_6, Qt::ControlModifier, { "6" } };
QCOMPARE(NeovimQt::Input::convertKey(evCtrl6), QString{ "<C-^>" });

QKeyEvent evCtrlShift6{ QEvent::KeyPress, Qt::Key_AsciiCircum, Qt::ControlModifier | Qt::ShiftModifier, { "\u001E" } };
QCOMPARE(NeovimQt::Input::convertKey(evCtrlShift6), QString{ "<C-^>" });
}

#include "tst_input_win32.moc"
QTEST_MAIN(TestInputWin32)

0 comments on commit 414d97b

Please sign in to comment.