Exemplo n.º 1
0
 void TrackDocument_TextChanged(object sender, MonoDevelop.Core.Text.TextChangeEventArgs e)
 {
     for (int i = 0; i < e.TextChanges.Count; ++i)
     {
         var change        = e.TextChanges[i];
         var startLine     = trackDocument.GetLineByOffset(change.NewOffset);
         var endLine       = trackDocument.GetLineByOffset(change.NewOffset + change.InsertionLength);
         var lineNumber    = startLine.LineNumber;
         var insertedLines = endLine.LineNumber - lineNumber;
         if (insertedLines == 0)
         {
             var oldState = lineNumber < lineStates.Count ? lineStates [lineNumber] : null;
             if (oldState != null && oldState.state == TextDocument.LineState.Dirty)
             {
                 continue;
             }
             lineStates[lineNumber] = LineChangeInfo.Dirty;
             if (trackDocument != null)
             {
                 trackDocument.CommitMultipleLineUpdate(lineNumber, lineNumber + insertedLines);
             }
             continue;
         }
         try {
             lineStates.InsertRange(lineNumber, insertedLines, LineChangeInfo.Dirty);
             if (trackDocument != null)
             {
                 trackDocument.CommitMultipleLineUpdate(lineNumber, lineNumber + insertedLines);
             }
         } catch (Exception ex) {
             Console.WriteLine("error while DiffTracker.TrackDocument_TextChanged:" + ex);
         }
     }
 }
Exemplo n.º 2
0
        void TrackDocument_TextChanged(object sender, MonoDevelop.Core.Text.TextChangeEventArgs e)
        {
            if (lineStates == null || e.TextChanges.Count == 0)
            {
                return;
            }
            for (int i = e.TextChanges.Count - 1; i >= 0; i--)
            {
                var change = e.TextChanges [i];
                if (change.RemovalLength == 0)
                {
                    continue;
                }

                var startLine     = trackDocumentSnapshot.GetLineByOffset(change.Offset);
                var endRemoveLine = trackDocumentSnapshot.GetLineByOffset(change.Offset + change.RemovalLength);
                if (startLine == null || endRemoveLine == null)
                {
                    continue;
                }
                try {
                    var lineNumber = startLine.LineNumber;
                    lineStates.RemoveRange(lineNumber, endRemoveLine.LineNumber - lineNumber);
                } catch (Exception ex) {
                    LoggingService.LogError("error while DiffTracker.TrackDocument_TextChanged changing update", ex);
                }
            }

            for (int i = 0; i < e.TextChanges.Count; ++i)
            {
                var change        = e.TextChanges[i];
                var startLine     = trackDocument.GetLineByOffset(change.NewOffset);
                var endLine       = trackDocument.GetLineByOffset(change.NewOffset + change.InsertionLength);
                var lineNumber    = startLine.LineNumber;
                var insertedLines = endLine.LineNumber - lineNumber;
                if (insertedLines == 0)
                {
                    var oldState = lineNumber < lineStates.Count ? lineStates [lineNumber] : null;
                    if (oldState != null && oldState.state == TextDocument.LineState.Dirty)
                    {
                        continue;
                    }
                    lineStates[lineNumber] = LineChangeInfo.Dirty;
                    if (trackDocument != null)
                    {
                        trackDocument.CommitMultipleLineUpdate(lineNumber, lineNumber + insertedLines);
                    }
                    continue;
                }
                try {
                    lineStates.InsertRange(lineNumber, insertedLines, LineChangeInfo.Dirty);
                    if (trackDocument != null)
                    {
                        trackDocument.CommitMultipleLineUpdate(lineNumber, lineNumber + insertedLines);
                    }
                } catch (Exception ex) {
                    LoggingService.LogError("error while DiffTracker.TrackDocument_TextChanged changed update", ex);
                }
            }
            trackDocumentSnapshot = trackDocument.CreateDocumentSnapshot();
        }