Skip to content

fix(ios): stale head indent on selection change to a trailing newline - #789

Open
hejsztynx wants to merge 1 commit into
mainfrom
@ksienkiewicz/fix-ios-trailing-newline-indent
Open

hejsztynx wants to merge 1 commit into
mainfrom
@ksienkiewicz/fix-ios-trailing-newline-indent

Conversation

@hejsztynx

@hejsztynx hejsztynx commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

When we had the editor's content ending with a newline, meant we had literally no character in that line at all. This caused UIKit to derive typing attributes from the previous character (previous line) on selection change. This happened even though we explicitly reset typing attributes in manageTypingAttributesWithOnlySelection, when onlySelectionChanged is true.

E.g. we change selection to that empty newline, and typingAttributes get derived from an unordered list that is above it. This caused the list indent to be applied on an unstyled line, incorrectly moving the caret. This issue could be reproduced with any style that uses an indent - list styles, blockquote.

Fixed it by explicitly setting the caret's position on empty lines to 0. Previously we were falling back to any values that were in the typing attributes state.

I've run all e2e tests, all passed.

Test Plan

Reproduce the steps shown in the attached videos. Verify it's working correctly.

Screenshots / Videos

Before:

Screen.Recording.2026-09-08.at.14.36.55.mov

This also happened with other indent-modifying styles, e.g.

image image

After:

Screen.Recording.2026-09-08.at.13.52.29.mov

Compatibility

OS Implemented
iOS
Android
Web

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

Copilot AI lite review requested due to automatic review settings September 8, 2026 12:04
@hejsztynx
hejsztynx marked this pull request as draft September 8, 2026 12:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new fallback branch can regress RTL behavior for NSTextAlignmentNatural/Justified by forcing the caret to x=0 instead of the leading edge in right-to-left layout direction.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adjusts iOS caret positioning for empty paragraphs (notably the trailing newline “empty last line”) to prevent UIKit from inheriting stale paragraph indentation (e.g., from lists/blockquote) when the selection changes, which can incorrectly shift the caret.

Changes:

  • Updates caretRectForPosition: to explicitly set the caret’s horizontal position for empty paragraphs when alignment isn’t center/right.
  • Adds inline rationale explaining why typing attributes/paragraph style can’t be relied on for caret geometry in this scenario.
File summaries
File Description
ios/enrichedInputTextView/EnrichedInputTextView.mm Forces caret x-position to avoid stale indent affecting caret placement on empty trailing lines.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread ios/enrichedInputTextView/EnrichedInputTextView.mm
@hejsztynx
hejsztynx marked this pull request as ready for review September 8, 2026 12:50
@hejsztynx
hejsztynx requested a review from szydlovsky September 8, 2026 12:50
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