Set the selection to a range from anchor to head. If head is not provided, creates a cursor at anchor.