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


C# DocumentChangeEventArgs.CreateSingleChangeMapEntry方法代码示例

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


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

示例1: DoReplace

		void DoReplace(int offset, int length, string newText, OffsetChangeMap offsetChangeMap)
		{
			if (length == 0 && newText.Length == 0)
				return;
			
			// trying to replace a single character in 'Normal' mode?
			// for single characters, 'CharacterReplace' mode is equivalent, but more performant
			// (we don't have to touch the anchorTree at all in 'CharacterReplace' mode)
			if (length == 1 && newText.Length == 1 && offsetChangeMap == null)
				offsetChangeMap = OffsetChangeMap.Empty;
			
			string removedText = rope.ToString(offset, length);
			DocumentChangeEventArgs args = new DocumentChangeEventArgs(offset, removedText, newText, offsetChangeMap);
			
			// fire DocumentChanging event
			if (Changing != null)
				Changing(this, args);
			
			cachedText = null; // reset cache of complete document text
			fireTextChanged = true;
			DelayedEvents delayedEvents = new DelayedEvents();
			
			lock (lockObject) {
				// create linked list of checkpoints, if required
				if (currentCheckpoint != null) {
					currentCheckpoint = currentCheckpoint.Append(args);
				}
				
				// now update the textBuffer and lineTree
				if (offset == 0 && length == rope.Length) {
					// optimize replacing the whole document
					rope.Clear();
					rope.InsertText(0, newText);
					lineManager.Rebuild();
				} else {
					rope.RemoveRange(offset, length);
					lineManager.Remove(offset, length);
					#if DEBUG
					lineTree.CheckProperties();
					#endif
					rope.InsertText(offset, newText);
					lineManager.Insert(offset, newText);
					#if DEBUG
					lineTree.CheckProperties();
					#endif
				}
			}
			
			// update text anchors
			if (offsetChangeMap == null) {
				anchorTree.HandleTextChange(args.CreateSingleChangeMapEntry(), delayedEvents);
			} else {
				foreach (OffsetChangeMapEntry entry in offsetChangeMap) {
					anchorTree.HandleTextChange(entry, delayedEvents);
				}
			}
			
			// raise delayed events after our data structures are consistent again
			delayedEvents.RaiseEvents();
			
			// fire DocumentChanged event
			if (Changed != null)
				Changed(this, args);
		}
开发者ID:ootsby,项目名称:SharpDevelop,代码行数:64,代码来源:TextDocument.cs

示例2: DoReplace

        void DoReplace(int offset, int length, ITextSource newText, OffsetChangeMap offsetChangeMap)
        {
            if (length == 0 && newText.TextLength == 0)
                return;

            // trying to replace a single character in 'Normal' mode?
            // for single characters, 'CharacterReplace' mode is equivalent, but more performant
            // (we don't have to touch the anchorTree at all in 'CharacterReplace' mode)
            if (length == 1 && newText.TextLength == 1 && offsetChangeMap == null)
                offsetChangeMap = OffsetChangeMap.Empty;

            ITextSource removedText;
            if (length == 0) {
                removedText = StringTextSource.Empty;
            } else if (length < 100) {
                removedText = new StringTextSource(rope.ToString(offset, length));
            } else {
                // use a rope if the removed string is long
                removedText = new RopeTextSource(rope.GetRange(offset, length));
            }
            DocumentChangeEventArgs args = new DocumentChangeEventArgs(offset, removedText, newText, offsetChangeMap);

            // fire DocumentChanging event
            if (Changing != null)
                Changing(this, args);
            if (textChanging != null)
                textChanging(this, args);

            undoStack.Push(this, args);

            cachedText = null; // reset cache of complete document text
            fireTextChanged = true;
            DelayedEvents delayedEvents = new DelayedEvents();

            lock (lockObject) {
                // create linked list of checkpoints
                versionProvider.AppendChange(args);

                // now update the textBuffer and lineTree
                if (offset == 0 && length == rope.Length) {
                    // optimize replacing the whole document
                    rope.Clear();
                    var newRopeTextSource = newText as RopeTextSource;
                    if (newRopeTextSource != null)
                        rope.InsertRange(0, newRopeTextSource.GetRope());
                    else
                        rope.InsertText(0, newText.Text);
                    lineManager.Rebuild();
                } else {
                    rope.RemoveRange(offset, length);
                    lineManager.Remove(offset, length);
                    #if DEBUG
                    lineTree.CheckProperties();
                    #endif
                    var newRopeTextSource = newText as RopeTextSource;
                    if (newRopeTextSource != null)
                        rope.InsertRange(offset, newRopeTextSource.GetRope());
                    else
                        rope.InsertText(offset, newText.Text);
                    lineManager.Insert(offset, newText);
                    #if DEBUG
                    lineTree.CheckProperties();
                    #endif
                }
            }

            // update text anchors
            if (offsetChangeMap == null) {
                anchorTree.HandleTextChange(args.CreateSingleChangeMapEntry(), delayedEvents);
            } else {
                foreach (OffsetChangeMapEntry entry in offsetChangeMap) {
                    anchorTree.HandleTextChange(entry, delayedEvents);
                }
            }

            lineManager.ChangeComplete(args);

            // raise delayed events after our data structures are consistent again
            delayedEvents.RaiseEvents();

            // fire DocumentChanged event
            OnChanged(args);                                                  // [DIGITALRUNE] Use protected virtual method to raise Changed event.
            if (textChanged != null)
                textChanged(this, args);
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:85,代码来源:TextDocument.cs


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