File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
module/PowerShellEditorServices/Commands/Public Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -86,10 +86,10 @@ function Unregister-EditorCommand {
8686 Creates and opens a new foo.ps1 in your editor
8787. EXAMPLE
8888 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
9090. EXAMPLE
9191 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
9393. INPUTS
9494 Path
9595 an array of files you want to open in your editor
@@ -125,7 +125,16 @@ 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+ }
137+
129138 if (! $editorContext ) {
130139 return
131140 }
You can’t perform that action at this time.
0 commit comments