IVsCompletionSet::OnCommit Method (String^, Int32, Int32, UInt16, String^)
Determines how text is completed.
Assembly: Microsoft.VisualStudio.TextManager.Interop (in Microsoft.VisualStudio.TextManager.Interop.dll)
int OnCommit( String^ pszSoFar, int iIndex, int fSelected, unsigned short cCommit, [OutAttribute] String^% pbstrCompleteWord )
Parameters
- pszSoFar
-
Type:
System::String^
[in] The text typed so far.
- 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::Int32If the method succeeds, it returns S_OK. If it fails, it returns an error code.
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.
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; }
