private static int getCaretPosition(FindResult findResult, int caretShiftFromSelectionStart) {
    return caretShiftFromSelectionStart < 0
           ? findResult.getEndOffset() : Math.min(findResult.getStartOffset() + caretShiftFromSelectionStart, findResult.getEndOffset());
  }
private static int getCaretPosition(FindResult findResult, int caretShiftFromSelectionStart)