IVsCompletionSet.OnCommit(String, Int32, Int32, UInt16, String) Method

Definition

Determines how text is completed.

public:
 int OnCommit(System::String ^ pszSoFar, int iIndex, int fSelected, System::UInt16 cCommit, [Runtime::InteropServices::Out] System::String ^ % pbstrCompleteWord);
int OnCommit(std::wstring const & pszSoFar, int iIndex, int fSelected, unsigned short cCommit, [Runtime::InteropServices::Out] std::wstring const & & pbstrCompleteWord);
public int OnCommit (string pszSoFar, int iIndex, int fSelected, ushort cCommit, out string pbstrCompleteWord);
abstract member OnCommit : string * int * int * uint16 * string -> int
Public Function OnCommit (pszSoFar As String, iIndex As Integer, fSelected As Integer, cCommit As UShort, ByRef pbstrCompleteWord As String) As Integer

Parameters

pszSoFar
String

[in] The text typed so far.

iIndex
Int32

[in] Index identifying the match completion set item.

fSelected
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(Int32, String, Int32[]). 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
UInt16

[in] Last character that was typed.

pbstrCompleteWord
String

[out] Returns the complete word.

Returns

If the method succeeds, it returns S_OK. If it fails, it returns an error code.

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;  
}  

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 null, then the existing text is not replaced at commit.

Applies to