Ejemplo n.º 1
0
		public virtual int ReplaceAll (string withPattern)
		{
			int result = 0;
			using (var undo = textEditorData.OpenUndoGroup ()) {
				int offset = 0;
				if (!SearchRequest.SearchRegion.IsInvalid)
					offset = SearchRequest.SearchRegion.Offset;
				SearchResult searchResult; 
				var text = textEditorData.Text;
				var args = new TextViewMargin.SearchWorkerArguments () { Text = text };
				while (true) {
					searchResult = SearchForward (null, args, offset);
					if (searchResult == null || searchResult.SearchWrapped)
						break;
					Replace (searchResult, withPattern);
					offset = searchResult.Offset + withPattern.Length;
					result++;
				}
				if (result > 0)
					textEditorData.ClearSelection ();
			}
			return result;
		}
Ejemplo n.º 2
0
		public override int ReplaceAll (string withPattern)
		{
			var searchResults = new List<SearchResult> ();

			int offset = 0;
			if (!SearchRequest.SearchRegion.IsInvalid)
				offset = SearchRequest.SearchRegion.Offset;
			SearchResult searchResult; 
			var text = textEditorData.Text;
			var args = new TextViewMargin.SearchWorkerArguments () { Text = text };
			while (true) {
				searchResult =  SearchForward (null, args, offset);
				if (searchResult == null || searchResult.SearchWrapped)
					break;
				searchResults.Add (searchResult);
				offset = searchResult.Offset + withPattern.Length;
			}
			if (searchResults.Count < 100) {
				foreach (var sr in searchResults)
					Replace (sr, withPattern);
				if (searchResults.Count > 0)
					textEditorData.ClearSelection ();
			} else {
				var first = searchResults[0];
				char[] oldText = text.ToCharArray ();
				char[] newText = new char[oldText.Length + searchResults.Count * (withPattern.Length - first.Length)];
				char[] pattern = withPattern.ToCharArray ();
				int curOffset = 0, destOffset = 0;
				foreach (var sr in searchResults) {
					var length = sr.Offset - curOffset;
					Array.Copy (oldText, curOffset, newText, destOffset, length);
					destOffset += length;
					Array.Copy (pattern, 0, newText, destOffset, pattern.Length);
					destOffset += withPattern.Length;
					curOffset = sr.EndOffset;
				}
				var l = textEditorData.Length - curOffset;
				Array.Copy (oldText, curOffset, newText, destOffset, l);

				textEditorData.Replace (0, textEditorData.Length, new string (newText));
				textEditorData.ClearSelection ();
			}
			return searchResults.Count;
		}
Ejemplo n.º 3
0
		public override int ReplaceAll (string withPattern)
		{
			var searchResults = new List<SearchResult> ();

			int offset = 0;
			if (!SearchRequest.SearchRegion.IsInvalid)
				offset = SearchRequest.SearchRegion.Offset;
			SearchResult searchResult; 
			var text = textEditorData.Text;
			var args = new TextViewMargin.SearchWorkerArguments { Text = text };
			while (true) {
				searchResult = SearchForward (null, args, offset);
				if (searchResult == null || searchResult.SearchWrapped)
					break;
				searchResults.Add (searchResult);
				offset = searchResult.EndOffset;
			}
			using (var undo = textEditorData.OpenUndoGroup ()) {
				for (int i = searchResults.Count - 1; i >= 0; i--) {
					Replace (searchResults [i], withPattern);
				}
				if (searchResults.Count > 0)
					textEditorData.ClearSelection ();
			}
			return searchResults.Count;
		}