Fix cursor jumping (thanks @amarandon) and update code style