Exemplo n.º 1
0
 /// <summary>
 /// Updates the selection when the document changes.
 /// </summary>
 public abstract Selection UpdateOnDocumentChange(DocumentChangeEventArgs e);
 internal ChangeTrackingCheckpoint(object documentIdentifier, DocumentChangeEventArgs value, int id)
 {
     this.documentIdentifier = documentIdentifier;
     this.value = value;
     this.id = id;
 }
Exemplo n.º 3
0
 internal void OnDocumentChanged(DocumentChangeEventArgs e)
 {
     InvalidateVisualColumn();
     if (storedCaretOffset >= 0) {
         int newCaretOffset = e.GetNewOffset(storedCaretOffset, AnchorMovementType.Default);
         TextDocument document = textArea.Document;
         if (document != null) {
             // keep visual column
             this.Position = new TextViewPosition(document.GetLocation(newCaretOffset), position.VisualColumn);
         }
     }
     storedCaretOffset = -1;
 }
 public DocumentChangeOperation(TextDocument document, DocumentChangeEventArgs change)
 {
     this.document = document;
     this.change = change;
 }
 internal ChangeTrackingCheckpoint Append(DocumentChangeEventArgs change)
 {
     Debug.Assert(this.next == null);
     this.next = new ChangeTrackingCheckpoint(this.documentIdentifier, change, unchecked( this.id + 1 ));
     return this.next;
 }
Exemplo n.º 6
0
 void OnDocumentChanged(DocumentChangeEventArgs e)
 {
     caret.OnDocumentChanged(e);
     this.Selection = selection.UpdateOnDocumentChange(e);
 }
Exemplo n.º 7
0
 void OnDocumentChanged(DocumentChangeEventArgs e)
 {
     foldings.UpdateOffsets(e);
     int newEndOffset = e.Offset + e.InsertionLength;
     // extend end offset to the end of the line (including delimiter)
     var endLine = document.GetLineByOffset(newEndOffset);
     newEndOffset = endLine.Offset + endLine.TotalLength;
     foreach (var affectedFolding in foldings.FindOverlappingSegments(e.Offset, newEndOffset - e.Offset)) {
         if (affectedFolding.Length == 0) {
             RemoveFolding(affectedFolding);
         } else {
             affectedFolding.ValidateCollapsedLineSections();
         }
     }
 }
Exemplo n.º 8
0
 /// <inheritdoc/>
 public override Selection UpdateOnDocumentChange(DocumentChangeEventArgs e)
 {
     if (e == null)
         throw new ArgumentNullException("e");
     return Selection.Create(
         textArea,
         new TextViewPosition(textArea.Document.GetLocation(e.GetNewOffset(startOffset, AnchorMovementType.Default)), start.VisualColumn),
         new TextViewPosition(textArea.Document.GetLocation(e.GetNewOffset(endOffset, AnchorMovementType.Default)), end.VisualColumn)
     );
 }
Exemplo n.º 9
0
        /// <inheritdoc/>
        public override Selection UpdateOnDocumentChange(DocumentChangeEventArgs e)
        {
            TextLocation newStartLocation = textArea.Document.GetLocation(e.GetNewOffset(topLeftOffset, AnchorMovementType.AfterInsertion));
            TextLocation newEndLocation = textArea.Document.GetLocation(e.GetNewOffset(bottomRightOffset, AnchorMovementType.BeforeInsertion));

            return new RectangleSelection(textArea,
                                          new TextViewPosition(newStartLocation, GetVisualColumnFromXPos(newStartLocation.Line, startXPos)),
                                          new TextViewPosition(newEndLocation, GetVisualColumnFromXPos(newEndLocation.Line, endXPos)));
        }
Exemplo n.º 10
0
        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);

            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, 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);
        }