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 568 forks source link

Skia: broken multi-line text input #3590

Closed jpnurmi closed 11 months ago

jpnurmi commented 11 months ago

Originally posted by @jpnurmi in https://github.com/slint-ui/slint/issues/3588#issuecomment-1742847367

Multiline editing is somehow broken with Skia. Sometimes (at the end of any non-empty line?) you need to press enter twice to insert a new line. Once you type in the next character, the extra line break appears.

"Center" + "↵" + "↵" + "n"
Screenshot 2023-10-02 at 13 55 14 Screenshot 2023-10-02 at 13 25 47 Screenshot 2023-10-02 at 13 28 20

Latest master (e44f70c9dfcf0379390b5f8886764e38c2bf9c25), macOS, winit-skia

jpnurmi commented 11 months ago

Similarly, while erasing, an extra backspace press is required.

https://github.com/slint-ui/slint/assets/140617/6367572d-4bdc-43b5-9f07-ca972784dcab

jpnurmi commented 11 months ago

The text boxes returned by SkParagraph::getRectsForRange() that are used for calculating the cursor rectangle don't quite match with SkParagrap::getLineMetrics(), at least when there's a singular trailing newline. For example, "Hello" and "Hello\n" are both presented as a single identical text box.

"Hello"

https://fiddle.skia.org/c/8ed057a649687bf916581fe0b8ebfad0