File tree 1 file changed +12
-3
lines changed
module/PowerShellEditorServices/Commands/Public
1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -86,10 +86,10 @@ function Unregister-EditorCommand {
86
86
Creates and opens a new foo.ps1 in your editor
87
87
. EXAMPLE
88
88
PS > Get-Process | New-EditorFile proc.txt
89
- Creates and opens a new foo.ps1 in your editor with the contents of the call to Get-Process
89
+ Creates and opens a new proc.txt in your editor with the contents of the call to Get-Process
90
90
. EXAMPLE
91
91
PS > Get-Process | New-EditorFile proc.txt -Force
92
- Creates and opens a new foo.ps1 in your editor with the contents of the call to Get-Process. Overwrites the file if it already exists
92
+ Creates and opens a new proc.txt in your editor with the contents of the call to Get-Process. Overwrites the file if it already exists
93
93
. INPUTS
94
94
Path
95
95
an array of files you want to open in your editor
@@ -125,7 +125,16 @@ function New-EditorFile {
125
125
end {
126
126
# If editorContext is null, then we're in a Temp session and
127
127
# 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
+ }
137
+
129
138
if (! $editorContext ) {
130
139
return
131
140
}
You can’t perform that action at this time.
0 commit comments