JBIDE-12847 VPE throws StackOverflowError and visual part is blank

Cherry-picked the changes from master (JBIDE-12308 VPE throws StackOverflowError and visual part is blank)