private void HandleSelfClosingPairs(AutoCompleteEventArgs e, ICodeModule module, Selection pSelection)
        {
            if (!pSelection.IsSingleCharacter)
            {
                return;
            }

            var currentCode      = e.CurrentLine;
            var currentSelection = e.CurrentSelection;
            //var surroundingCode = GetSurroundingCode(module, currentSelection); // todo: find a way to parse the current instruction

            var original = new CodeString(currentCode, new Selection(0, currentSelection.EndColumn - 1), new Selection(pSelection.StartLine, 1));

            var prettifier = new CodeStringPrettifier(module);

            foreach (var selfClosingPair in _selfClosingPairs)
            {
                CodeString result;
                if (e.Character == '\b' && pSelection.StartColumn > 1)
                {
                    result = _selfClosingPairCompletion.Execute(selfClosingPair, original, '\b');
                }
                else
                {
                    result = _selfClosingPairCompletion.Execute(selfClosingPair, original, e.Character, prettifier);
                }

                if (result != default)
                {
                    using (var pane = module.CodePane)
                    {
                        module.DeleteLines(result.SnippetPosition);
                        module.InsertLines(result.SnippetPosition.StartLine, result.Code);
                        pane.Selection = result.SnippetPosition.Offset(result.CaretPosition);
                        e.Handled      = true;
                        return;
                    }
                }
            }
        }
Exemple #2
0
        private bool Run(SelfClosingPair pair, CodeString original, Keys input, out TestCodeString testResult)
        {
            var sut = new SelfClosingPairCompletionService();

            if (sut.Execute(pair, original, input, out var result))
            {
                testResult = new TestCodeString(result);
                return(true);
            }

            testResult = null;
            return(false);
        }
Exemple #3
0
        private CodeString Run(SelfClosingPair pair, CodeString original, Keys input)
        {
            var sut = new SelfClosingPairCompletionService(null);

            return(sut.Execute(pair, original, input));
        }