This logic here is not quite doing the right thing if the window or canvas element lose and then regain focus. I actually wonder whether the decision to hide or show the caret belongs within the caret.show / caret.refreshCursorBlinking function.

Reproduction steps:
1. Select an image
2. Click on the browser's location bar to "lose" window focus
3. Click back on the previously selected image. Note that the cursor starts blinking beside the image again