ruffle icon indicating copy to clipboard operation
ruffle copied to clipboard

core: Improve placement of cursor when clicking in textbox

Open MrCheeze opened this issue 1 year ago • 1 comments

Currently when clicking in a textbox, the cursor will only be placed correctly if you click exactly on top of a letter. The basic purpose of this commit is to make it so that clicking in the surrounding margin will put the cursor in the closest available position, as in Flash Player.

The logic is a bit complex because a single row of text can contain multiple layout boxes, each with a different Y offset (but all with the same Y extent). To be accurate, we need to treat each layout box in the row "as if" it had the same Y offset that the tallest box in its row has.

This commit also contains a fix for an issue where lower_from_text_spans was passing the wrong text strings and indexes to fixup_line for newlines, which needed to be fixed in order to be able to click to place the cursor in an empty row that was created by newlines.

I don't know if tests are possible for this function, but here's a swf that I manually tested with.

Oh yeah, and this fixes https://github.com/ruffle-rs/ruffle/issues/2351 (possibly others)

MrCheeze avatar Feb 04 '24 05:02 MrCheeze

I don't know if tests are possible for this function, but here's a swf that I manually tested with.

You can simulate clicks at specific points using input.json e.g. https://github.com/ruffle-rs/ruffle/blob/master/tests/tests/swfs/avm2/mouse_pick_text/input.json.

evilpie avatar Feb 04 '24 11:02 evilpie

Amended the PR by adding a test, the actual logic is unchanged. Should be reviewable now.

MrCheeze avatar Feb 19 '24 21:02 MrCheeze