slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.93k stars 565 forks source link

Enter key causes TextEdit to add a space instead of going to the new line #1318

Closed cppdev123 closed 2 years ago

cppdev123 commented 2 years ago

When using TextEdit and pressing enter a space is added then when you try to write the text goes to the new line. Instead a new line should be added when pressing Enter

ogoffart commented 2 years ago

Thanks for the bug report! I can reproduce the problem in the gallery on wasm in the browser (firefox). But it works fine on the native linux with both backend.

(So this is most likely a bug in wasm_input_helper.rs)

ogoffart commented 2 years ago

Actually no, i can also reproduce on desktop with the GL backend. So this is not a wasm problem. The problem only happens if we are at the last position of the TextEdit. The Qt backend seems to work.

ogoffart commented 2 years ago

I think this is related to the position of the cursor. We have some special logic when the cursor is at the end of the text: https://github.com/slint-ui/slint/blob/a2484cfc64d4d14baa4ebeae2df47ac2207c3aee/internal/backends/gl/glrenderer.rs#L400-L401 But that kind of fails if the last character is a \n Because the \n is at the end of the line, and there is no more line after that (the empty line is not rendered) then we can't know the position of the cursor in the next line in that loop. We would need to special case it.

Another problem is that the selection is drawn over the whitespace at the end of the lines, which the Qt backend doesn't do