git: Open File command fix on clean tree#60426
Conversation
|
@joaomoreno I made a simple fix without making much change. For now, I've included the fix based on the reference from Review and let me know your thoughts |
| uris = resources.map(r => r.resourceUri); | ||
| } | ||
| else { | ||
| uris = [(window.activeTextEditor && window.activeTextEditor.document.uri)] as Uri[]; |
There was a problem hiding this comment.
If window.activeEditor is undefined, this will cause uris to be an array with one element (undefined). Better use the ternary operator.
uris = (activeTextEditor ? [activeTextEditor.document.uri] : []) as Uri[];
Also you can move the activeTextEditor declaration above the uris declaration (close to the start of the openFile function), and reuse that.
There was a problem hiding this comment.
Sorry, for the late response. You're right about the check. But I doubt that this command will be invoked without an active editor. Because this command would not be accessible when there is no active editor. Let me know if I'm wrong.
There was a problem hiding this comment.
Actually the window.activeTextEditor is a nullable field (of type TextEditor | undefined) hence using the existence check is required, otherwise there can be bugs in the future.
|
Thanks! 🍻 |
Fixes #60174