Skip to content

fix: autofocus only new, empty posts - #823

Merged
dcalhoun merged 4 commits into
trunkfrom
fix/autofocus-only-new-empty-posts
Oct 23, 2026
Merged

dcalhoun merged 4 commits into
trunkfrom
fix/autofocus-only-new-empty-posts

Conversation

@dcalhoun

@dcalhoun dcalhoun commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What?

Limit auto-focus to new, empty posts.

Why?

Aligns more closely with the WP Admin experience.

How?

  • Add an internal isNewEmptyPost check for iOS and Android
  • Check for no server ID, empty title, and empty content

Testing Instructions

Test the demo app on iOS and Android with a site added through the demo app's login, rather than the built-in wp-env site, which has no Browse button on Android. Use a device or a simulator/emulator with the software keyboard enabled.

  1. In the site's WP Admin, add a new post, type only a title, and click Save draft.
  2. In the demo app, select the site and tap Start to open a new post. Verify that the keyboard opens with the caret in the title.
  3. Close the editor, tap Browse, and open the post from step 1. Verify that the keyboard doesn't open. On trunk, it does.
  4. To open a new post with only a title, as a reopened local draft looks to the editor, temporarily add .setTitle("Trip notes") to applyDemoAppDefaults in ios/Demo-iOS/Sources/Views/SitePreparationView.swift. On Android, change .setTitle("") to .setTitle("Trip notes") in SitePreparationViewModel.kt. Tap Start, and verify that the keyboard doesn't open. On trunk, it does.
  5. To hide the title, temporarily add .setShouldHideTitle(true) to applyDemoAppDefaults on iOS. On Android, change .setHideTitle(false) to .setHideTitle(true). Tap Start, and verify that the keyboard opens with the caret in the content. This PR shouldn't change this case.

Revert the demo app edits afterward.

Accessibility Testing Instructions

N/A, no navigation changes.

Screenshots or screencast

N/A, no visual changes.


AI-generated details

Native autofocus (#191) was meant for new posts but checked only for empty content. It now uses the same rule as the web editor's new posts (#794): no server ID (missing or ≤ 0), and a blank title and content.

  • Adds an internal isNewEmptyPost to EditorConfiguration on iOS and Android.
  • iOS focus(force:) and Android's autofocus on load use it. focus(force: true) still overrides it.
  • On Android, isNewEmptyPost and GBKitGlobal share an internal serverPostId (null for a new post), so autofocus and the web editor can't disagree about whether a post is new. Only the bridge's Post.id still encodes a new post as -1.

Behavior changes

  • Still focuses: a new post, and a new title-less editor such as comments.
  • Stops focusing: an existing server post with empty content, and a local draft with only a title.
  • Public API: a host's focus() call without force on iOS no longer focuses an existing post with empty content.
  • Android bridge: a negative post ID converted to UInt now reaches the web editor as -1 rather than its own negative value. Both mean a new post.

The native calls stay because core's title focus only moves DOM focus. iOS's becomeFirstResponder() and Android's requestFocus() and showSoftInput raise the keyboard, and GBK's editor.focus() covers editors with a hidden title, which core never focuses.

Testing

  • Unit tests for isNewEmptyPost on both platforms, and for the Android -1 mapping in GBKitGlobalTest. The iOS package tests and Android library unit tests pass, and both linters pass.
  • Not yet tested on a device.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YNDBX7RNXn3NsfDuV1PkNV

@github-actions github-actions Bot added the [Type] Bug An existing feature does not function as intended label Oct 22, 2026
@wpmobilebot

wpmobilebot commented Oct 22, 2026 •

Copy link
Copy Markdown

XCFramework Build

This PR's XCFramework is available for testing. Add the following to your Package.swift:

.package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/823")

Built from ac09603

dcalhoun and others added 4 commits October 23, 2026 11:40
Autofocus was meant for new posts, as in WP Admin, but checked only for empty content, so it also raised the keyboard on existing posts with empty content and on local drafts with only a title. It now matches the web editor's rule for new posts: no server ID and an empty title and content.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YNDBX7RNXn3NsfDuV1PkNV
GBKitGlobal sends the web editor postId.toInt(), so a negative ID a host converted with toUInt() reaches it as a new post. Autofocus read the same value as a server ID, so the two disagreed about whether the post was new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YNDBX7RNXn3NsfDuV1PkNV
… web editor

Autofocus and GBKitGlobal each converted postId on their own, so they could disagree about whether a post is new. One property now decides, with null for a new post as the Post.id TODO intends; only the wire encoding still uses -1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WP Admin focuses a clean auto-draft, not a post with no ID and a blank title and content, so the comparison misled readers about which posts autofocus targets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dcalhoun
dcalhoun force-pushed the fix/autofocus-only-new-empty-posts branch from 2bdf395 to ac09603 Compare October 23, 2026 15:40
@dcalhoun
dcalhoun marked this pull request as ready for review October 23, 2026 15:51
@dcalhoun
dcalhoun requested a review from nbradbury October 23, 2026 15:52
@nbradbury

Copy link
Copy Markdown
Contributor

Claude had one medium finding, but it's not something that really needs to be addressed, imo.

Severity Merge Location Issue Impact
Medium Could fix GBKitGlobal.kt:122 The web editor now gets -1 for every negative post ID on Android, while iOS still passes the ID through unchanged (configuration.postID ?? -1 in GBKitGlobal.swift). A host passing (-5L).toUInt() used to send post.id = -5 and now sends -1, but iOS still sends -5; that changes what goes over the wire in a commit labelled a refactor and leaves the two platforms disagreeing.

@dcalhoun

Copy link
Copy Markdown
Member Author

@nbradbury I don't believe it is all that valuable to address here. I do not believe any post passes negative IDs aside from -1 and doing so wouldn't change the outcome. We could potentially clean up the divergence later.

@nbradbury nbradbury 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.

All good :shipit:

@dcalhoun
dcalhoun merged commit fdcf360 into trunk Oct 23, 2026
23 checks passed
@dcalhoun
dcalhoun deleted the fix/autofocus-only-new-empty-posts branch October 23, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants