move obtaining caret offset into helper method