private void TrackInsertText(NativeMethods.SCNotification scn)
        {
            var startLine = scintilla.DirectMessage(NativeMethods.SCI_LINEFROMPOSITION, new IntPtr(scn.position)).ToInt32();

            if (scn.linesAdded == 0)
            {
                // That was easy
                var delta = GetCharCount(scn.position, scn.length);
                AdjustLineLength(startLine, delta);
            }
            else
            {
                var lineByteStart  = 0;
                var lineByteLength = 0;

                // Adjust existing line
                lineByteStart  = scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(startLine)).ToInt32();
                lineByteLength = scintilla.DirectMessage(NativeMethods.SCI_LINELENGTH, new IntPtr(startLine)).ToInt32();
                AdjustLineLength(startLine, GetCharCount(lineByteStart, lineByteLength) - CharLineLength(startLine));

                for (int i = 1; i <= scn.linesAdded; i++)
                {
                    var line = startLine + i;

                    // Insert new line
                    lineByteStart += lineByteLength;
                    lineByteLength = scintilla.DirectMessage(NativeMethods.SCI_LINELENGTH, new IntPtr(line)).ToInt32();
                    InsertPerLine(line, GetCharCount(lineByteStart, lineByteLength));
                }
            }
        }
        private void TrackDeleteText(NativeMethods.SCNotification scn)
        {
            var startLine = scintilla.DirectMessage(NativeMethods.SCI_LINEFROMPOSITION, new IntPtr(scn.position)).ToInt32();

            if (scn.linesAdded == 0)
            {
                // That was easy
                var delta = GetCharCount(scn.text, scn.length, scintilla.Encoding);
                AdjustLineLength(startLine, delta * -1);
            }
            else
            {
                // Adjust the existing line
                var lineByteStart  = scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(startLine)).ToInt32();
                var lineByteLength = scintilla.DirectMessage(NativeMethods.SCI_LINELENGTH, new IntPtr(startLine)).ToInt32();
                AdjustLineLength(startLine, GetCharCount(lineByteStart, lineByteLength) - CharLineLength(startLine));

                var linesRemoved = scn.linesAdded * -1;
                for (int i = 0; i < linesRemoved; i++)
                {
                    // Deleted line
                    DeletePerLine(startLine + 1);
                }
            }
        }
        private void ScnModified(NativeMethods.SCNotification scn)
        {
            if ((scn.modificationType & NativeMethods.SC_MOD_DELETETEXT) > 0)
            {
                TrackDeleteText(scn);
            }

            if ((scn.modificationType & NativeMethods.SC_MOD_INSERTTEXT) > 0)
            {
                TrackInsertText(scn);
            }
        }
        internal void RebuildLineData()
        {
            stepLine   = 0;
            stepLength = 0;

            perLineData = new GapBuffer <PerLine>();
            perLineData.Add(new PerLine {
                Start = 0
            });
            perLineData.Add(new PerLine {
                Start = 0
            });                                         // Terminal

            // Fake an insert notification
            var scn = new NativeMethods.SCNotification();

            scn.linesAdded = scintilla.DirectMessage(NativeMethods.SCI_GETLINECOUNT).ToInt32() - 1;
            scn.position   = 0;
            scn.length     = scintilla.DirectMessage(NativeMethods.SCI_GETLENGTH).ToInt32();
            scn.text       = scintilla.DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, new IntPtr(scn.position), new IntPtr(scn.length));
            TrackInsertText(scn);
        }
 public SCNotificationEventArgs(NativeMethods.SCNotification scn)
 {
     this.SCNotification = scn;
 }
 public SCNotificationEventArgs(NativeMethods.SCNotification scn)
 {
     this.SCNotification = scn;
 }