Torna al Thread

Option Strict Off Option Explicit Off Imports EnvDTE Imports EnvDTE80 Imports System.Diagnostics Imports Microsoft.VisualBasic Imports Microsoft.VisualBasic.ControlChars Public Module HtmlEntitiesAutocomplete Dim ParamArr() As String Dim previousSelection As String Dim completionWords As String Dim completionWordsIndex As Integer ' Auto-completion macro. Sub AddToCompletionWords(ByVal word As String) ' If the word is already there, abort. If InStr(1, completionWords, " " & word & " ", 1) <> 0 Then Exit Sub End If If word <> " " Then completionWords = completionWords & word & " " End If End Sub Private Function ExtractNextCompletionWord() ExtractNextCompletionWord = "" ' If no words yet, go away. If Len(completionWords) <= 1 Then Exit Function End If ' Wrap to beginning if necessary. If completionWordsIndex > Len(completionWords) Then completionWordsIndex = 2 End If ' Find next <space>. Dim newIndex As Integer newIndex = InStr(completionWordsIndex, completionWords, " ", 0) If newIndex = 0 Then Exit Function End If ExtractNextCompletionWord = Mid(completionWords, completionWordsIndex, newIndex - completionWordsIndex) completionWordsIndex = newIndex + 1 ' Skip over <space>. End Function Sub FillCompletionWords(ByVal word As String) ' Find all words in this file which match word, and ' add them, space separated, to completionWords. previousSelection = word completionWords = " " completionWordsIndex = 2 Dim sel As EnvDTE.TextSelection sel = DTE.ActiveDocument.Selection Dim searchString As String searchString = "[^a-zA-Z0-9]" & word Dim firstTime As Boolean firstTime = True Dim firstLine, firstCol As Integer sel.StartOfDocument() Do While sel.FindText(searchString, vsFindOptions.vsFindOptionsRegularExpression) If firstTime Then firstLine = sel.TopLine firstCol = sel.CurrentColumn firstTime = False ElseIf firstLine = sel.TopLine And firstCol = sel.CurrentColumn Then Exit Do ' Jump out of loop before repeat. End If sel.WordRight() sel.WordLeft(DsMovementOptions.dsExtend) AddToCompletionWords(Trim(sel.Text)) sel.Cancel() Loop End Sub Function SuggestNextCompletionWord() SuggestNextCompletionWord = True Dim selection As EnvDTE.TextSelection Dim word As String selection = DTE.ActiveDocument.Selection word = ExtractNextCompletionWord() If word <> "" Then selection.Text = word previousSelection = word End If selection.WordLeft(DsMovementOptions.dsExtend) End Function Sub AutoCompleteHtmlEntities() ' DESCRIPTION: Looks through the active file, searching for the rest of the word that you began to type. Dim doc As EnvDTE.Document Dim sel As EnvDTE.TextSelection Dim origLine, origCol As Integer doc = DTE.ActiveDocument completionWords = "&nbsp; &gt; &lt; &ggt; &gggt" ' Be sure active document is a text document. If doc Is Nothing Then Exit Sub ElseIf doc.Type <> "Text" Then Exit Sub End If ' Get word to be completed. sel = doc.Selection sel.Cancel() origLine = sel.CurrentLine origCol = sel.CurrentColumn sel.WordLeft(DsMovementOptions.dsExtend) ' If the cursor is sitting just to the right of a space, an infinite loop ' results. This bit of code protects from that: If Right(sel.Text, 1) = " " Then sel.CharRight() Exit Sub End If FillCompletionWords(sel.Text) sel.MoveToLineAndOffset(origLine, origCol) sel.WordLeft(DsMovementOptions.dsExtend) SuggestNextCompletionWord() End Sub End Module
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5