Console confused by emojis with variant selector 0xFE0F
- iTerm2 version: Build 3.2.4beta3
- OS version: macOS High Sierra
- plist file: com.googlecode.iterm2.plist
Emojis composed with the "variant selector 16" character code appear as the wrong width and confuse the backspace motion.
Detailed steps to reproduce the problem:
- Start a bash session.
- Enter:
heart='\xe2\x9d\xa4\xef\xb8\x8f'
- Enter:
printf "$heart$heart$heart\n"
What happened:
The heart emojis appeared overlapped.
What should have happened:
The heart emojis should not overlap.
Alternatively:
- Start a bash session.
- Press ctrl+cmd+space to bring up the system emoji selector.
- Select the red heart emoji.
- Press backspace.
- Press backspace again.
What happened: At step 3, the double-width heart emoji appeared, but the cursor only advanced one character cell, so it was still overlapping the emoji. At step 4, the heart emoji appeared to have been deleted. (But actually only the zero-width variant selector was deleted from the command buffer.) At step 5, the cursor moved left again, unexpectedly.
What should have happened: At step 3, the cursor should have advanced two cells. At steps 4 and 5, either: on the first keystroke the cursor should have moved left one cell and the emoji heart been replaced by a non-emoji heart symbol, and on the second keystroke the cursor should have moved left another cell and the heart been deleted entirely; OR on the first keystroke the cursor should have moved left two cells and the heart disappeared entirely, and the second keystroke should have had no effect other than bash ringing the bell.
I'm not 100% sure this is just an iTerm2 bug. I think bash/readline is treating the heart symbol and the emoji variant selector as two separate typed/deletable characters, which is a little surprising. Nevertheless, iterm2 could be handling this more gracefully.