public override TextFormatInfo[] GetFormatDataForLine(int line, out TextChange change)
        {
            lock (this.lockObject)
            {
                if (this.parseEpisode == null)
                {
                    // We've never started a parse, so do it now.
                    StartNewParse(this.currentChange);
                }

                change = this.currentChange;

                if (this.data.Count > 0)
                {
                    int firstInRange = FindFirstInfoWhere(0, this.data.Count - 1, idx => this.data[idx].Range.End.Line >= line);
                    int firstBeyondRange = FindFirstInfoWhere(0, this.data.Count - 1, idx => this.data[idx].Range.Start.Line > line);

                    if (firstBeyondRange == -1)
                    {
                        firstBeyondRange = this.data.Count;
                    }

                    if (firstInRange == -1 || firstInRange > firstBeyondRange)
                    {
                        return null;
                    }

                    var result = new TextFormatInfo[firstBeyondRange - firstInRange];
                    this.data.CopyTo(firstInRange, result, 0, result.Length);
                    return result;
                }

                return null;
            }
        }
        public void AddChange(TextChange change)
        {
            if (this.changes == null)
            {
                this.changes = new List<TextChange>();
            }

            this.changes.Add(change);
        }
        protected void StartNewParse(TextChange change)
        {
            OnStartingNewParse();

            lock (this.lockObject)
            {
                if (this.parseEpisode != null)
                {
                    this.parseEpisode.Canceled = true;
                }

                this.parseEpisode = new ParseEpisode();
                this.parseEpisode.Start(this, change);
            }
        }
        void OnParseCompleted(ParseEpisode episode)
        {
            bool raiseEvent = false;

            lock (this.lockObject)
            {
                if (episode == this.parseEpisode)
                {
                    this.data = episode.FormatData;
                    this.currentChange = episode.Change;
                    raiseEvent = true;
                }
            }

            if (raiseEvent)
            {
                RaiseFormatDataChangedEvent();
            }
        }
 protected BufferedTextFormatProvider(TextBuffer buffer) : base(buffer)
 {
     this.lockObject = new object();
     this.currentChange = buffer.LastChange;
     this.data = new List<TextFormatInfo>();
 }
 public void Start(BufferedTextFormatProvider owner, TextChange change)
 {
     this.owner = owner;
     this.Change = change;
     ThreadPool.QueueUserWorkItem((o) => DoParse());
 }
            public override bool Write(TextLocation start, TextLocation end, TextData replacement)
            {
                if (!CanWrite(start, end) || replacement == null)
                {
                    throw new ArgumentException();
                }

                var currentData = this.CurrentTextData;
                var newData = TextData.ApplyEdit(currentData, start, end, replacement);
                var newEnd = DetermineNewEnd(start, end, replacement);

                var newChange = new TextChange()
                {
                    OldTextData = currentData,
                    NewTextData = newData,
                    Start = start,
                    OldEnd = end,
                    NewEnd = newEnd,
                    Replacement = replacement
                };

                if (this.lastChange == null)
                {
                    this.firstChange = this.lastChange = newChange;
                }
                else
                {
                    this.lastChange.NextChange = newChange;
                    this.lastChange = newChange;
                }

                if (this.undoUnit != null)
                {
                    this.undoUnit.AddChange(newChange);
                }

                return true;
            }
            public Pencil(TextBuffer buffer, bool forUndoRedo)
            {
                this.buffer = buffer;
                this.firstChange = null;
                this.lastChange = null;

                if (!forUndoRedo)
                {
                    this.undoUnit = new TextUndoUnit();
                }
            }
 public TextDataChangedEventArgs(TextChange change)
 {
     this.Change = change;
 }
Пример #10
0
 public abstract TextFormatInfo[] GetFormatDataForLine(int line, out TextChange change);
 public abstract TextFormatInfo[] GetFormatDataForLine(int line, out TextChange change);