Compartir a través de


IVsCompletionSet.OnCommit Method

Determines how text is completed.

Namespace:  Microsoft.VisualStudio.TextManager.Interop
Assembly:  Microsoft.VisualStudio.TextManager.Interop (in Microsoft.VisualStudio.TextManager.Interop.dll)

Syntax

'Declaración
Function OnCommit ( _
    pszSoFar As String, _
    iIndex As Integer, _
    fSelected As Integer, _
    cCommit As UShort, _
    <OutAttribute> ByRef pbstrCompleteWord As String _
) As Integer
int OnCommit(
    string pszSoFar,
    int iIndex,
    int fSelected,
    ushort cCommit,
    out string pbstrCompleteWord
)
int OnCommit(
    [InAttribute] String^ pszSoFar, 
    [InAttribute] int iIndex, 
    [InAttribute] int fSelected, 
    [InAttribute] unsigned short cCommit, 
    [OutAttribute] String^% pbstrCompleteWord
)
abstract OnCommit : 
        pszSoFar:string * 
        iIndex:int * 
        fSelected:int * 
        cCommit:uint16 * 
        pbstrCompleteWord:string byref -> int 
function OnCommit(
    pszSoFar : String, 
    iIndex : int, 
    fSelected : int, 
    cCommit : ushort, 
    pbstrCompleteWord : String
) : int

Parameters

  • iIndex
    Type: System.Int32
    [in] Index identifying the match completion set item.
  • fSelected
    Type: System.Int32
    [in] Indicates whether a completion item is selected in the completion box. If true, then the value of the pszSoFar parameter is replaced by the text returned by GetDisplayText. If true, this indicates that an S_OK return with the value of pbstrCompleteWord equal to pszSoFar is appropriate default behavior. The default value of fSelected is true.
  • cCommit
    Type: System.UInt16
    [in] Last character that was typed.
  • pbstrCompleteWord
    Type: System.String%
    [out] Returns the complete word.

Return Value

Type: System.Int32
If the method succeeds, it returns S_OK. If it fails, it returns an error code.

Remarks

COM Signature

From textmgr.idl:

HRESULT IVsCompletionSet::OnCommit(
   [in] const WCHAR *pszSoFar,
   [in] long iIndex,
   [in] BOOL fSelected,
   [in] WCHAR cCommit,
   [out] BSTR *pbstrCompleteWord
);

Implement this method to customize when and how statement completions are committed to text.

The default behavior causes a commit if the user presses any of the standard completion characters. The standard completion characters are any non-alphanumeric characters with the exception of "~" and "_". Text replacement occurs at commit only if a best matching text item is currently selected in the statement completion drop list box. It is this text that replaces the text typed so far.

This method is called only if a value of CSF_CUSTOMCOMMIT is specified for the completion set flags. This method is called once for each character that the user types while statement completion is active.

If this method returns S_FALSE, no commit occurs and the character is inserted as a normal (non-completing) character.

Note

Do not return S_FALSE if the character is a TAB or CTRL-ENTER, since these are enforced commit cases.

If this method returns S_OK, a commit occurs. If fSelected is true, then the value returned in pbstrCompleteWord replaces the text typed so far. If fSelected is false or the returned pbstrCompleteWord value is nulla null reference (Nothing in Visual Basic), then the existing text is not replaced at commit.

Examples

The following is an example of the OnCommit method.

STDMETHODIMP CFigStatementCompletion::OnCommit(
   /*[in] */ const WCHAR *pszSoFar,
   /*[in] */ long iIndex,
   /*[in] */ BOOL fSelected,
   /*[in] */ WCHAR cCommit,
   /*[out]*/ BSTR *pbstrCompleteWord )
{
      if (IsCharAlphaNumeric(cCommit) || cCommit == ':' || cCommit == '_')
       {
              // continue trying to match without completion
              return S_FALSE;
       }
       if (null == pbstrCompleteWord)
         return E_POINTER;
       *pbstrCompleteWord = SysAllocString(m_vecCompletions[ iIndex ]);
       return S_OK;
}

.NET Framework Security

See Also

Reference

IVsCompletionSet Interface

Microsoft.VisualStudio.TextManager.Interop Namespace