Skip to content

Fix missing selection change notifications for cut operations#422

Open
Dilrvvr wants to merge 1 commit intosimonbs:mainfrom
Dilrvvr:main
Open

Fix missing selection change notifications for cut operations#422
Dilrvvr wants to merge 1 commit intosimonbs:mainfrom
Dilrvvr:main

Conversation

@Dilrvvr
Copy link
Copy Markdown

@Dilrvvr Dilrvvr commented Apr 3, 2026

Summary

TextInputView.cut(_:) did not notify inputDelegate when the selection
changed after cutting text.

Because of that, the visual selection highlight could remain visible even
after the selected text had been removed and the selection had collapsed.

Changes

  • call selectionWillChange(_:) before replacing the selected text during
    cut(_:)
  • call selectionDidChange(_:) after the replacement completes
  • align the cut(_:) behavior with the existing selection notification flow
    used by paste(_:)

Testing

  • manually verify that cutting a selection removes the text and clears the
    visual selection highlight
  • confirm that the caret collapses to the expected insertion point after the
    cut operation

Notes

  • this change is limited to selection notification handling in the cut path
  • no functional changes were made to copy, paste, or general text replacement
    behavior

The cut() method was not notifying inputDelegate about the selection
change, unlike paste() which properly calls selectionWillChange/
selectionDidChange. This caused the visual selection highlight to
persist after cutting text.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Dilrvvr Dilrvvr requested a review from simonbs as a code owner April 3, 2026 11:04
Copilot AI review requested due to automatic review settings April 3, 2026 11:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes missing UITextInputDelegate selection change notifications when performing a cut, which could leave the system selection UI (highlight/caret) visually out of sync after the selected text is removed.

Changes:

  • Notify inputDelegate with selectionWillChange(_:) immediately before cutting (replacing selection with empty string).
  • Notify inputDelegate with selectionDidChange(_:) immediately after the cut replacement completes.
  • Align cut(_:) selection notification behavior with the existing paste(_:) flow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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