Ejemplo n.º 1
0
 public void TextReplaced(object sender, DocumentChangeEventArgs args)
 {
     if (args.RemovalLength > 0)
     {
         TextRemove(args.Offset, args.RemovalLength);
     }
     if (args.InsertionLength > 0)
     {
         TextInsert(args.Offset, args.InsertedText.Text);
     }
 }
 public static TextSegment AdjustSegment(this TextSegment segment, DocumentChangeEventArgs args)
 {
     if (args.Offset < segment.Offset)
     {
         return(new TextSegment(segment.Offset + args.ChangeDelta, segment.Length));
     }
     if (args.Offset <= segment.EndOffset)
     {
         return(new TextSegment(segment.Offset, segment.Length));
     }
     return(segment);
 }
Ejemplo n.º 3
0
        public void UpdateOnTextReplace(object sender, DocumentChangeEventArgs e)
        {
            IsDirty = true;
            if (e.RemovalLength == 0)
            {
                var length = e.InsertionLength;
                foreach (var segment in GetSegmentsAt(e.Offset).Where(s => s.Offset < e.Offset && e.Offset < s.EndOffset))
                {
                    segment.Length += length;
                    segment.UpdateAugmentedData();
                }
                var node = SearchFirstSegmentWithStartAfter(e.Offset);
                if (node != null)
                {
                    node.DistanceToPrevNode += length;
                    node.UpdateAugmentedData();
                }
                return;
            }
            int delta = e.ChangeDelta;

            foreach (var segment in new List <T> (GetSegmentsOverlapping(e.Offset, e.RemovalLength)))
            {
                if (segment.Offset < e.Offset)
                {
                    if (segment.EndOffset >= e.Offset + e.RemovalLength)
                    {
                        segment.Length += delta;
                    }
                    else
                    {
                        segment.Length = e.Offset - segment.Offset;
                    }
                    segment.UpdateAugmentedData();
                    continue;
                }
                int remainingLength = segment.EndOffset - (e.Offset + e.RemovalLength);
                Remove(segment);
                if (remainingLength > 0)
                {
                    segment.Offset = e.Offset + e.RemovalLength;
                    segment.Length = remainingLength;
                    Add(segment);
                }
            }
            var next = SearchFirstSegmentWithStartAfter(e.Offset + 1);

            if (next != null)
            {
                next.DistanceToPrevNode += delta;
                next.UpdateAugmentedData();
            }
        }
Ejemplo n.º 4
0
        internal void UpdateCaretPosition(DocumentChangeEventArgs e)
        {
            if (e.AnchorMovementType == AnchorMovementType.BeforeInsertion && caretOffset == e.Offset)
            {
                return;
            }
            var curVersion = TextEditorData.Version;

            if (offsetVersion == null)
            {
                offsetVersion = curVersion;
                return;
            }
            var newOffset = offsetVersion.MoveOffsetTo(curVersion, caretOffset);

            offsetVersion = curVersion;
            if (newOffset == caretOffset || !AutoUpdatePosition)
            {
                return;
            }
            DocumentLocation old = Location;
            var newLocation      = TextEditorData.OffsetToLocation(newOffset);
            int newColumn        = newLocation.Column;

            var curLine = TextEditorData.GetLine(newLocation.Line);

            if (TextEditorData.HasIndentationTracker && TextEditorData.Options.IndentStyle == IndentStyle.Virtual && curLine.Length == 0)
            {
                var indentColumn = TextEditorData.GetVirtualIndentationColumn(Location);
                if (column == indentColumn)
                {
                    newColumn = indentColumn;
                }
            }
            if (AllowCaretBehindLineEnd)
            {
                if (curLine != null && column > curLine.Length)
                {
                    newColumn = column;
                }
            }

            line   = newLocation.Line;
            column = newColumn;

            SetDesiredColumn();
            UpdateCaretOffset();
            OnPositionChanged(new DocumentLocationEventArgs(old));
        }
