示例#1
0
        private int SearchPosition(CharId newCharId, CharId previousId, CharId nextId)
        {
            int nextIndex, previousIndex;

            if (!(chars.TryGetPositionById(previousId, out previousIndex) &&
                  chars.TryGetPositionById(nextId, out nextIndex) &&
                  nextIndex >= previousIndex))
            {
                throw new ArgumentException("Wrong next or previous");
            }

            if (nextIndex == previousIndex + 1)
            {
                return(nextIndex);
            }

            var skipped = chars
                          .GetChars()
                          .Skip(previousIndex)
                          .Take(nextIndex - previousIndex)
                          .SkipWhile(l => CharId.Compare(newCharId, l.Id) < 0)
                          .Take(2)
                          .ToList();

            if (skipped.Count < 2)
            {
                skipped = chars.GetChars().Skip(previousIndex).Take(2).ToList();
            }
            return(SearchPosition(newCharId, skipped[0].Id, skipped[1].Id));
        }
示例#2
0
 public Char(CharId id, string character, CharId previous, CharId next)
 {
     Id        = id;
     Character = character;
     Previous  = previous;
     Next      = next;
 }
示例#3
0
        public bool TryGetPositionById(CharId id, out int position)
        {
            CharElement ci;

            if (idToChar.TryGetValue(id, out ci))
            {
                position = ci.Position + ci.Block.BlockPosition;
                return(true);
            }
            position = -1;
            return(false);
        }
示例#4
0
        private Char[] GenerateInsertOperation(string s, int position)
        {
            var previousId = chars.GetByVisiblePosition(position).Id;
            var nextId     = chars.GetByVisiblePosition(position + 1).Id;

            var result = new Char[s.Length];

            for (var i = 0; i < s.Length; i++)
            {
                var currentId = new CharId(operationId++);
                result[i]  = new Char(currentId, s[i].ToString(), previousId, nextId);
                previousId = currentId;
            }
            return(result);
        }
示例#5
0
 public static int Compare(CharId newCharId, CharId l)
 {
     return(l.Value.CompareTo(newCharId.Value));
 }