fix: Improve anchor retrieval in ReferenceInputBehavior and enhance widget escape handling