Skip to content

Commit 054ca6c

Browse files
committed
Fix when there is no editor window open.
1 parent e5b7be9 commit 054ca6c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,15 @@ function New-EditorFile {
125125
end {
126126
# If editorContext is null, then we're in a Temp session and
127127
# this cmdlet won't work so return early.
128-
$editorContext = $psEditor.GetEditorContext()
128+
try {
129+
$editorContext = $psEditor.GetEditorContext()
130+
}
131+
catch {
132+
# If there's no editor, this throws an error. Create a new file, and grab the context here.
133+
# This feels really hacky way to do it, but not sure if there's another way to detect editor context...
134+
$psEditor.Workspace.NewFile()
135+
$editorContext = $psEditor.GetEditorContext()
136+
}
129137
if (!$editorContext) {
130138
return
131139
}

0 commit comments

Comments
 (0)