Ejemplo n.º 5
0
        void UpdateLinksOnTextReplace(object sender, DocumentChangeEventArgs e)
        {
            wasReplaced = true;
            int offset = e.Offset - baseOffset;
            int delta  = e.ChangeDelta;

            if (!IsInUpdate && !links.Any(link => link.Links.Any(segment => segment.Contains(offset) ||
                                                                 segment.EndOffset == offset)))
            {
                SetCaretPosition = false;
                ExitTextLinkMode();
                return;
            }
            AdjustLinkOffsets(offset, delta);
            UpdateTextLinks();
        }
		void HandleSkipCharsOnReplace (object sender, DocumentChangeEventArgs args)
		{
			var skipChars = GetTextEditorData ().SkipChars;
			for (int i = 0; i < skipChars.Count; i++) {
				var sc = skipChars [i];
				if (args.Offset > sc.Offset) {
					skipChars.RemoveAt (i);
					i--;
					continue;
				}
				if (args.Offset <= sc.Offset) {
					sc.Offset += args.ChangeDelta;
				}
			}
		}
Ejemplo n.º 7
0
		void OnTextReplacing (object s, DocumentChangeEventArgs a)
		{
			oldReplaceText = a.RemovedText;
		}
Ejemplo n.º 8
0
 public void TextReplaced(object sender, DocumentChangeEventArgs args)
 {
     throw new NotSupportedException("Operation not supported on this line splitter.");
 }
		void HandleTextReplacing (object sender, DocumentChangeEventArgs e)
		{
			wasInVerbatimString = null;
			var o = e.Offset + e.RemovalLength;
			if (o < 0 || o + 1 > textEditorData.Length || e.RemovalLength != 1 || textEditorData.Document.IsInUndo) {
				return;
			}
			if (textEditorData.GetCharAt (o) != '"')
				return;
			SafeUpdateIndentEngine (o + 1);
			wasInVerbatimString = stateTracker.IsInsideVerbatimString;
		}
Ejemplo n.º 10
0
			public UndoOperation (DocumentChangeEventArgs args)
			{
				this.args = args;
			}
		// Handles text modifications in hidden document
		void UnderlyingDocument_TextReplacing (object sender, DocumentChangeEventArgs e)
		{
			if (razorDocument == null)
				return;

			EnsureUnderlyingDocumentSet ();
			int off = CalculateCaretPosition (e.Offset);

			if (e.RemovalLength > 0) {
				int removalLength = e.RemovalLength;
				if (off + removalLength > HiddenDoc.Editor.Length)
					removalLength = HiddenDoc.Editor.Length - off;
				HiddenDoc.Editor.Remove (new TextSegment (off, removalLength));
			}
			if (e.InsertionLength > 0) {
				if (isInCSharpContext)
					HiddenDoc.Editor.Insert (off, e.InsertedText.Text);
				else // Insert spaces to correctly calculate offsets until next reparse
					HiddenDoc.Editor.Insert (off, new String (' ', e.InsertionLength));
			}
			if (codeFragment != null)
				codeFragment.EndOffset += (e.InsertionLength - e.RemovalLength);
		}
Ejemplo n.º 12
0
		public void TextReplaced (object sender, DocumentChangeEventArgs args)
		{
			if (args.RemovalLength > 0)
				TextRemove (args.Offset, args.RemovalLength);
			if (args.InsertionLength > 0)
				TextInsert (args.Offset, args.InsertedText.Text);
		}
Ejemplo n.º 13
0
		public void Replace (int offset, int count, string value, ICSharpCode.NRefactory.Editor.AnchorMovementType anchorMovementType = AnchorMovementType.Default)
		{
			if (offset < 0)
				throw new ArgumentOutOfRangeException ("offset", "must be > 0, was: " + offset);
			if (offset > TextLength)
				throw new ArgumentOutOfRangeException ("offset", "must be <= Length, was: " + offset);
			if (count < 0)
				throw new ArgumentOutOfRangeException ("count", "must be > 0, was: " + count);

			InterruptFoldWorker ();
			//int oldLineCount = LineCount;
			var args = new DocumentChangeEventArgs (offset, count > 0 ? GetTextAt (offset, count) : "", value, anchorMovementType);
			OnTextReplacing (args);
			value = args.InsertedText.Text;
			UndoOperation operation = null;
			if (!isInUndo) {
				operation = new UndoOperation (args);
				if (currentAtomicOperation != null) {
					currentAtomicOperation.Add (operation);
				} else {
					OnBeginUndo ();
					undoStack.Push (operation);
					OnEndUndo (new UndoOperationEventArgs (operation));
				}
				redoStack.Clear ();
			}
			
			buffer.Replace (offset, count, value);
			foldSegmentTree.UpdateOnTextReplace (this, args);
			splitter.TextReplaced (this, args);
			versionProvider.AppendChange (args);
			OnTextReplaced (args);
		}
		void HandleDataDocumentTextReplaced (object sender, DocumentChangeEventArgs e)
		{
			var data = dict [(TextDocument)sender];
			localUpdate.Remove (data);
			var editor = info.Document.GetContent<IEditableTextFile> ();
			editor.DeleteText (e.Offset, e.RemovalLength);
			editor.InsertText (e.Offset, e.InsertedText.Text);
			localUpdate.Add (data);
			UpdateDiff ();
		}
Ejemplo n.º 15
0
			internal override void InformTextReplace (DocumentChangeEventArgs args)
			{
				operations.ForEach (o => o.InformTextReplace (args));
			}
 public static IEnumerable <TextSegment> AdjustSegments(this IEnumerable <TextSegment> segments, DocumentChangeEventArgs args)
 {
     foreach (var segment in segments)
     {
         yield return(segment.AdjustSegment(args));
     }
 }
Ejemplo n.º 17
0
		internal void UpdateCaretPosition (DocumentChangeEventArgs e)
		{
			if (e.AnchorMovementType == AnchorMovementType.BeforeInsertion && caretOffset == e.Offset) {
				offsetVersion = TextEditorData.Version;
				return;
			}
			var curVersion = TextEditorData.Version;
			if (offsetVersion == null) {
				offsetVersion = curVersion;
				return;
			}
			var newOffset = offsetVersion.MoveOffsetTo (curVersion, caretOffset);
			offsetVersion = curVersion;
			if (newOffset == caretOffset || !AutoUpdatePosition)
				return;
			DocumentLocation old = Location;
			var newLocation = TextEditorData.OffsetToLocation (newOffset);
			int newColumn = newLocation.Column;
			
			var curLine = TextEditorData.GetLine (newLocation.Line);
			if (TextEditorData.HasIndentationTracker && TextEditorData.Options.IndentStyle == IndentStyle.Virtual && curLine.Length == 0) {
				var indentColumn = TextEditorData.GetVirtualIndentationColumn (Location);
				if (column == indentColumn) {
					newColumn = indentColumn;
				}
			}
			if (AllowCaretBehindLineEnd) {
				if (curLine != null && column > curLine.Length)
					newColumn = column;
			}
			line = newLocation.Line;
			column = newColumn;

			SetDesiredColumn ();
			UpdateCaretOffset ();
			OnPositionChanged (new DocumentLocationEventArgs (old));
		}
Ejemplo n.º 18
0
		void OnTextReplacing (object sender, DocumentChangeEventArgs e)
		{
			if (lastChange == null)
				lastChange = new ChangeInfo (e.Offset, new SeekableTextReader((sender as TextDocument).Text));
			if (e.ChangeDelta > 0) {
				lastChange.Length += e.InsertionLength;
			} else {
				lastChange.Length -= e.RemovalLength;
			}
		}
Ejemplo n.º 19
0
		private void BufferChanged (object sender, DocumentChangeEventArgs args)
		{
			if (TextChanged != null)
				TextChanged (this, EventArgs.Empty);
		}
		public void TextReplaced (object sender, DocumentChangeEventArgs args)
		{
			throw new NotSupportedException ("Operation not supported on this line splitter.");
		}
Ejemplo n.º 21
0
		// The undo stack needs to be updated on replace, because the text editor
		// draws a replace operation marker at the left margin.
		public void UpdateUndoStackOnReplace (DocumentChangeEventArgs args)
		{
			foreach (UndoOperation op in undoStack) {
				op.InformTextReplace (args);
			}
			// since we're only displaying the undo stack it's not required to update the redo stack
//			foreach (UndoOperation op in redoStack) {
//				op.InformTextReplace (args);
//			}
		}
		void HandleTextReplaced (object sender, DocumentChangeEventArgs e)
		{
			if (e.RemovalLength != 1 || textEditorData.Document.CurrentAtomicUndoOperationType == OperationType.Format) {
				return;
			}
			stateTracker.UpdateEngine (Math.Min (textEditorData.Document.TextLength, e.Offset + e.InsertionLength + 1));
			if (wasInVerbatimString && !stateTracker.Engine.IsInsideVerbatimString) {
				textEditorData.Document.TextReplacing -= HandleTextReplacing;
				textEditorData.Document.TextReplaced -= HandleTextReplaced;;
				ConvertVerbatimStringToNormal (textEditorData, e.Offset + e.InsertionLength + 1);
				textEditorData.Document.TextReplacing += HandleTextReplacing;
				textEditorData.Document.TextReplaced += HandleTextReplaced;;
			}
		}
Ejemplo n.º 23
0
		void HandleTextReplaced (object sender, DocumentChangeEventArgs e)
		{
			caret.UpdateCaretPosition ();
		}
Ejemplo n.º 24
0
			/// <summary>
			/// Marks necessary lines modified when text is replaced
			/// </summary>
			private void EditorDocumentTextReplacing (object sender, DocumentChangeEventArgs e)
			{
				int startLine = widget.Editor.Document.OffsetToLineNumber (e.Offset),
					endLine = widget.Editor.Document.OffsetToLineNumber (e.Offset + Math.Max (e.RemovalLength, e.InsertionLength)),
					lineCount = 0;
				string[] tokens = null;
				
				if (startLine < endLine) {
					// change crosses line boundary
					
					lineCount = endLine - startLine;
					lineCount = Math.Min (lineCount, annotations.Count - startLine);
					
					if (lineCount > 0)
						annotations.RemoveRange (startLine - 1, lineCount);
					if (!string.IsNullOrEmpty (e.InsertedText.Text)) {
						for (int i=0; i<lineCount; ++i)
							annotations.Insert (startLine - 1, locallyModified);
					}
					return;
				} else if (0 == e.RemovalLength) {
					// insert
					tokens = e.InsertedText.Text.Split (new string[]{Environment.NewLine}, StringSplitOptions.None);
						lineCount = tokens.Length - 1;
						for (int i=0; i<lineCount; ++i) {
							annotations.Insert (Math.Min (startLine, annotations.Count), locallyModified);
						}
				} else if (startLine > endLine) {
					// revert
					UpdateAnnotations (null, null);
					return;
				}
				
				SetAnnotation (startLine, locallyModified);
			}
Ejemplo n.º 25
0
		protected virtual void OnTextReplacing (DocumentChangeEventArgs args)
		{
			if (TextReplacing != null)
				TextReplacing (this, args);
		}
Ejemplo n.º 26
0
		void HandleInfoDocumentTextEditorDataDocumentTextReplaced (object sender, DocumentChangeEventArgs e)
		{
			foreach (var data in localUpdate.ToArray ()) {
				data.Document.TextReplaced -= HandleDataDocumentTextReplaced;
				data.Replace (e.Offset, e.RemovalLength, e.InsertedText.Text);
				data.Document.TextReplaced += HandleDataDocumentTextReplaced;
				data.Document.CommitUpdateAll ();
			}
		}
Ejemplo n.º 27
0
		void HandleTextReplaced (object sender, DocumentChangeEventArgs args)
		{
			if (Document.CurrentAtomicUndoOperationType == OperationType.Format)
				return;

			int startIndex = args.Offset;
			foreach (var marker in currentErrorMarkers) {
				var line = marker.LineSegment;
				if (line == null || line.Contains (args.Offset) || line.Contains (args.Offset + args.InsertionLength) || args.Offset < line.Offset && line.Offset < args.Offset + args.InsertionLength) {
					markersToRemove.Enqueue (marker);
				}
			}
			ResetRemoveMarker ();
		}
Ejemplo n.º 28
0
		void HandleDataDocumentTextReplaced (object sender, DocumentChangeEventArgs e)
		{
			var data = dict [(TextDocument)sender];
			localUpdate.Remove (data);
			var editor = info.Document.GetContent<MonoDevelop.Ide.Editor.ITextDocument> ();
			editor.ReplaceText (e.Offset, e.RemovalLength, e.InsertedText.Text);
			localUpdate.Add (data);
			UpdateDiff ();
		}
		void HandleTextEditorDataDocumentTextReplaced (object sender, DocumentChangeEventArgs e)
		{
			RemoveMarkers (false);
		}
Ejemplo n.º 30
0
		void UpdateConflictsOnTextReplace (object sender, DocumentChangeEventArgs e)
		{
			this.UpdateDiff ();
			foreach (var conflict in currentConflicts) {
				conflict.StartSegment = conflict.StartSegment.AdjustSegment (e);
				conflict.DividerSegment = conflict.DividerSegment.AdjustSegment (e);
				conflict.EndSegment = conflict.EndSegment.AdjustSegment (e);
				conflict.MySegment = conflict.MySegment.AdjustSegment (e);
				conflict.TheirSegment = conflict.TheirSegment.AdjustSegment (e);
			}
		}
		void HandleTextReplaced (object sender, DocumentChangeEventArgs e)
		{
			stateTracker.ResetEngineToPosition (e.Offset); 
			if (wasInVerbatimString == null)
				return;
			if (e.RemovalLength != 1 || textEditorData.Document.CurrentAtomicUndoOperationType == OperationType.Format)
				return;
			SafeUpdateIndentEngine (Math.Min (textEditorData.Document.TextLength, e.Offset + e.InsertionLength + 1));
			if (wasInVerbatimString == true && !stateTracker.IsInsideVerbatimString) {
				textEditorData.Document.TextReplacing -= HandleTextReplacing;
				textEditorData.Document.TextReplaced -= HandleTextReplaced;
				ConvertVerbatimStringToNormal (textEditorData, e.Offset + e.InsertionLength + 1);
				textEditorData.Document.TextReplacing += HandleTextReplacing;
				textEditorData.Document.TextReplaced += HandleTextReplaced;
			}
		}
Ejemplo n.º 32
0
		void HandleTextReplaced (object sender, DocumentChangeEventArgs args)
		{
			if (Document.CurrentAtomicUndoOperationType == OperationType.Format)
				return;
			if (!inLoad) {
				if (widget.TextEditor.Document.IsInAtomicUndo) {
					wasEdited = true;
				}
				else {
					InformAutoSave ();
				}
			}

			int startIndex = args.Offset;
			foreach (var marker in currentErrorMarkers) {
				if (marker.LineSegment.Contains (args.Offset) || marker.LineSegment.Contains (args.Offset + args.InsertionLength) || args.Offset < marker.LineSegment.Offset && marker.LineSegment.Offset < args.Offset + args.InsertionLength) {
					markersToRemove.Enqueue (marker);
				}
			}
			ResetRemoveMarker ();
		}
Ejemplo n.º 33
0
			void TextReplaced (object sender, DocumentChangeEventArgs args)
			{
				RequestRedraw ();
			}
Ejemplo n.º 34
0
			internal void Setup (TextDocument doc, DocumentChangeEventArgs args)
			{
				if (args != null) {
					startOffset = args.Offset;
					length = args.InsertionLength;
				}
			}
Ejemplo n.º 35
0
		void HandleTextReplaced (object sender, DocumentChangeEventArgs e)
		{
			RemoveCachedLine (Document.GetLineByOffset (e.Offset));
			if (mouseSelectionMode == MouseSelectionMode.Word && e.Offset < mouseWordStart) {
				int delta = e.ChangeDelta;
				mouseWordStart += delta;
				mouseWordEnd += delta;
			}
			
			if (selectedRegions.Count > 0) {
				this.selectedRegions = new List<TextSegment> (this.selectedRegions.AdjustSegments (e));
				RefreshSearchMarker ();
			}
		}
Ejemplo n.º 36
0
			internal virtual void InformTextReplace (DocumentChangeEventArgs args)
			{
				if (args.Offset < startOffset) {
					startOffset = System.Math.Max (startOffset + args.ChangeDelta, args.Offset);
				} else if (args.Offset < startOffset + length) {
					length = System.Math.Max (length + args.ChangeDelta, startOffset - args.Offset);
				}
			}
Ejemplo n.º 37
0
		void OnTextReplaced (object s, DocumentChangeEventArgs a)
		{
			this.IsDirty = Document.IsDirty;
			
			DocumentLocation location = Document.OffsetToLocation (a.Offset);
			
			int i = 0, lines = 0;
			while (i != -1 && i < oldReplaceText.Length) {
				i = oldReplaceText.IndexOf ('\n', i);
				if (i != -1) {
					lines--;
					i++;
				}
			}

			if (a.InsertedText != null) {
				i = 0;
				string sb = a.InsertedText;
				while (i < sb.Length) {
					if (sb [i] == '\n')
						lines++;
					i++;
				}
			}
			if (lines != 0)
				TextFileService.FireLineCountChanged (this, location.Line, lines, location.Column);
		}
 public void TextReplaced(object sender, DocumentChangeEventArgs args)
 {
 }