Ejemplo n.º 1
0
        public void GetLastTag()
        {
            DocumentEditor editor = new DocumentEditor();
            TextBuffer     buffer = editor.Buffer;

            TextIter insertIter = buffer.StartIter;

            buffer.Insert(ref insertIter, "Start Extern Region ");
            buffer.InsertWithTagsByName(ref insertIter, "Intern Region", "Type:Attributes");
            int index = insertIter.Offset - 1;

            buffer.Insert(ref insertIter, "End Extern Region");
            buffer.ApplyTag("Type", buffer.StartIter, insertIter);

            TextTag expectedTag = buffer.TagTable.Lookup("Type:Attributes");
            TextTag actualTag   = DocumentUtils.GetLastTag(buffer.GetIterAtOffset(index));

            Assert.AreEqual(expectedTag, actualTag, "GLT01");
        }
Ejemplo n.º 2
0
        private void OnInsertText(object sender, InsertTextArgs args)
        {
            int    offset = args.Pos.Offset - args.Length;
            string text   = args.Text;

            TextIter previousIter = GetIterAtOffset(offset - 1);      // Previous is the iter before the insert offset.
            TextIter startIter    = GetIterAtOffset(offset);
            TextIter endIter      = GetIterAtOffset(offset + text.Length);

            // Only handle special inserting cases when we have a fully loaded document.
            if (document_loaded)
            {
                        #if DEBUG
                Console.WriteLine("DEBUG: Inserting: {0}", text);
                Console.WriteLine("DEBUG: Start Offset: {0} Char: {1}", startIter.Offset, startIter.Char);
                Console.WriteLine("DEBUG: End Offset: {0} Char: {1}", endIter.Offset, endIter.Char);
                        #endif

                TextTag lastEnd      = DocumentUtils.GetLastTag(endIter);
                TextTag lastPrevious = DocumentUtils.GetLastTag(previousIter);

                if (endIter.BeginsTag(lastEnd) && lastEnd.Editable)
                {
                                #if DEBUG
                    Console.WriteLine("DEBUG: Inserting text at start of editable region.");
                    Console.WriteLine("DEBUG: Tag Name: {0} Char: {1}", lastEnd.Name, endIter.Char);
                                #endif

                    ApplyTag(lastEnd, startIter, endIter);
                }
                else if (DocumentUtils.TagEndsHere(lastPrevious, previousIter, startIter) && lastPrevious.Editable)
                {
                                #if DEBUG
                    Console.WriteLine("DEBUG: Inserting text at end of editable region.");
                    Console.WriteLine("DEBUG: Tag Name: {0} Char: {1}", lastPrevious.Name, previousIter.Char);
                                #endif

                    ApplyTag(lastPrevious, startIter, endIter);
                }
            }
        }
Ejemplo n.º 3
0
        private void OnDeleteRange(object sender, DeleteRangeArgs args)
        {
            TextIter startIter = GetIterAtOffset(args.Start.Offset - 1);
            TextIter endIter   = GetIterAtOffset(args.Start.Offset);

                #if DEBUG
            Console.WriteLine("DEBUG: Deleting range");
                #endif

            bool startsRegion = startIter.Char.Equals("[");
            bool endsRegion   = endIter.Char.Equals("]");

            if (startsRegion && endsRegion)
            {
                        #if DEBUG
                Console.WriteLine("DEBUG: Deleting whole editing region.");
                        #endif

                TextTag last = DocumentUtils.GetAssociatedTextTag(this, DocumentUtils.GetLastTag(startIter));
                Undoer.FreezeUndo();
                InsertWithTags(ref endIter, "Documentation for this section has not yet been entered.", last);
                Undoer.ThrawUndo();
            }
        }