-
Notifications
You must be signed in to change notification settings - Fork 171
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
Refactor Keyboard Input Code, Improve Test Coverage, Fix Bugs #612
Conversation
I have seen this same issue before in Pull Request #573. Perhaps this is an unreliable UnitTest?
Both changes trigger the issue, but don't touch neovimconnector in any meaningful way. Neither change shows any observable build or runtime issues. I am not sure what is happening here... |
Reran a couple of times locally and in TravisCI:
Aah the fun this will be ... |
From #134 it seems that on Mac OS X I was seeing key: < with modifier Shift and text: <. This was a while back and probably in a pt_PT layout though. |
Gahhh! The failure was deterministic for the SVG changes too, but only on MacOS. Very Strange. I have MacOS VM that I can debug on. This will be interesting indeed... |
Mmmm, there is also the possibility that there is some issue with CI. I have enabled daily builds for the master branch. I'll try to test it a bit too in #615 |
With the SVG changes, I could reproduce the issue locally on MacOS every time. |
Based on looking at these failures in the debugger, my best guess is unreliable timeout/wait logic causes these failures. In all cases In the passing tests, a breakpoint at I can make NeovimConnector* NeovimConnector::connectToHost(const QString& host, int port)
...
s->connectToHost(host, port);
+ s->waitForConnected();
return c;
} void connectToNeovimTCP() {
...
// The signal might be emited before we get to connect
- SPYWAIT(onError);
+ SPYWAIT(onError, 50000 /*msec*/);
QCOMPARE(c->errorCause(), NeovimConnector::SocketError);
c->deleteLater();
} Maybe we can improve the test reliability by adjusting timeout values... There are also a few very slow tests; maybe this is a good opportunity to improve the test performance too? |
f79c289
to
17c27f2
Compare
The last commit fixes the Travis error. AppVeyor is failing to download a nightly release of Neovim. For Travies, MacOS takes ~50 seconds to timeout for the TCP socket sent to Adding a 2-minute timeout resolves the issue, Do you have any opinions on such a solution? Other that the long timeout, I don't like how The test could then become: SPYWAIT(onError, 2500 /*msec*/);
QVERIFY(c->errorCause() == NeovimConnector::SocketError ||
c->errorCause() == NeovimConnector::NotConnected); |
I also improved the test performance. Only a handful of SPYWAITS were causing most of the spinlock. Manually commenting and lowering the timeout value for these cases seems worthwhile. I can spin off these changes, or include them in their own commit with this Pull Request. |
ACK I'm good with merging the fix along with this CR. |
39e5d52
to
acd46a6
Compare
That's all I've got for this PR, I think it is ready... Let me know if you feel it needs anything else :) |
No control / command / meta combos are working for me with this PR. On macOS Catalina, running ...
... and the focus doesn't move between splits. |
Thanks @mikew! MacOS is a difficult platform for me to debug/test on, since I don't own a Mac... I would like to write a unit test for this scenario, so it isn't regressed in the future. Could you provide some debug output for a few of the key sequences in question? This patch will provide debug output for the diff -r a4b43d295f61 src/gui/shell.cpp
--- a/src/gui/shell.cpp Mon Dec 16 02:23:57 2019 -0500
+++ b/src/gui/shell.cpp Thu Dec 26 10:58:19 2019 -0500
@@ -1070,6 +1070,8 @@
this->setCursor(Qt::BlankCursor);
}
+ qDebug() << "QKeyEvent ev:" << ev;
+
const QString inp = Input::convertKey(ev->text(), ev->key(), ev->modifiers());
if (inp.isEmpty()) {
QWidget::keyPressEvent(ev); |
acd46a6
to
a97edf4
Compare
186de4b
to
a97edf4
Compare
08c5409
to
5e9790f
Compare
#510 should be fixed. There is now some MacOS specific logic to remove the #579 should be fixed now if the user selects a keyboard layout that does not conflict with the bindings, such as Unicode Hex Input. @mikew Are you still able to look the code over, and give everything a quick test? |
799c7ab
to
68bdd38
Compare
68bdd38
to
8ca3750
Compare
Several outstanding bugs are related to the way key input is handled. This code is difficult to modify and validate due to the usage of #ifdefs. Each platform has different behavior, and UTs only validate the active platform. This change does the following: 1) Get rid of all #ifdefs, to make the code easier to read. 2) Split platform specific behavior into separate compilation units. 3) Add UT coverage for all platforms, regardless of active platform. 4) Remove unused logic.
Some versions of Qt will send key events using Key_Super_L and Key_Super_R. We should handle these keys like other modifier keys. If the event contains only modifier keys it should be ignored. UTs added for ignoring various modifier key combination, as well as this specific scenario.
8ca3750
to
4f805ac
Compare
The Shift key modifier is redundant, and should be removed before sending the event to Neovim. The "<" should be sent as "<lt>".
A handful of tests are hitting SPYWAIT timeouts, causing dramatic slow-downs in the overall test performance. Comments have been added to these tests, and the timeout values adjusted for better performance.
The following test failure has been observed on MacOS: ``` FAIL! : NeovimQt::Test::connectToNeovimTCP() Compared values are not the same Actual (c->errorCause()) : NoError Expected (NeovimConnector::SocketError): SocketError Loc: [/Users/travis/build/equalsraf/neovim-qt/test/tst_neovimconnector.cpp(65)] ``` This issue occurs when the SPYWAIT times out before the TCP connection failure. Add a QVERIFY to catch the timeout, and increase timeout value to 2x the longest observed connection failure time on MacOS (~50s).
This statement is useful for writing Unit Tests, and for helping to debug input event issues. Having the code here, and commented out is useful for showing users how to print the correct information.
MacOS can send special characters when the Alt key is held. The Alt key modifier should be removed in these cases so the underlying character is sent as input. Before: Alt + A -> "<A-å>" After: Alt + A -> "å"
The input for uppercase letters is not well-formed. The Shift Key is implied for uppercase character, and should not be explicitly sent. Before: Shift + X: "<S-X>" After: Shift + X: "X"
The MacOS Alt behavior prevents simple key mappings like <A-x>. With this change, users can now map <A-...> with the proper keyboard layout, Unicode Hex Input. Before: Alt + X -> "" After: Alt + X -> "<A-x>"
4f805ac
to
ac5d5fa
Compare
@equalsraf This should be ready to go. Everything I have tested looks reasonable on Mac/Linux/Windows. I am not aware of any outstanding issues. |
Merged. Thanks @jgehrig. This is a tremendous amount of work. |
Thanks for the kind words! :) |
Several outstanding bugs are related to the way key input is handled. This code is difficult to modify and validate due to the usage of #ifdefs. Each platform has different behavior, and Unit Tests only validate the active platform.
This change does the following:
I've also added fixes for Issue #593 and Issue #607.
Issue 607: The QKeyEvent for "<" contains a ShiftModifier. We need to remove this and send
<lt>
instead of<S-lt>
.Issue 593: Some versions of Qt can send
Key_Super_L
. We should ignore this event along with other modifier-only key events.Issue 579: Cannot map <A-...> on MacOS. Keyboard layout "UnicodeHexInput" required.
Issue 510: Alt special key input does not work on MacOS. We are currently sending
<A-...>
instead of...
.