Exemple #1
0
        /// <summary>
        /// Handles the Changed event of the TextBuffer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">
        ///   The <see cref="TextContentChangedEventArgs" />
        ///   instance containing the event data.
        /// </param>
        /// <param name="docId">The document id.</param>
        private void TextChanged(object sender, TextContentChangedEventArgs e, string docId)
        {
            var doc = this.Documents[docId];

            if (doc.BlockEvent)
            {
                return;
            }

            foreach (var change in e.Changes)
            {
                var tick = (long)doc.TickStamp;

                lock (doc.OpLocker)
                {
                    if (!change.OldText.IsNullOrEmpty())
                    {
                        var model = new OpDeleteMessage()
                        {
                            Service = "op",
                            MessageType = "delete",
                            User = this.UserName,
                            Index = change.OldPosition,
                            ReplacementLength = change.OldLength,
                            OldContent = change.OldText,
                            DocumentId = docId,
                            OpId = doc.OpId,
                            TickStamp = tick,
                            IsApplied = true,
                            LocalCount = doc.LocalCount,
                            RemoteCount = doc.RemoteCount
                        };

                        doc.LocalCount++;
                        doc.Changes.Add(model);
                        this.SendMessage(model);
                    }

                    if (!change.NewText.IsNullOrEmpty())
                    {
                        var model = new OpInsertMessage()
                        {
                            Service = "op",
                            MessageType = "insert",
                            User = this.UserName,
                            Index = change.NewPosition,
                            Content = change.NewText,
                            DocumentId = docId,
                            OpId = doc.OpId,
                            TickStamp = tick,
                            IsApplied = true,
                            LocalCount = doc.LocalCount,
                            RemoteCount = doc.RemoteCount
                        };

                        doc.LocalCount++;
                        doc.Changes.Add(model);
                        this.SendMessage(model);
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Undoes a delete operation.
 /// </summary>
 /// <param name="model">The model.</param>
 private void UndoDelete(DocumentModel doc, OpDeleteMessage model, ITextEdit edit)
 {
     //doc.BlockEvent = true;
     edit.Insert(model.Index, model.OldContent);
 }
Exemple #3
0
        /// <summary>
        /// Performs a delete in a document.
        /// </summary>
        /// <param name="model">The model.</param>
        private void Delete(DocumentModel doc, OpDeleteMessage model, ITextEdit edit)
        {
            //doc.BlockEvent = true;
            var len = model.End - model.Index;

            if (len > doc.View.TextBuffer.CurrentSnapshot.Length)
            {
                len = edit.Snapshot.Length;
            }

            var span = new Span(model.Index, len);
            edit.Delete(span);
        }