internal void FireModified(NativeScintillaEventArgs ea)
        {
            //	First we fire the INativeScintilla Modified event.
            if(Events[_modifiedEventKey] != null)
                ((EventHandler<NativeScintillaEventArgs>)Events[_modifiedEventKey])(this, ea);

            //	Now we use raw information from the Modified event to construct
            //	some more user friendly Events to fire.
            SCNotification scn	= ea.SCNotification;
            int modType			= scn.modificationType;

            if((modType & TEXT_MODIFIED_FLAGS) > 0)
            {
                TextModifiedEventArgs mea = new TextModifiedEventArgs
                    (
                    modType,
                    (modType | Constants.SC_PERFORMED_USER) > 0,
                    scn.line,
                    scn.position,
                    scn.length,
                    scn.linesAdded,
                    Utilities.PtrToStringUtf8(scn.text, scn.length)
                    );

                //	These messages all get fired seperately hence the if else ifs
                if((modType & Constants.SC_MOD_BEFOREDELETE) > 0)
                    OnBeforeTextDelete(mea);
                else if((modType & Constants.SC_MOD_BEFOREINSERT) > 0)
                    OnBeforeTextInsert(mea);
                else if((modType & Constants.SC_MOD_DELETETEXT) > 0)
                    OnTextDeleted(mea);
                else if((modType & Constants.SC_MOD_INSERTTEXT) > 0)
                    OnTextInserted(mea);
            }
            else if((modType & Constants.SC_MOD_CHANGEFOLD) > 0)
            {
                FoldChangedEventArgs fea = new FoldChangedEventArgs(scn.line, scn.foldLevelNow, scn.foldLevelPrev, scn.modificationType);
                OnFoldChanged(fea);
            }
            else if((modType & Constants.SC_MOD_CHANGESTYLE) > 0)
            {
                StyleChangedEventArgs sea = new StyleChangedEventArgs(scn.position, scn.length, scn.modificationType);
                OnStyleChanged(sea);
            }
            else if((modType & Constants.SC_MOD_CHANGEMARKER) > 0)
            {
                MarkerChangedEventArgs mea = new MarkerChangedEventArgs(scn.line, scn.modificationType);
                OnMarkerChanged(mea);
            }

            OnDocumentChange(ea);
        }
Esempio n. 2
0
        protected virtual void OnBeforeTextInsert(TextModifiedEventArgs e)
        {
            List<ManagedRange> offsetRanges = new List<ManagedRange>();
            foreach (ManagedRange mr in _managedRanges)
            {
                if (mr.Start == e.Position && mr.PendingDeletion)
                {
                    mr.PendingDeletion = false;
                    ManagedRange lmr = mr;
                    BeginInvoke(new MethodInvoker(delegate() { lmr.Change(e.Position, e.Position + e.Length); }));
                }

                //	If the Range is a single point we treat it slightly
                //	differently than a spanned range
                if (mr.IsPoint)
                {
                    //	Unlike a spanned range, if the insertion point of
                    //	the new text == the start of the range (and thus
                    //	the end as well) we offset the entire point.
                    if (mr.Start >= e.Position)
                        mr.Change(mr.Start + e.Length, mr.End + e.Length);
                    else if (mr.End >= e.Position)
                        mr.Change(mr.Start, mr.End + e.Length);
                }
                else
                {
                    //	We offset a spanned range entirely only if the
                    //	start occurs after the insertion point of the new
                    //	text.
                    if (mr.Start > e.Position)
                        mr.Change(mr.Start + e.Length, mr.End + e.Length);
                    else if (mr.End >= e.Position)
                    {
                        //	However it the start of the range == the insertion
                        //	point of the new text instead of offestting the
                        //	range we expand it.
                        mr.Change(mr.Start, mr.End + e.Length);
                    }
                }

            }

            if (Events[_beforeTextInsertEventKey] != null)
                ((EventHandler<TextModifiedEventArgs>)Events[_beforeTextInsertEventKey])(this, e);
        }
Esempio n. 3
0
 protected virtual void OnTextInserted(TextModifiedEventArgs e)
 {
     if (Events[_textInsertedEventKey] != null)
         ((EventHandler<TextModifiedEventArgs>)Events[_textInsertedEventKey])(this, e);
 }
Esempio n. 4
0
        protected virtual void OnBeforeTextDelete(TextModifiedEventArgs e)
        {
            int firstPos = e.Position;
            int lastPos = firstPos + e.Length;

            List<ManagedRange> deletedRanges = new List<ManagedRange>();
            foreach (ManagedRange mr in _managedRanges)
            {

                //	These ranges lie within the deleted range so
                //	the ranges themselves need to be deleted
                if (mr.Start >= firstPos && mr.End <= lastPos)
                {

                    //	If the entire range is being delete and NOT a superset of the range,
                    //	don't delete it, only collapse it.
                    if (!mr.IsPoint && e.Position == mr.Start && (e.Position + e.Length == mr.End))
                    {
                        mr.Change(mr.Start, mr.Start);
                    }
                    else
                    {
                        //	Notify the virtual Range that it needs to cleanup
                        mr.Change(-1, -1);

                        //	Mark for deletion after this foreach:
                        deletedRanges.Add(mr);

                    }
                }
                else if (mr.Start >= lastPos)
                {
                    //	These ranges are merely offset by the deleted range
                    mr.Change(mr.Start - e.Length, mr.End - e.Length);
                }
                else if (mr.Start >= firstPos && mr.Start <= lastPos)
                {
                    //	The left side of the managed range is getting
                    //	cut off
                    mr.Change(firstPos, mr.End - e.Length);
                }
                else if (mr.Start < firstPos && mr.End >= firstPos && mr.End >= lastPos)
                {
                    mr.Change(mr.Start, mr.End - e.Length);
                }
                else if (mr.Start < firstPos && mr.End >= firstPos && mr.End < lastPos)
                {
                    mr.Change(mr.Start, firstPos);
                }

            }

            foreach (ManagedRange mr in deletedRanges)
                mr.Dispose();

            if (Events[_beforeTextDeleteEventKey] != null)
                ((EventHandler<TextModifiedEventArgs>)Events[_beforeTextDeleteEventKey])(this, e);
        }