public void TextReplaced (object sender, ReplaceEventArgs args)
		{
			if (args.Count > 0)
				TextRemove (args.Offset, args.Count);
			if (args.Value != null && args.Value.Length > 0)
				TextInsert (args.Offset, args.Value);
		}
Esempio n. 2
0
 public void TextReplaced(object sender, ReplaceEventArgs args)
 {
     if (args.Count > 0)
     {
         TextRemove(args.Offset, args.Count);
     }
     if (!string.IsNullOrEmpty(args.Value))
     {
         TextInsert(args.Offset, args.Value);
     }
 }
Esempio n. 3
0
 public void TextReplaced(object sender, ReplaceEventArgs args)
 {
     if (args.Count > 0)
     {
         TextRemove(args.Offset, args.Count);
     }
     if (args.Value != null && args.Value.Length > 0)
     {
         TextInsert(args.Offset, args.Value);
     }
 }
Esempio n. 4
0
        void UpdateOnTextReplace(object sender, ReplaceEventArgs e)
        {
            if (e.Count == 0)
            {
                var length = (e.Value != null ? e.Value.Length : 0);
                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.Value != null ? e.Value.Length : 0) - e.Count;

            foreach (var segment in GetSegmentsOverlapping(e.Offset, e.Count))
            {
                if (segment.Offset <= e.Offset)
                {
                    if (segment.EndOffset >= e.Offset + e.Count)
                    {
                        segment.Length += delta;
                    }
                    else
                    {
                        segment.Length = e.Offset - segment.Offset;
                    }
                    segment.UpdateAugmentedData();
                    continue;
                }
                int remainingLength = segment.EndOffset - (e.Offset + e.Count);
                Remove(segment);
                if (remainingLength > 0)
                {
                    segment.Offset = e.Offset + e.Count;
                    segment.Length = remainingLength;
                    Add(segment);
                }
            }

            var next = SearchFirstSegmentWithStartAfter(e.Offset + 1);

            if (next != null)
            {
                next.DistanceToPrevNode += delta;
                next.UpdateAugmentedData();
            }
        }
        void UpdateLinksOnTextReplace(object sender, ReplaceEventArgs e)
        {
            wasReplaced = true;
            int offset = e.Offset - baseOffset;
            int delta  = -e.Count + (!string.IsNullOrEmpty(e.Value) ? e.Value.Length : 0);

            if (!IsInUpdate && !links.Where(link => link.Links.Where(segment => segment.Contains(offset) || segment.EndOffset == offset).Any()).Any())
            {
                SetCaretPosition = false;
                ExitTextLinkMode();
                return;
            }
            AdjustLinkOffsets(offset, delta);
            UpdateTextLinks();
        }
Esempio n. 6
0
		void HandleDataDocumentTextReplaced (object sender, ReplaceEventArgs e)
		{
			var data = dict[(Document)sender];
			localUpdate.Remove (data);
			info.Document.Editor.Replace (e.Offset, e.Count, e.Value);
			localUpdate.Add (data);
			CreateDiff ();
		}
		void HandleDataDocumentTextReplaced (object sender, ReplaceEventArgs e)
		{
			var data = dict[(Document)sender];
			localUpdate.Remove (data);
			var editor = info.Document.GetContent<IEditableTextFile> ();
			editor.DeleteText (e.Offset, e.Count);
			editor.InsertText (e.Offset, e.Value);
			localUpdate.Add (data);
			UpdateDiff ();
		}
Esempio n. 8
0
		void HandleInfoDocumentTextEditorDataDocumentTextReplaced (object sender, ReplaceEventArgs e)
		{
			foreach (var data in localUpdate.ToArray ()) {
				data.Document.TextReplaced -= HandleDataDocumentTextReplaced;
				data.Replace (e.Offset, e.Count, e.Value);
				data.Document.TextReplaced += HandleDataDocumentTextReplaced;
				data.Document.CommitUpdateAll ();
			}
		}
Esempio n. 9
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 (ReplaceEventArgs 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);
//			}
		}
