Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 170: Send <C-6> as <C-^> #682

Merged
merged 1 commit into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)