Code added when commenting out a line and then pressing TAB

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
FarmersDairy
Posts: 22
Joined: Wed May 02, 2012 7:35 am

Code added when commenting out a line and then pressing TAB

Post by FarmersDairy »

OS: Windows 7 Professional (64-bit)
PSS: 2012 v3.1.32 (32-bit) & 2014 v4.1.51 (64-bit)

Sorry if this is a repeated question, but I could not find a similar support incident.

I was using PSS 2014 to add a # in front of a line of code to comment it out and pressed the tab key to put in some space to make it easier to read later. I had expected it to tab over x number of columbs, but it inserted a bunch of code as seen below. The # in front of "function Parse-Commandline" is the # I had place before my code. My code was uncommented immediately following the inserted code.

I tried on my 2012 edition as well and got the exact same result. Bug or feature? :)

Code: Select all

#function Parse-Commandline 
{ 
<#
	.SYNOPSIS
		Parses the Commandline of a package executable

	.DESCRIPTION
		Parses the Commandline of a package executable

	.PARAMETER  Commandline
		The Commandline of the package executable

	.EXAMPLE
		$arguments = Parse-Commandline -Commandline $Commandline

	.INPUTS
		System.String

	.OUTPUTS
		System.Collections.Specialized.StringCollection
#>

	[OutputType([System.Collections.Specialized.StringCollection])]
    Param([string]$CommandLine) 
	
    $Arguments = New-Object System.Collections.Specialized.StringCollection 
	
	if($CommandLine)
	{
	    #Find First Quote 
	    $index = $CommandLine.IndexOf('"') 

	    while ( $index -ne -1) 
	    {#Continue as along as we find a quote 
	        #Find Closing Quote 
	        $closeIndex = $CommandLine.IndexOf('"',$index + 1) 
	        if($closeIndex -eq -1) 
	        { 
	            break #Can’t find a match 
	        } 
	        $value = $CommandLine.Substring($index + 1,$closeIndex – ($index + 1)) 
	        [void]$Arguments.Add($value) 
	        $index = $closeIndex 

	        #Find First Quote 
	        $index = $CommandLine.IndexOf('"',$index + 1) 
	    } 
	}
    return $Arguments 
}

function Convert-CommandLineToDictionary 
{ 
	<#
	.SYNOPSIS
		Parses and converts the commandline of a packaged executable into a Dictionary

	.DESCRIPTION
		Parses and converts the commandline of a packaged executable into a Dictionary

	.PARAMETER  Dictionary
		The Dictionary to load the value pairs into.

	.PARAMETER  CommandLine
		The commandline of the package executable

	.PARAMETER  ParamIndicator
		The character used to indicate what is a parameter.
	
	.EXAMPLE
		$Dictionary = New-Object System.Collections.Specialized.StringDictionary
		Convert-CommandLineToDictionary -Dictionary $Dictionary -CommandLine $Commandline  -ParamIndicator '-'
	#>
    Param(	[ValidateNotNull()]
			[System.Collections.Specialized.StringDictionary]$Dictionary,
			[string]$CommandLine, 
			[char] $ParamIndicator) 

	$Params = Parse-Commandline $CommandLine
	
    for($index = 0; $index -lt $Params.Count; $index++) 
    { 
        [string]$param = $Params[$index] 
        #Clear the values 
        $key = "" 
        $value = "" 

        if($param.StartsWith($ParamIndicator)) 
        { 
            #Remove the indicator 
            $key = $param.Remove(0,1) 
            if($index  + 1 -lt $Params.Count) 
            { 
                #Check if the next Argument is a parameter 
                [string]$param = $Params[$index + 1] 
                if($param.StartsWith($ParamIndicator) -ne $true ) 
                { 
                    #If it isn’t a parameter then set it as the value 
                    $value = $param 
                    $index++ 
                } 
            } 
            $Dictionary[$key] = $value 
        }#else skip 
    } 
}

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: Code added when commenting out a line and then pressing

Post by davidc »

If you hit tab after a snippet shortcut name, it will automatically insert the snippet (even within comments).

For example

msgbox<tab> will expand to:

PowerShell Code
Double-click the code block to select all.
#[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][System.Windows.Forms.MessageBox]::Show("Text","Caption")
If you hit tab while a snippet is highlighted while the code completion window is open, it will also expand the snippet.

David
David
SAPIEN Technologies, Inc.