Example #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);
                    }
                }
            }
        }
Example #2
0
 /// <summary>
 /// Undoes an insert operation.
 /// </summary>
 /// <param name="model">The model.</param>
 private void UndoInsert(DocumentModel doc, OpInsertMessage model, ITextEdit edit)
 {
     //doc.BlockEvent = true;
     var span = new Span(model.Index, model.Content.Length);
     edit.Delete(span);
 }
Example #3
0
 /// <summary>
 /// Performs an insert in a document.
 /// </summary>
 /// <param name="model">The model.</param>
 private void Insert(DocumentModel doc, OpInsertMessage model, ITextEdit edit)
 {
     //doc.BlockEvent = true;
     var start = model.Index > edit.Snapshot.Length ? edit.Snapshot.Length : model.Index;
     edit.Insert(start, model.Content);
 }