public ImmutableTextTextSource (ImmutableText immutableText, System.Text.Encoding encoding, bool useBom, ITextSourceVersion version = null)
		{
			if (immutableText == null)
				throw new ArgumentNullException (nameof (immutableText));
			this.immutableText = immutableText;
			this.encoding = encoding;
			UseBOM = useBom;
			this.version = version;
		}
		/// <summary>
		/// Returns the text having the specified text inserted at 
		/// the specified location.
		/// </summary>
		/// <param name="index">index the insertion position.</param>
		/// <param name="txt">txt the text being inserted.</param>
		/// <returns>subtext(0, index).concat(txt).concat(subtext(index))</returns>
		/// <exception cref="IndexOutOfRangeException">if <code>(index &lt; 0) || (index &gt; this.Length)</code></exception>
		public ImmutableText InsertText (int index, ImmutableText txt)
		{
			return GetText (0, index).Concat (txt).Concat (SubText (index));
		}
		/// <summary>
		/// Concatenates the specified text to the end of this text. 
		/// This method is very fast (faster even than 
		/// <code>StringBuffer.append(String)</code>) and still returns
		/// a text instance with an internal binary tree of minimal depth!
		/// </summary>
		/// <param name="that">that the text that is concatenated.</param>
		/// <returns><code>this + that</code></returns>
		public ImmutableText Concat (ImmutableText that)
		{
			return that.Length == 0 ? this : Length == 0 ? that : new ImmutableText (ConcatNodes (EnsureChunked ().root, that.EnsureChunked ().root));
		}
Пример #4
0
		public void Replace (int offset, int count, string value, ICSharpCode.NRefactory.Editor.AnchorMovementType anchorMovementType = AnchorMovementType.Default)
		{
			if (offset < 0)
				throw new ArgumentOutOfRangeException (nameof (offset), "must be > 0, was: " + offset);
			if (offset > TextLength)
				throw new ArgumentOutOfRangeException (nameof (offset), "must be <= TextLength(" + TextLength +"), was: " + offset);
			if (count < 0)
				throw new ArgumentOutOfRangeException (nameof (count), "must be > 0, was: " + count);
			if (ReadOnly)
				return;
			InterruptFoldWorker ();

			//int oldLineCount = LineCount;
			var args = new DocumentChangeEventArgs (offset, count > 0 ? GetTextAt (offset, count) : "", value, anchorMovementType);

			UndoOperation operation = null;
			bool endUndo = false;
			if (!isInUndo) {
				operation = new UndoOperation (args);
				if (currentAtomicOperation != null) {
					currentAtomicOperation.Add (operation);
				} else {
					OnBeginUndo ();
					undoStack.Push (operation);
					endUndo = true;
				}
				redoStack.Clear ();
			}

			if (value != null)
				EnsureSegmentIsUnfolded (offset, value.Length);
			
			OnTextReplacing (args);
			value = args.InsertedText.Text;

			cachedText = null;
			buffer = buffer.RemoveText(offset, count);
			if (!string.IsNullOrEmpty (value))
				buffer = buffer.InsertText (offset, value);
			foldSegmentTree.UpdateOnTextReplace (this, args);
			splitter.TextReplaced (this, args);
			versionProvider.AppendChange (args);
			OnTextReplaced (args);
			if (endUndo)
				OnEndUndo (new UndoOperationEventArgs (operation));
		}
Пример #5
0
		protected TextDocument (ImmutableText buffer,ILineSplitter splitter)
		{
			this.buffer = buffer;
			this.splitter = splitter;
			splitter.LineRemoved += HandleSplitterLineSegmentTreeLineRemoved;
			foldSegmentTree.tree.NodeRemoved += HandleFoldSegmentTreetreeNodeRemoved; 
			textSegmentMarkerTree.InstallListener (this);
			this.diffTracker.SetTrackDocument (this); 
		}
		public ImmutableTextTextReader(ImmutableText immutableText)
		{
			if (immutableText == null)
				throw new ArgumentNullException(nameof (immutableText));
			this.immutableText = immutableText;
		}