From adba47d00e79247bf76ef56e14984d9767ac72fc Mon Sep 17 00:00:00 2001 From: Frode Flaten <3436158+fflaten@users.noreply.github.com> Date: Mon, 20 Feb 2023 18:42:16 +0000 Subject: [PATCH 1/2] Fix New-EditorFile inserting text in wrong editor The object returned from GetEditorContext() always points to the original file in CurrentFile. We need to get an updated object after opening or creating a file to insert text in the right editor. Fix PowerShell/vscode-powershell#3192 --- .../Commands/Public/CmdletInterface.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 b/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 index 6fc9114e6..e54089d91 100644 --- a/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 +++ b/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 @@ -155,7 +155,7 @@ function New-EditorFile { } $psEditor.Workspace.OpenFile($fileName, $preview) - $editorContext.CurrentFile.InsertText(($valueList | Out-String)) + $psEditor.GetEditorContext().CurrentFile.InsertText(($valueList | Out-String)) } else { $PSCmdlet.WriteError( ( New-Object -TypeName System.Management.Automation.ErrorRecord -ArgumentList @( @@ -167,7 +167,7 @@ function New-EditorFile { } } else { $psEditor.Workspace.NewFile() - $editorContext.CurrentFile.InsertText(($valueList | Out-String)) + $psEditor.GetEditorContext().CurrentFile.InsertText(($valueList | Out-String)) } } } From 8e4d14006d8895cc30e9fd3f914a97f81818731b Mon Sep 17 00:00:00 2001 From: Frode Flaten <3436158+fflaten@users.noreply.github.com> Date: Mon, 20 Feb 2023 18:45:02 +0000 Subject: [PATCH 2/2] Remove unintended output from Out-CurrentFile #869 forgot to assign a returned editorcontext, causing new output from the command. Assigning to null. --- .../Commands/Public/Out-CurrentFile.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 b/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 index a8d222e97..bc7bfcba1 100644 --- a/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 +++ b/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 @@ -26,7 +26,7 @@ function Out-CurrentFile { try { # If there is no file open - $psEditor.GetEditorContext() + $null = $psEditor.GetEditorContext() } catch { # create a new one