A wrong behaviour on Safari is observed when entering characters like ˜, ˆ after a highlighted character. The behaviour can be reproduced with a basic setup:
Put the cursor at the end of line 2 (make sure the bracket(s) are highlighted)
Press ⌥ + n on Mac
The same process applies for line 5 with ⌥ + i
The cursor jumps backwards. After that, it sometimes produces unexpected behaviours on any future actions.
The wrong behaviour is observed only when entering accent characters directly from a keyboard but not when pasting them. Tested on Safari 16.2 (18614.3.7.1.5).
Somehow, on my Safari (15.6.1, on macOS 16.6) this problem does not occur. The keys do start a composition (underlined, can combine with another char typed after) but the cursor stays in the right place and everything seems to work properly.
In Safari, with an IME enabled (say, Pinyin or Hiragana), place the cursor inside the parentheses in console.log() and type a character. The cursor jumps back a few characters and composition ends abruptly. ⌥ + n on a US or GB keyboard will do it too.