Exemplo n.º 1
0
        private void FormatBackCodeEditor_TextArea_TextEntered(object sender, TextCompositionEventArgs e)
        {
            // open code completion after the user has pressed dot:
            _completionWindow = new CompletionWindow(FormatBackCodeEditor.TextArea);
            // provide AvalonEdit with the data:
            IList <ICompletionData> data = _completionWindow.CompletionList.CompletionData;

            data.Clear();

            if (_completionDatas == null)
            {
                _completionDatas = StaticContainer.Container.Resolve <ICodeFormatterService>().GetFunctionsInfo()
                                   .Select((funInfo) => new CodeCompletionItem(funInfo.name, funInfo.desc)).Cast <ICompletionData>()
                                   .ToList();
            }

            var stringBetweenCaretAndPrevSpecialChar = CodeStringHelper
                                                       .GetStringBetweenCaretAndPrevSpecialChar(FormatBackCodeEditor.Text, FormatBackCodeEditor.CaretOffset)
                                                       .ToLowerInvariant();

            if (stringBetweenCaretAndPrevSpecialChar == "=>")
            {
                _completionDatas.ForEach(data.Add);
            }
            else
            {
                _completionDatas.Where(completionData => completionData.Text.ToLowerInvariant().Contains(stringBetweenCaretAndPrevSpecialChar)).ForEach(data.Add);
            }

            _completionWindow.Show();
            _completionWindow.Closed += delegate { _completionWindow = null; };
        }
Exemplo n.º 2
0
        public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs)
        {
            var length = CodeStringHelper.GetStringBetweenCaretAndPrevSpecialChar(textArea.Document.Text,
                                                                                  completionSegment.EndOffset).Length;

            textArea.Document.Replace(new AnchorSegment(textArea.Document, completionSegment.Offset - length, length), this.Text);
        }