FB13789916: NSTextInputClient.setMarkedText provide bogus selection range for Chinese keyboard

May 9, 2024 ยท View on GitHub

  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