Skip to content

Fix Paragraph.getOffsetForPosition behavour in corner cases#3071

Open
Vladimir Mazunin (mazunin-v-jb) wants to merge 1 commit into
jb-mainfrom
v.mazunin/getOffsetForPosition-corner-cases
Open

Fix Paragraph.getOffsetForPosition behavour in corner cases#3071
Vladimir Mazunin (mazunin-v-jb) wants to merge 1 commit into
jb-mainfrom
v.mazunin/getOffsetForPosition-corner-cases

Conversation

@mazunin-v-jb

@mazunin-v-jb Vladimir Mazunin (mazunin-v-jb) commented May 27, 2026

Copy link
Copy Markdown

Follow-up to the Skia/Skiko hit-testing fixes for caret positioning.
This PR must be merged after updating Skia.

  • Enabled three previously ignored tests.
  • Removed the workaround with the RTL block-position correction in getOffsetForPosition (the correctedGlyphPosition -= 1 branch with the isNeutralDirection / Direction.RTL check). Skia should return the correct offset for clicks to the right of a line in mixed-direction text now, so the compose-side adjustment is no longer needed.
  • Adjusted and removed getOffsetForPosition_insideComplexCharacter_shouldJumpToEndgetOffsetForPosition_midpointOfComplexCharacter_snapsToClusterStart`, since it's more accurate and conforms to the Android behavior.

Fixes:
CMP-8594 Fix Paragraph.getOffsetForPosition behavour in corner cases

Testing

There are tests already, however, this better be tested by QA

Release Notes

N/A

@mazunin-v-jb

Vladimir Mazunin (mazunin-v-jb) commented May 27, 2026

Copy link
Copy Markdown
Author

Just in case, it's better to merge it after this PR.


// For RTL blocks, the position is still not correct, so we have to subtract 1 from the returned result
if (!isNeutralChar && getBoxBackwardByOffset(correctedGlyphPosition)?.direction == Direction.RTL) {
correctedGlyphPosition -= 1 // TODO Check if it should be CodePoint.charCount()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an implementation of a common interface, and most likely some commonMain code relies on that.
Just saying that we do it differently and fixing copy-pasted tests (that should be in commonTest ideally) seems really suspicious tbh.

Shouldn't we align SkParagraph to android instead?

@mazunin-v-jb Vladimir Mazunin (mazunin-v-jb) marked this pull request as draft May 28, 2026 11:27
…kiaParagraph, removed @Ingore related to CMP-8594, adjusted Skia test to match android behavior
@mazunin-v-jb Vladimir Mazunin (mazunin-v-jb) force-pushed the v.mazunin/getOffsetForPosition-corner-cases branch from d107e97 to cd41693 Compare June 6, 2026 23:33
@mazunin-v-jb Vladimir Mazunin (mazunin-v-jb) changed the title Fix ignored tests in DesktopParagraphIntegrationTest Fix Paragraph.getOffsetForPosition behavour in corner cases Jun 6, 2026
@mazunin-v-jb Vladimir Mazunin (mazunin-v-jb) marked this pull request as ready for review June 6, 2026 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants