Adding kotoeri support (Japanese text on MacOS)

This also fixes a little error when deleting text when there is no text, and a little tidying up.

Haven't tested for Chinese/Korean/other similar languages, but I believe it works the same.