def METHOD_NAME( candidates ):
  """This function adjusts the candidate insertion text to take into account the
  text that's currently in front of the cursor.
  For instance ('|' represents the cursor):
    1. Buffer state: 'foo.|bar'
    2. A completion candidate of 'zoobar' is shown and the user selects it.
    3. Buffer state: 'foo.zoobar|bar' instead of 'foo.zoo|bar' which is what the
    user wanted.
  This function changes candidates to resolve that issue.
  It could be argued that the user actually wants the final buffer state to be
  'foo.zoobar|' (the cursor at the end), but that would be much more difficult
  to implement and is probably not worth doing.
  """
  def NewCandidateInsertionText( to_insert, text_after_cursor ):
    overlap_len = OverlapLength( to_insert, text_after_cursor )
    if overlap_len:
      return to_insert[ :-overlap_len ]
    return to_insert
  text_after_cursor = vimsupport.TextAfterCursor()
  if not text_after_cursor:
    return candidates
  new_candidates = []
  for candidate in candidates:
    new_candidate = candidate.copy()
    if not new_candidate.get( 'abbr' ):
      new_candidate[ 'abbr' ] = new_candidate[ 'word' ]
    new_candidate[ 'word' ] = NewCandidateInsertionText(
      new_candidate[ 'word' ],
      text_after_cursor )
    new_candidates.append( new_candidate )
  return new_candidates