Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
Created May 9, 2024 11:49
Show Gist options
  • Save krzyzanowskim/340c5810fc427e346b7c4b06d46b1e10 to your computer and use it in GitHub Desktop.
Save krzyzanowskim/340c5810fc427e346b7c4b06d46b1e10 to your computer and use it in GitHub Desktop.
FB13789916: NSTextInputClient.setMarkedText provide bogus selection range for Chinese keyboard
  1. Open macOS TextEdit application
  2. enter "aaaaaaaaaaaaaaaaaaaa"
  3. move insertion point at location 0
  4. switch system keyboard to Pinyin - Simplified (Chinese)
  5. on the keyboard type letters "abcdefghij"
  6. 💥 observe bug: marked text is "abc " insertion point is at location 11

expected: insertion point is at location 4

The problem is observable from setMarkedText(_:selectedRange:replacementRange:) from NSTextInputClient protocol, where selectedRange value changes from 16 to 11 without a good reason: logs:

  setMarkedText(_:selectedRange:replacementRange:) a bc de fghi, selectedRange: (16, 0), replacementRange: 19223372036854775807, 0,
  setMarkedText(_:selectedRange:replacementRange:) abc, selectedRange: {11, 0}, replacementRange: {9223372036854775807, 0}

Screenshot 2024-05-09 at 13 34 30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment