Пример #1
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));
		}