コード例 #1
0
        void DoReplace(int offset, int length, ITextSource newText)
        {
            if (length == 0 && newText.TextLength == 0)
            {
                return;
            }

            ITextSource removedText;

            if (length == 0)
            {
                removedText = StringTextSource.Empty;
            }
            else if (length < 100)
            {
                removedText = new StringTextSource(rope.ToString(offset, length));
            }
            else
            {
                // use a rope if the removed string is long
                removedText = new RopeTextSource(rope.GetRange(offset, length));
            }

            cachedText      = null;        // reset cache of complete document text
            fireTextChanged = true;

            lock (lockObject) {
                // now update the textBuffer and lineTree
                if (offset == 0 && length == rope.Length)
                {
                    // optimize replacing the whole document
                    rope.Clear();
                    var newRopeTextSource = newText as RopeTextSource;
                    if (newRopeTextSource != null)
                    {
                        rope.InsertRange(0, newRopeTextSource.GetRope());
                    }
                    else
                    {
                        rope.InsertText(0, newText.Text);
                    }
                    lineManager.Rebuild();
                }
                else
                {
                    rope.RemoveRange(offset, length);
                    lineManager.Remove(offset, length);
#if DEBUG
                    lineTree.CheckProperties();
#endif
                    var newRopeTextSource = newText as RopeTextSource;
                    if (newRopeTextSource != null)
                    {
                        rope.InsertRange(offset, newRopeTextSource.GetRope());
                    }
                    else
                    {
                        rope.InsertText(offset, newText.Text);
                    }
                    lineManager.Insert(offset, newText);
#if DEBUG
                    lineTree.CheckProperties();
#endif
                }
            }
        }
コード例 #2
0
ファイル: TextDocument.cs プロジェクト: manojdjoshi/dnSpy
		void DoReplace(int offset, int length, ITextSource newText) {
			if (length == 0 && newText.TextLength == 0)
				return;

			ITextSource removedText;
			if (length == 0) {
				removedText = StringTextSource.Empty;
			}
			else if (length < 100) {
				removedText = new StringTextSource(rope.ToString(offset, length));
			}
			else {
				// use a rope if the removed string is long
				removedText = new RopeTextSource(rope.GetRange(offset, length));
			}

			cachedText = null; // reset cache of complete document text
			fireTextChanged = true;

			lock (lockObject) {
				// now update the textBuffer and lineTree
				if (offset == 0 && length == rope.Length) {
					// optimize replacing the whole document
					rope.Clear();
					var newRopeTextSource = newText as RopeTextSource;
					if (newRopeTextSource != null)
						rope.InsertRange(0, newRopeTextSource.GetRope());
					else
						rope.InsertText(0, newText.Text);
					lineManager.Rebuild();
				}
				else {
					rope.RemoveRange(offset, length);
					lineManager.Remove(offset, length);
#if DEBUG
					lineTree.CheckProperties();
#endif
					var newRopeTextSource = newText as RopeTextSource;
					if (newRopeTextSource != null)
						rope.InsertRange(offset, newRopeTextSource.GetRope());
					else
						rope.InsertText(offset, newText.Text);
					lineManager.Insert(offset, newText);
#if DEBUG
					lineTree.CheckProperties();
#endif
				}
			}
		}