Esempio n. 10
0
		public void TextReplaced (object sender, ReplaceEventArgs args)
		{
			if (args.Count > 0)
				TextRemove (args.Offset, args.Count);
			if (!string.IsNullOrEmpty (args.Value))
				TextInsert (args.Offset, args.Value);
		}
		public void TextReplaced (object sender, ReplaceEventArgs args)
		{
			throw new NotSupportedException ("Operation not supported on this line splitter.");
		}
		public abstract void TextReplaced (ReplaceEventArgs args);
Esempio n. 13
0
		void UpdateConflictsOnTextReplace (object sender, ReplaceEventArgs e)
		{
			this.UpdateDiff ();
			Mono.TextEditor.Document.UpdateSegments (GetAllConflictingSegments (), e);
		}
		void OnTextReplacing (object s, ReplaceEventArgs a)
		{
			if (a.Count > 0)  {
				oldReplaceText = widget.TextEditor.Document.GetTextAt (a.Offset, a.Count);
			} else {
				oldReplaceText = "";
			}
		}
Esempio n. 15
0
		protected virtual void OnTextReplacing (ReplaceEventArgs args)
		{
			if (TextReplacing != null)
				TextReplacing (this, args);
		}
Esempio n. 16
0
			public UndoOperation (ReplaceEventArgs args, string text)
			{
				this.args = args;
				this.text = text;
			}
Esempio n. 17
0
		void IBuffer.Replace (int offset, int count, string value)
		{
			if (atomicUndoLevel == 0) {
				if (this.syntaxMode != null && !SuppressHighlightUpdate)
					Mono.TextEditor.Highlighting.SyntaxModeService.WaitUpdate (this);
			}
			InterruptFoldWorker ();
			//			Mono.TextEditor.Highlighting.SyntaxModeService.WaitForUpdate (true);
			//			Debug.Assert (count >= 0);
			//			Debug.Assert (0 <= offset && offset + count <= Length);
			int oldLineCount = this.LineCount;
			var args = new ReplaceEventArgs (offset, count, value);
			if (Partitioner != null)
				Partitioner.TextReplacing (args);
			OnTextReplacing (args);
			value = args.Value;
			/* insert/repla
			lock (syncObject) {
				int endOffset = offset + count;
				foldSegments = new List<FoldSegment> (foldSegments.Where (s => (s.Offset < offset || s.Offset >= endOffset) && 
				                                                               (s.EndOffset <= offset || s.EndOffset >= endOffset)));
			}*/	
			UndoOperation operation = null;
			if (!isInUndo) {
				operation = new UndoOperation (args, count > 0 ? GetTextAt (offset, count) : "");
				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);
			if (Partitioner != null)
				Partitioner.TextReplaced (args);
			OnTextReplaced (args);
			
			UpdateUndoStackOnReplace (args);
			if (operation != null)
				operation.Setup (this, args);
			
			if (this.syntaxMode != null && !SuppressHighlightUpdate) {
				Mono.TextEditor.Highlighting.SyntaxModeService.StartUpdate (this, this.syntaxMode, offset, value != null ? offset + value.Length : offset + count);
			}
			if (oldLineCount != LineCount)
				this.CommitLineToEndUpdate (this.OffsetToLocation (offset).Line);
		}
Esempio n. 18
0
		public static void UpdateSegments (IEnumerable<ISegment> segments, ReplaceEventArgs args)
		{
			int delta = -args.Count + (!string.IsNullOrEmpty (args.Value) ? args.Value.Length : 0);
			foreach (ISegment segment in segments) {
				if (args.Offset < segment.Offset) {
					segment.Offset += delta;
				} else if (args.Offset <= segment.EndOffset) {
					segment.Length += delta;
				}
			}
		}
