当前位置: 首页>>代码示例>>C#>>正文


C# TextDocument.Replace方法代码示例

本文整理汇总了C#中ICSharpCode.AvalonEdit.Document.TextDocument.Replace方法的典型用法代码示例。如果您正苦于以下问题:C# TextDocument.Replace方法的具体用法?C# TextDocument.Replace怎么用?C# TextDocument.Replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.AvalonEdit.Document.TextDocument的用法示例。


在下文中一共展示了TextDocument.Replace方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IndentLine

 public void IndentLine(TextDocument document, DocumentLine line)
 {
     if (document == null || line == null)
     {
         return;
     }
     DocumentLine previousLine = line.PreviousLine;
     if (previousLine != null)
     {
         ISegment indentationSegment = TextUtilities.GetWhitespaceAfter(document, previousLine.Offset);
         string indentation = document.GetText(indentationSegment);
         if (Program.OptionsObject.Editor_AgressiveIndentation)
         {
             string currentLineTextTrimmed = (document.GetText(line)).Trim();
             string lastLineTextTrimmed = (document.GetText(previousLine)).Trim();
             char currentLineFirstNonWhitespaceChar = ' ';
             if (currentLineTextTrimmed.Length > 0)
             {
                 currentLineFirstNonWhitespaceChar = currentLineTextTrimmed[0];
             }
             char lastLineLastNonWhitespaceChar = ' ';
             if (lastLineTextTrimmed.Length > 0)
             {
                 lastLineLastNonWhitespaceChar = lastLineTextTrimmed[lastLineTextTrimmed.Length - 1];
             }
             if (lastLineLastNonWhitespaceChar == '{' && currentLineFirstNonWhitespaceChar != '}')
             {
                 indentation += "\t";
             }
             else if (currentLineFirstNonWhitespaceChar == '}')
             {
                 if (indentation.Length > 0)
                 {
                     indentation = indentation.Substring(0, indentation.Length - 1);
                 }
                 else
                 {
                     indentation = string.Empty;
                 }
             }
             /*if (lastLineTextTrimmed == "{" && currentLineTextTrimmed != "}")
             {
                 indentation += "\t";
             }
             else if (currentLineTextTrimmed == "}")
             {
                 if (indentation.Length > 0)
                 {
                     indentation = indentation.Substring(0, indentation.Length - 1);
                 }
                 else
                 {
                     indentation = string.Empty;
                 }
             }*/
         }
         indentationSegment = TextUtilities.GetWhitespaceAfter(document, line.Offset);
         document.Replace(indentationSegment, indentation);
     }
 }
开发者ID:not1ce111,项目名称:Spedit,代码行数:60,代码来源:EditorIndetation.cs

