Skip to content

Commit

Permalink
#53 add line / column parameters to psedit
Browse files Browse the repository at this point in the history
  • Loading branch information
halvarsson committed May 8, 2024
1 parent 2f562af commit bc7e79e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions ShowEditorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down Expand Up @@ -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", () => { });
Expand Down

0 comments on commit bc7e79e

Please sign in to comment.