I don't think it is a good idea to create a new file entry here. This change also unnecessarily creates a new file entry for current text document. Instead, I would suggest that you keep the old code and add an else block to handle the closing of an image preview and return resolved promise in the new else block. Your current approach not only creates an extra file entry, but also fall through the code below that is calling DocumentManager.getOpenDocumentForPath() which we should not be doing for an image file.