SWC-1223: support empty selection, and handle focus and previous cursor position