Fix a bug when setting cursor positions from Python