Example #1
0
        public static Condition SetWhileLoop(Condition condition)
        {
            int indent = LineHelper.GetIndent(condition.Prefix);

            condition.Prefix = LineHelper.GenerateIndent(indent) + "while ";
            condition.Suffix = " do";
            return(condition);
        }
Example #2
0
        private static string _getAffix(string value, string[] affixes, out string oAffix)
        {
            int indent = LineHelper.GetIndent(value);

            foreach (string affix in affixes)
            {
                if (value.Contains(affix))
                {
                    oAffix = LineHelper.GenerateIndent(indent) + affix;
                    value  = value.ReplaceOnce(oAffix, "");
                    return(value);
                }
            }

            oAffix = null;
            return(value);
        }
        private void _textArea_TextEntering(object sender, TextCompositionEventArgs e)
        {
            try {
                if (e.Text.Length > 0 && _completionWindow != null)
                {
                    if (!char.IsLetterOrDigit(e.Text[0]) && e.Text[0] != '_' && e.Text[0] != ' ')
                    {
                        string word = AvalonLoader.GetWholeWordAdv(_textEditor.TextArea.Document, _textEditor);

                        var strategy = new RegexSearchStrategy(new Regex(word), true);

                        if ((e.Text[0] != '\t' || e.Text[0] != '\n') && strategy.FindAll(_textEditor.Document, 0, _textEditor.Document.TextLength).Count() > 1)
                        {
                            _completionWindow.Close();
                            return;
                        }

                        string line = _getText(_textEditor.TextArea.Caret.Line);

                        if (line.IndexOf('#') > -1)
                        {
                            _completionWindow.Close();
                            return;
                        }

                        _completionWindow.CompletionList.RequestInsertion(e);
                    }
                    else if (e.Text[0] == ' ')
                    {
                        _completionWindow.Close();
                    }
                }
                if (e.Text.Length > 0 && _completionWindow == null)
                {
                    if (e.Text[0] == '\n')
                    {
                        int currentLine = _textEditor.TextArea.Caret.Line;

                        DocumentLine docLine       = _getLine(currentLine);
                        string       line          = _getText(currentLine);
                        int          currentIndent = LineHelper.GetIndent(line);

                        if (line.EndsWith(":") && _textEditor.CaretOffset >= docLine.EndOffset)
                        {
                            currentIndent++;
                        }

                        if (_textEditor.LineCount == currentLine)
                        {
                            _textEditor.Document.Insert(_textEditor.Document.TextLength, "\n" + LineHelper.GenerateIndent(currentIndent));
                            _textEditor.CaretOffset = _textEditor.Text.Length;
                        }
                        else
                        {
                            var position = _textEditor.CaretOffset;
                            _textEditor.Document.Insert(_textEditor.CaretOffset, "\n" + LineHelper.GenerateIndent(currentIndent));
                            _textEditor.CaretOffset = position + ("\n" + LineHelper.GenerateIndent(currentIndent)).Length;
                        }

                        _textEditor.TextArea.Caret.BringCaretToView();
                        e.Handled = true;
                    }
                }
            }
            catch { }
        }