Esempio n. 19
0
		void UpdateConflictsOnTextReplace (object sender, ReplaceEventArgs e)
		{
			Document.UpdateSegments (GetAllConflictingSegments (), e);
		}
		void HandleTextReplaced (object sender, ReplaceEventArgs e)
		{
			RemoveCachedLine (Document.GetLineByOffset (e.Offset));
			if (mouseSelectionMode == MouseSelectionMode.Word && e.Offset < mouseWordStart) {
				int delta = -e.Count;
				if (!string.IsNullOrEmpty (e.Value))
					delta += e.Value.Length;
				mouseWordStart += delta;
				mouseWordEnd += delta;
			}
			
			if (selectedRegions.Count > 0) {
				List<ISegment> newRegions = new List<ISegment> (this.selectedRegions);
				Document.UpdateSegments (newRegions, e);
				this.selectedRegions = newRegions;
				RefreshSearchMarker ();
			}
		}
Esempio n. 21
0
			/// <summary>
			/// Marks necessary lines modified when text is replaced
			/// </summary>
			private void EditorDocumentTextReplacing (object sender, ReplaceEventArgs e)
			{
				int  startLine = widget.Editor.Document.OffsetToLineNumber (e.Offset),
				     endLine = widget.Editor.Document.OffsetToLineNumber (e.Offset + Math.Max (e.Count, e.Value != null ? e.Value.Length : 0)),
				     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.Value)) {
						for (int i=0; i<lineCount; ++i)
							annotations.Insert (startLine - 1, locallyModified);
					}
					return;
				} else if (0 == e.Count) {
						// insert
						tokens = e.Value.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);
			}
 public void TextReplaced(object sender, ReplaceEventArgs args)
 {
     throw new NotSupportedException("Operation not supported on this line splitter.");
 }
Esempio n. 23
0
		private void BufferChanged (object sender, ReplaceEventArgs args)
		{
			if (TextChanged != null)
				TextChanged (this, EventArgs.Empty);
		}
Esempio n. 24
0
			static int GetDelta (ReplaceEventArgs args)
			{
				int result = -args.Count;
				if (!String.IsNullOrEmpty (args.Value))
					result += args.Value.Length;
				return result;
			}
		public virtual void TextReplacing (ReplaceEventArgs args)
		{
		}
		void HandleTextEditorDataDocumentTextReplaced (object sender, ReplaceEventArgs e)
		{
			RemoveMarkers (false);
		}
Esempio n. 27
0
			internal void Setup (Document doc, ReplaceEventArgs args)
			{
				if (args != null) {
					this.startOffset = args.Offset;
					if (!String.IsNullOrEmpty (args.Value))
						this.length  = args.Value.Length;
				}
			}
		void OnTextReplaced (object s, ReplaceEventArgs 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.Value != null) {
				i=0;
				string sb = a.Value;
				while (i < sb.Length) {
					if (sb [i] == '\n')
						lines++;
					i++;
				}
			}
			if (lines != 0)
				TextFileService.FireLineCountChanged (this, location.Line, lines, location.Column);
		}
Esempio n. 29
0
			internal virtual void InformTextReplace (ReplaceEventArgs args)
			{
				if (args.Offset < startOffset) {
					startOffset = System.Math.Max (startOffset + GetDelta(args), args.Offset);
				} else if (args.Offset < startOffset + length) {
					length = System.Math.Max (length + GetDelta(args), startOffset - args.Offset);
				}
			}
Esempio n. 30
0
		void HandleSkipCharsOnReplace (object sender, ReplaceEventArgs args)
		{
			for (int i = 0; i < skipChars.Count; i++) {
				SkipChar sc = skipChars[i];
				if (args.Offset < sc.Start || args.Offset > sc.Offset) {
					skipChars.RemoveAt (i);
					i--;
					continue;
				}
				if (args.Offset <= sc.Offset) {
					sc.Offset -= args.Count;
					if (!string.IsNullOrEmpty (args.Value)) {
						sc.Offset += args.Value.Length;
					}
				}
			}
		}
Esempio n. 31
0
			internal override void InformTextReplace (ReplaceEventArgs args)
			{
				operations.ForEach (o => o.InformTextReplace (args));
			}