Beispiel #1
0
 private async void TextArea_TextEntered(object sender, TextCompositionEventArgs e)
 {
     curblock = GetCurBlock(editor.SelectionStart - 1);
     if (e.Text == ".")
     {
         completewind = new CompletionWindow(editor.TextArea);
         IList <ICompletionData> data = completewind.CompletionList.CompletionData;
         data.Add(new CompletionData("test1"));
         completewind.Show();
         completewind.Closed += delegate
         {
             completewind = null;
         };
     }
     else if (e.Text == "(")
     {
         insertText(editor.SelectionStart, ")");
     }
     else if (e.Text == "{")
     {
         Block2 test = new Block2(null, editor.Document.CreateAnchor(editor.SelectionStart - 1), editor.Document.CreateAnchor(editor.SelectionStart), curblock.depth + 1);
         string tab  = "\n\n";
         for (int i = 0; i < curblock.depth; ++i)
         {
             tab += '\t';
         }
         editor.Document.Insert(editor.SelectionStart, tab + "}");
         test.end = editor.Document.CreateAnchor(editor.SelectionStart - 1);
         curblock.blocks.Add(test);
     }
     else if (e.Text == "$")
     {
         System.Diagnostics.Debug.WriteLine(editor.SelectionStart);
     }
 }
Beispiel #2
0
 private void Document_Changed(object sender, DocumentChangeEventArgs e)
 {
     if (e.RemovedText.Text.Contains("}"))
     {
         int    offset = e.Offset - e.RemovalLength + e.RemovedText.Text.IndexOf("}");
         Block2 block  = GetCurBlock(offset);
         block.state = Block2.DEACTIVE;
     }
 }
Beispiel #3
0
 public Block2(Block2 par, TextAnchor s, TextAnchor e, int d)
 {
     blocks  = new List <Block2>();
     start   = s;
     end     = e;
     parent  = par;
     depth   = d;
     m_state = ACTIVE;
 }
Beispiel #4
0
 public codeeditor(ICSharpCode.AvalonEdit.TextEditor e)
 {
     editor = e;
     editor.TextArea.TextEntered      += TextArea_TextEntered;
     editor.TextArea.TextEntering     += TextArea_TextEntering;
     editor.TextArea.SelectionChanged += TextArea_SelectionChanged;
     editor.Document.Changed          += Document_Changed;
     txts     = new Block2(null, null, null, 0);
     curblock = txts;
 }
Beispiel #5
0
        private Block2 GetCurBlock(int pos)
        {
            bool   flag = true;
            Block2 cur  = new Block2(null, null, null, 0);

            cur = txts;
            while (true)
            {
                flag = true;
                foreach (Block2 o in cur.blocks)
                {
                    if (o.startpos <= pos && o.endpos >= pos && o.state == Block2.ACTIVE)
                    {
                        flag = false;
                        cur  = o;
                        break;
                    }
                }
                if (flag)
                {
                    return(cur);
                }
            }
        }