Replace selectionParentNode with getContaining for better selection detection