Open eugkong opened 6 months ago
Video illustrating the issue: https://github.com/bonafideduck/react-highlight-within-textarea/assets/56010320/c71d8502-2164-4d33-b21a-02e58202c3e5
Seems to be caused by the onChange handler being invoked twice when a (single) space is typed. For example, if we log the value received by the onChange handler each time it is invoked, we get the following when 'Hello world' is typed:
value: '' value: 'H' value: 'He' value: 'Hel' value: 'Hell' value: 'Hello' value: 'Hello ' value: 'Hello ' // onChange handler triggered a second time, causing double space. value: 'Hello w' value: 'Hello wo' value: 'Hello wor' value: 'Hello worl' value: 'Hello world'
value: ''
value: 'H'
value: 'He'
value: 'Hel'
value: 'Hell'
value: 'Hello'
value: 'Hello '
value: 'Hello ' // onChange handler triggered a second time, causing double space.
value: 'Hello w'
value: 'Hello wo'
value: 'Hello wor'
value: 'Hello worl'
value: 'Hello world'
How annoying. I can reproduce it on the demo page in the first demo on my ipad. I may not have time to look into this for a couple weeks.
Video illustrating the issue: https://github.com/bonafideduck/react-highlight-within-textarea/assets/56010320/c71d8502-2164-4d33-b21a-02e58202c3e5
Seems to be caused by the onChange handler being invoked twice when a (single) space is typed. For example, if we log the value received by the onChange handler each time it is invoked, we get the following when 'Hello world' is typed:
value: ''
value: 'H'
value: 'He'
value: 'Hel'
value: 'Hell'
value: 'Hello'
value: 'Hello '
value: 'Hello ' // onChange handler triggered a second time, causing double space.
value: 'Hello w'
value: 'Hello wo'
value: 'Hello wor'
value: 'Hello worl'
value: 'Hello world'