[inmethod-grid] Issue #308 - Simplify the cod to find the closest TD cell