Fix Issue: WASM, Reading console input does not work #360
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the current WebAssembly (WASM) version of Ripes there's an issue preventing input reading from the console. This because pressing
Enter
does not return control to the processor, as stated in issue #304.The problems stems from the behaviour of the
Console::keyPressEvent(QKeyEvent *e)
method, which requires aQKeyEvent
parameter, that appears to behave differently in the binary executable compared to the WASM version.In the binary executable, when pressing Enter or Return, the
QKeyEvent
associated with the keysQt::Key_Return
orQt::Key_Enter
has a non empty text field (e->text()
). However, in the WASM version that field is empty and therefore the checkif (!e->text().isEmpty())
always returns false when pressing Enter, resulting in the already reported error.The same happens with the Backspace Key.
Proposed fix
I propose altering the handling of these events: rather than mandating a non-empty text field in the
QKeyEvent
, I suggest to verify only the key associated with each command. Text inspection should only occur for the events where the key is not checked.As stated in the Qt documentation of the QKeyEvent Class of
key()
:The
key()
of an event is independent from the underlying system while thetext()
may not.In the modified code, all types of
QKeyEvent
are processed using the same switch-case structure, as currently happens for the directional keys. When a key event is triggered, the program checks if the key corresponds to any of the arrow keys, the Enter key, the Return key or the Backspace key.If the key does not match any of these, the event is handled as it used to: first, it checks that the content of the key event is not empty, ensuring that modifier keys such as Shift, Control, or Alt are not considered. Then, it adds the content of the event to the buffer and calls the
putData()
method.