Modify grouping-related code in InputMethod.