Move Line Comments over 1 character

SyntaxEditor for Windows Forms Forum

Posted 15 years ago by ernesto
Avatar
Trying to move my line comments over 1 character in the Editor.SelectedView.CommentLines method

If I see an exclamation ! at the beginning of the line when commenting out lines I want to move the comment character to the right one space. My comment character is the apostrophe '

Before commenting the line:
!This is a line to comment

After commenting the line, this is my goal:
!'This is a line to comment

This is what I have in my VB code

Select Case Operation
                    Case AppOperation.LinesComment
                        editor.SelectedView.CommentLines()

                    Case AppOperation.LinesUnComment
                        editor.SelectedView.UncommentLines()

                End Select
This is what I have in my XML language file

<!-- Comments -->
        <State Key="CommentState" TokenKey="CommentDefaultToken" Style="CommentDefaultStyle">
            <!-- Scopes -->
            <Scopes>
                <Scope>
                    <ExplicitPatternGroup Type="StartScope" TokenKey="CommentStartToken" Style="CommentDelimiterStyle" PatternValue="'" />
                    <RegexPatternGroup Type="EndScope" TokenKey="CommentEndToken" Style="CommentDelimiterStyle" PatternValue="{LineTerminatorMacro}" IsWhitespace="True" />
                </Scope>
            </Scopes>
        </State>
Thanks for any help

Comments (2)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Sorry but the built-in comment line features will add/remove text specified by SyntaxLanguage.LineCommentDelimiter at the start of the lines only.


Actipro Software Support

Posted 15 years ago by ernesto
Avatar
Solution found!

' Get first and last line positions of the currently selected text
                Dim firstLine As Integer = editor.SelectedView.Selection.FirstEditPosition.Line
                Dim lastLine As Integer = editor.SelectedView.Selection.LastEditPosition.Line

Select Case Operation
Case AppOperation.LinesComment
Dim index As Integer
                            ' Iterate through all selected lines of text to add an apostrophe ' charater directly after the exclaimation character !
                            For index = firstLine To lastLine
                                editor.Document.Lines.Item(index).Text = editor.Document.Lines.Item(index).Text.Insert(1, "'")
                            Next

Case AppOperation.LinesUnComment
Dim index As Integer
                            ' Iterate through all selected lines of text and determine if the line starts an exlaimation and an apostrophe !'
                            ' indicating that the current line is commented out.  Then remove the apostrophe to Uncomment the line
                            For index = firstLine To lastLine
                                If editor.Document.Lines.Item(index).Text.StartsWith("!'") Then
                                    editor.Document.Lines.Item(index).Text = editor.Document.Lines.Item(index).Text.Remove(1, 1)
                                End If
                            Next


End Select
The latest build of this product (v23.1.2) was released 13 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.