示例2: IndentLine

		/// <inheritdoc/>
		public virtual void IndentLine(TextDocument document, DocumentLine line)
		{
			if (document == null)
				throw new ArgumentNullException("document");
			if (line == null)
				throw new ArgumentNullException("line");
			DocumentLine previousLine = line.PreviousLine;
			if (previousLine != null) {
				ISegment indentationSegment = TextUtilities.GetWhitespaceAfter(document, previousLine.Offset);
				string indentation = document.GetText(indentationSegment);
				// copy indentation to line
				indentationSegment = TextUtilities.GetWhitespaceAfter(document, line.Offset);
				document.Replace(indentationSegment, indentation);
			}
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:16,代码来源:DefaultIndentationStrategy.cs

示例3: IndentLine

		/// <summary>
		/// Sets the indentation for the specified line.
		/// Usually this is constructed from the indentation of the previous line.
		/// </summary>
		/// <param name="document"></param>
		/// <param name="line"></param>
		public void IndentLine(TextDocument document, DocumentLine line)
		{
			var pLine = line.PreviousLine;
			if (pLine != null)
			{
				var segment = TextUtilities.GetWhitespaceAfter(document, pLine.Offset);
				var indentation = document.GetText(segment);

				var amount = HtmlParser.CountUnclosedTags(document.GetText(pLine));
				if (amount > 0)
					indentation += new string('\t', amount);

				document.Replace(TextUtilities.GetWhitespaceAfter(document, line.Offset), indentation);
			}
		}
开发者ID:andrebelanger,项目名称:HTMLEditor,代码行数:21,代码来源:HtmlIndentationStrategy.cs

示例4: BackwardChanges

		public void BackwardChanges()
		{
			TextDocument document = new TextDocument("initial text");
			ITextSource snapshot1 = document.CreateSnapshot();
			document.Replace(0, 7, "nw");
			document.Insert(1, "e");
			ITextSource snapshot2 = document.CreateSnapshot();
			Assert.AreEqual(1, snapshot2.Version.CompareAge(snapshot1.Version));
			TextChangeEventArgs[] arr = snapshot2.Version.GetChangesTo(snapshot1.Version).ToArray();
			Assert.AreEqual(2, arr.Length);
			Assert.AreEqual("", arr[0].InsertedText.Text);
			Assert.AreEqual("initial", arr[1].InsertedText.Text);
			
			Assert.AreEqual("initial text", snapshot1.Text);
			Assert.AreEqual("new text", snapshot2.Text);
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:16,代码来源:ChangeTrackingTest.cs

示例5: BackwardChanges

		public void BackwardChanges()
		{
			TextDocument document = new TextDocument("initial text");
			ChangeTrackingCheckpoint checkpoint1, checkpoint2;
			ITextSource snapshot1 = document.CreateSnapshot(out checkpoint1);
			document.Replace(0, 7, "nw");
			document.Insert(1, "e");
			ITextSource snapshot2 = document.CreateSnapshot(out checkpoint2);
			Assert.AreEqual(1, checkpoint2.CompareAge(checkpoint1));
			DocumentChangeEventArgs[] arr = checkpoint2.GetChangesTo(checkpoint1).ToArray();
			Assert.AreEqual(2, arr.Length);
			Assert.AreEqual("", arr[0].InsertedText);
			Assert.AreEqual("initial", arr[1].InsertedText);
			
			Assert.AreEqual("initial text", snapshot1.Text);
			Assert.AreEqual("new text", snapshot2.Text);
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:17,代码来源:ChangeTrackingTest.cs

示例6: IndentLine

        /// <inheritdoc/>
        public virtual void IndentLine(TextDocument document, DocumentLine line)
        {
            if (document == null)
                throw new ArgumentNullException(nameof(document));
            if (line == null)
                throw new ArgumentNullException(nameof(line));

            if (line.PreviousLine != null)
            {
                var indentationSegment = TextUtilities.GetWhitespaceAfter(document, line.PreviousLine.Offset);
                var indentation = document.GetText(indentationSegment);
                // copy indentation to line
                indentationSegment = TextUtilities.GetWhitespaceAfter(document, line.Offset);

                document.Replace(indentationSegment, indentation);
            }
        }
开发者ID:arkanoid1,项目名称:Yanitta,代码行数:18,代码来源:DefaultIndentationStrategy.cs

示例7: IndentLine

		/// <inheritdoc/>
		public virtual void IndentLine(TextDocument document, DocumentLine line)
		{
			if (document == null)
				throw new ArgumentNullException("document");
			if (line == null)
				throw new ArgumentNullException("line");
			DocumentLine previousLine = line.PreviousLine;
			if (previousLine != null) {
				ISegment indentationSegment = TextUtilities.GetWhitespaceAfter(document, previousLine.Offset);
				string indentation = document.GetText(indentationSegment);
				// copy indentation to line
				indentationSegment = TextUtilities.GetWhitespaceAfter(document, line.Offset);
				document.Replace(indentationSegment.Offset, indentationSegment.Length, indentation,
				                 OffsetChangeMappingType.RemoveAndInsert);
				// OffsetChangeMappingType.RemoveAndInsert guarantees the caret moves behind the new indentation.
			}
		}
开发者ID:bbqchickenrobot,项目名称:AvalonEdit,代码行数:18,代码来源:DefaultIndentationStrategy.cs

示例8: RenameReferencesInFile

		void RenameReferencesInFile(SymbolRenameArgs args, IList<IFindReferenceSearchScope> searchScopeList, FileName fileName, Action<PatchedFile> callback, Action<Error> errorCallback, bool isNameValid, CancellationToken cancellationToken)
		{
			ITextSource textSource = args.ParseableFileContentFinder.Create(fileName);
			if (textSource == null)
				return;
			if (searchScopeList != null) {
				if (!searchScopeList.DistinctBy(scope => scope.SearchTerm ?? String.Empty).Any(
					scope => (scope.SearchTerm == null) || (textSource.IndexOf(scope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) >= 0)))
					return;
			}
			
			var parseInfo = SD.ParserService.Parse(fileName, textSource) as CSharpFullParseInformation;
			if (parseInfo == null)
				return;
			ReadOnlyDocument document = null;
			IHighlighter highlighter = null;
			List<RenameResultMatch> results = new List<RenameResultMatch>();
			
			// Grab the unresolved file matching the compilation version
			// (this may differ from the version created by re-parsing the project)
			CSharpUnresolvedFile unresolvedFile = null;
			IProjectContent pc = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;
			if (pc != null) {
				unresolvedFile = pc.GetFile(fileName) as CSharpUnresolvedFile;
			}
			
			CSharpAstResolver resolver = new CSharpAstResolver(compilation, parseInfo.SyntaxTree, unresolvedFile);
			
			fr.RenameReferencesInFile(
				searchScopeList, args.NewName, resolver,
				delegate (RenameCallbackArguments callbackArgs) {
					var node = callbackArgs.NodeToReplace;
					string newCode = callbackArgs.NewNode.ToString();
					if (document == null) {
						document = new ReadOnlyDocument(textSource, fileName);
						
						if (args.ProvideHighlightedLine) {
							highlighter = SD.EditorControlService.CreateHighlighter(document);
							highlighter.BeginHighlighting();
						}
					}
					var startLocation = node.StartLocation;
					var endLocation = node.EndLocation;
					int offset = document.GetOffset(startLocation);
					int length = document.GetOffset(endLocation) - offset;
					if (args.ProvideHighlightedLine) {
						var builder = SearchResultsPad.CreateInlineBuilder(node.StartLocation, node.EndLocation, document, highlighter);
						var defaultTextColor = highlighter != null ? highlighter.DefaultTextColor : null;
						results.Add(new RenameResultMatch(fileName, startLocation, endLocation, offset, length, newCode, builder, defaultTextColor));
					} else {
						results.Add(new RenameResultMatch(fileName, startLocation, endLocation, offset, length, newCode));
					}
				},
				errorCallback, cancellationToken);
			if (highlighter != null) {
				highlighter.Dispose();
			}
			if (results.Count > 0) {
				if (!isNameValid) {
					errorCallback(new Error(ErrorType.Error, string.Format("The name '{0}' is not valid in the current context!", args.NewName),
					                        new DomRegion(fileName, results[0].StartLocation)));
					return;
				}
				IDocument changedDocument = new TextDocument(document);
				var oldVersion = changedDocument.Version;
				List<SearchResultMatch> fixedResults = new List<SearchResultMatch>();
				int lastStartOffset = changedDocument.TextLength + 1;
				foreach (var result in results.OrderByDescending(m => m.StartOffset)) {
					if (result.EndOffset <= lastStartOffset) {
						changedDocument.Replace(result.StartOffset, result.Length, result.NewCode);
						fixedResults.Add(result);
						lastStartOffset = result.StartOffset;
					}
				}
				callback(new PatchedFile(fileName, fixedResults, oldVersion, changedDocument.Version));
			}
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:77,代码来源:CSharpSymbolSearch.cs

示例9: ReloadDocument

		void ReloadDocument(TextDocument document, string newContent)
		{
			var diff = new MyersDiffAlgorithm(new StringSequence(document.Text), new StringSequence(newContent));
			document.Replace(0, document.TextLength, newContent, diff.GetEdits().ToOffsetChangeMap());
			document.UndoStack.ClearAll();
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:6,代码来源:CodeEditor.cs

示例10: ReloadDocument

		void ReloadDocument(TextDocument document, string newContent)
		{
			var diff = new MyersDiffAlgorithm(new StringSequence(document.Text), new StringSequence(newContent));
			document.Replace(0, document.TextLength, newContent, diff.GetEdits().ToOffsetChangeMap());
			
			if (this.ClearUndoStackOnSwitch || documentFirstLoad)
				document.UndoStack.ClearAll();
			
			if (documentFirstLoad)
				documentFirstLoad = false;
		}
开发者ID:ichengzi,项目名称:SharpDevelop,代码行数:11,代码来源:CodeEditor.cs

示例11: RenameReferencesInFile

		void RenameReferencesInFile(SymbolRenameArgs args, FileName fileName, Action<PatchedFile> callback, Action<Error> errorCallback, bool isNameValid, CancellationToken cancellationToken)
		{
			ITextSource textSource = args.ParseableFileContentFinder.Create(fileName);
			if (textSource == null)
				return;
			int offset = textSource.IndexOf(entity.Name, 0, textSource.TextLength, StringComparison.Ordinal);
			if (offset < 0)
				return;
			
			var parseInfo = SD.ParserService.Parse(fileName, textSource) as XamlFullParseInformation;
			if (parseInfo == null)
				return;
			ReadOnlyDocument document = null;
			IHighlighter highlighter = null;
			List<RenameResultMatch> results = new List<RenameResultMatch>();
			XamlAstResolver resolver = new XamlAstResolver(compilation, parseInfo);
			string newCode = args.NewName;
			do {
				if (document == null) {
					document = new ReadOnlyDocument(textSource, fileName);
					highlighter = SD.EditorControlService.CreateHighlighter(document);
					highlighter.BeginHighlighting();
				}
				var result = resolver.ResolveAtLocation(document.GetLocation(offset + entity.Name.Length / 2 + 1), cancellationToken);
				int length = entity.Name.Length;
				if ((result is TypeResolveResult && ((TypeResolveResult)result).Type.Equals(entity)) || (result is MemberResolveResult && ((MemberResolveResult)result).Member.Equals(entity))) {
					var region = new DomRegion(fileName, document.GetLocation(offset), document.GetLocation(offset + length));
					var builder = SearchResultsPad.CreateInlineBuilder(region.Begin, region.End, document, highlighter);
					results.Add(new RenameResultMatch(fileName, document.GetLocation(offset), document.GetLocation(offset + length), offset, length, newCode, builder, highlighter.DefaultTextColor));
				}
				offset = textSource.IndexOf(entity.Name, offset + length, textSource.TextLength - offset - length, StringComparison.OrdinalIgnoreCase);
			} while (offset > 0);
			if (highlighter != null) {
				highlighter.Dispose();
			}
			if (results.Count > 0) {
				if (!isNameValid) {
					errorCallback(new Error(ErrorType.Error, string.Format("The name '{0}' is not valid in the current context!", args.NewName),
					                        new DomRegion(fileName, results[0].StartLocation)));
					return;
				}
				IDocument changedDocument = new TextDocument(document);
				var oldVersion = changedDocument.Version;
				foreach (var result in results.OrderByDescending(m => m.StartOffset)) {
					changedDocument.Replace(result.StartOffset, result.Length, result.NewCode);
				}
				callback(new PatchedFile(fileName, results, oldVersion, changedDocument.Version));
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:49,代码来源:XamlSymbolSearch.cs

示例12: InsertBold

        public void InsertBold(int start, int length, TextDocument document)
        {
            var chs = document.GetCharAt(start);
            var che = document.GetCharAt(start + length - 1);

            document.Insert(start + length - 1, che.ToString());
            document.Replace(start + length, 1, "]");   //trick to keep anchors

            document.Insert(start + 1, chs.ToString());
            document.Replace(start, 1, "["); //trick to keep anchors

            Blocks.Add(new TextBlockBold()
            {
                OriginallyLength = length + 2,
                OriginallyOffset = start,
                MyAnchor = new AnchorSegment(document, start, length + 2)
            });
        }
开发者ID:yetanothervan,项目名称:conspector,代码行数:18,代码来源:TextModel.cs


注:本文中的ICSharpCode.AvalonEdit.Document.TextDocument.Replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。