ARCed.Scintilla.SnippetManager.Scintilla_BeforeTextDelete C# (CSharp) Method

Scintilla_BeforeTextDelete() private method

private Scintilla_BeforeTextDelete ( object sender, TextModifiedEventArgs e ) : void
sender object
e TextModifiedEventArgs
return void
        private void Scintilla_BeforeTextDelete(object sender, TextModifiedEventArgs e)
        {
            if (!this._isEnabled)
                return;

            if (this._snippetLinks.IsActive && !this._pendingUndo && !(e.UndoRedoFlags.IsUndo || e.UndoRedoFlags.IsRedo))
            {
                this._pendingUndo = true;
                Scintilla.UndoRedo.BeginUndoAction();
                this._snippetLinkTimer.Enabled = true;
            }

            ManagedRange undoneSnippetLinkRange = null;
            if (e.UndoRedoFlags.IsUndo && this._snippetLinks.IsActive)
            {
                foreach (ManagedRange mr in Scintilla.ManagedRanges)
                {
                    if (mr.Start == e.Position && mr.Length == e.Length && mr.Length > 1)
                    {
                        undoneSnippetLinkRange = mr;

                        //	Expanding the range So that it won't get marked for deletion
                        mr.End++;
                    }
                }
            }

            //	It's possible that the _end point may have been deleted. The endpoint
            //	is an ultra persistent marker that cannot be deleted until the Snippet
            //	Link mode is deactivated. Place a new EndPoint at the begining of the
            //	deleted range.
            if (this._snippetLinks.IsActive && this._snippetLinks.EndPoint != null && this._snippetLinks.EndPoint.Scintilla == null)
            {
                var eci = new SnippetLinkEnd(e.Position, Scintilla);
                Scintilla.ManagedRanges.Add(eci);
                this._snippetLinks.EndPoint = eci;
            }

            //	Now collapse the Undone range in preparation for the
            //	newly inserted text that will be put in here
            if (undoneSnippetLinkRange != null)
                undoneSnippetLinkRange.End = undoneSnippetLinkRange.Start;

            //	Check to see if all SnippetLink ranges have been deleted.
            //	If this is the case we need to turn Deactivate SnippetLink
            //	mode.

            bool deactivate = true;
            foreach (SnippetLink sl in this._snippetLinks.Values)
            {
                if (sl.Ranges.Count > 0)
                {
                    foreach (SnippetLinkRange slr in sl.Ranges)
                    {
                        if (slr.Scintilla != null)
                        {
                            deactivate = false;
                            break;
                        }
                    }
                }
                if (!deactivate)
                    break;
            }

            if (deactivate && this.IsActive)
                this.IsActive = false;
        }