IsCaretInsideSnippetFields() private méthode

private IsCaretInsideSnippetFields ( ) : bool
Résultat bool
Exemple #1
0
       public void ExpansionClientTest() {
            var textBuffer = new TextBufferMock("if", RContentTypeDefinition.ContentType);
            var textView = new TextViewMock(textBuffer);
            var client = new ExpansionClient(textView, textBuffer, _expansionManager, _cache);

            client.IsEditingExpansion().Should().BeFalse();
            client.IsCaretInsideSnippetFields().Should().BeFalse();

            _expansionManager.InvokeInsertionUI(null, null, Guid.Empty, new string[0], 0, 0, new string[0], 0, 0, string.Empty, string.Empty)
                .ReturnsForAnyArgs(VSConstants.S_OK);

            client.InvokeInsertionUI((int)VSConstants.VSStd2KCmdID.INSERTSNIPPET).Should().Be(VSConstants.S_OK);

            textView.Caret.MoveTo(new SnapshotPoint(textView.TextBuffer.CurrentSnapshot, 2));

            bool inserted;
            client.StartSnippetInsertion(out inserted);

            inserted.Should().BeTrue();
            client.IsEditingExpansion().Should().BeTrue();

            client.EndExpansion();
            client.IsEditingExpansion().Should().BeFalse();

            client.OnItemChosen("if", "path");
            client.IsEditingExpansion().Should().BeTrue();

            client.EndExpansion();
            client.IsEditingExpansion().Should().BeFalse();
            client.IsCaretInsideSnippetFields().Should().BeFalse();
        }
        public CommandResult Invoke(Guid group, int id, object inputArg, ref object outputArg)
        {
            var hr = VSConstants.E_FAIL;

            if (group == VSConstants.VSStd2K)
            {
                switch ((VSConstants.VSStd2KCmdID)id)
                {
                case VSConstants.VSStd2KCmdID.INSERTSNIPPET:
                case VSConstants.VSStd2KCmdID.SURROUNDWITH:
                    _expansionClient.InvokeInsertionUI(id);
                    return(CommandResult.Executed);

                case VSConstants.VSStd2KCmdID.TAB:
                    if (_expansionClient.IsEditingExpansion())
                    {
                        if (IsPossibleFilePathCompletion())
                        {
                            return(CommandResult.NotSupported);
                        }
                        hr = _expansionClient.GoToNextExpansionField();
                    }
                    else
                    {
                        bool snippetInserted = false;

                        hr = _expansionClient.StartSnippetInsertion(out snippetInserted);
                        if (!snippetInserted)
                        {
                            return(CommandResult.NotSupported);
                        }
                    }
                    break;

                case VSConstants.VSStd2KCmdID.BACKTAB:
                    if (_expansionClient.IsEditingExpansion())
                    {
                        hr = _expansionClient.GoToPreviousExpansionField();
                    }
                    break;

                case VSConstants.VSStd2KCmdID.RETURN:
                    if (!_expansionClient.TextView.IsStatementCompletionWindowActive() && _expansionClient.IsEditingExpansion())
                    {
                        if (_expansionClient.IsCaretInsideSnippetFields())
                        {
                            // End the current expansion session and position the
                            // edit caret according to the code snippet template.
                            _expansionClient.EndExpansionSession(false);
                            return(CommandResult.Executed);
                        }
                        else
                        {
                            // Dev10 710692: if caret is not inside of one of the snippet fields then leave caret at the current position and let the
                            //   editor handles the RETURN
                            _expansionClient.EndExpansionSession(true);
                        }
                    }
                    break;

                case VSConstants.VSStd2KCmdID.CANCEL:
                    if (!_expansionClient.TextView.IsStatementCompletionWindowActive() && _expansionClient.IsEditingExpansion())
                    {
                        _expansionClient.EndExpansionSession(true);
                        return(CommandResult.Executed);
                    }
                    break;
                }
            }

            return(hr == VSConstants.S_OK ? CommandResult.Executed : CommandResult.NotSupported);
        }