From bc7e79e870b4d14e0cee9b657a65a209f39e11c7 Mon Sep 17 00:00:00 2001 From: halvarsson Date: Wed, 8 May 2024 20:13:41 +0200 Subject: [PATCH] #53 add line / column parameters to psedit --- ShowEditorCommand.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ShowEditorCommand.cs b/ShowEditorCommand.cs index a920bda..2d0d308 100644 --- a/ShowEditorCommand.cs +++ b/ShowEditorCommand.cs @@ -34,6 +34,13 @@ public class ShowEditorCommand : PSCmdlet [Parameter(ParameterSetName = "Path", ValueFromPipeline = true, Position = 0)] public string Path { get; set; } + + [Parameter(ParameterSetName = "Path", ValueFromPipeline = true, Position = 1, Mandatory = false)] + public int Line { get; set; } + + [Parameter(ParameterSetName = "Path", ValueFromPipeline = true, Position = 2, Mandatory = false)] + public int Column { get; set; } + private byte[] _originalText = new System.IO.MemoryStream().ToArray(); [Parameter()] @@ -66,13 +73,25 @@ protected override void ProcessRecord() }; fileNameStatus = new StatusItem(Key.CtrlMask | Key.Q, "Unsaved", () => { Quit(); }); - + // Load the path if it was passed in if (Path != null) { Path = GetUnresolvedProviderPathFromPSPath(Path); LoadFile(); } - + // Set the cursor position if it was passed in + if (Line > 0 || Column > 0) + { + if (!(Line > 0)) + { + Line = 1; + } + if (!(Column > 0)) + { + Column = 1; + } + textEditor.CursorPosition = new Point(Column - 1, Line - 1); + } Application.Init(); top = Application.Top; languageStatus = new StatusItem(Key.Unknown, "Text", () => { });