Exemplo n.º 1
0
 public Change(string id, Location from, Location to, string text, string removed)
 {
     this.Id      = id;
     this.From    = from;
     this.To      = to;
     this.Text    = new DocumentLines(text);
     this.Removed = new DocumentLines(removed);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Apply a change to the document
        /// </summary>
        public void ApplyChange(Change change)
        {
            var from = Lines.ClampLocation(change.From);
            var to   = Lines.ClampLocation(change.To);

            Lines = Lines.RemoveText(from, to);
            Lines = Lines.InsertText(from, new DocumentLines(change.Text));

            history.Add(change);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Insert text into a location and return the modified document
        /// </summary>
        /// <param name="at">Location of insertion</param>
        /// <param name="text">Text to be inserted</param>
        public DocumentLines InsertText(Location at, DocumentLines text)
        {
            List <string> lines = ToList();

            string lineStart = lines[at.line].Substring(0, at.ch);
            string lineEnd   = lines[at.line].Substring(at.ch);

            lines[at.line] = lineStart + text[0];

            lines.InsertRange(at.line + 1, text.Skip(1));
            lines[at.line + text.LineCount - 1] += lineEnd;

            return(new DocumentLines(lines));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates new document with the given content
 /// </summary>
 public Document(string content = null)
 {
     Lines = new DocumentLines(content);
 }