Fix second caret is not properly updated

When mCaretMode is changed from SELECTION to CURSOR , the second caret
is not properly updated. I separate the update carets logic into cursor
mode and selection mode. This makes some code duplicated but it should
make the update logic more explicit.