Example #1
0
        /// <summary>
        /// targetにmergedの内容を追加してmergedを削除する.
        /// </summary>
        public void MergeLineSegments(LineSegment target, LineSegment merged)
        {
            Contract.Requires(target != null && merged != null);

            var mergedInlines = new List <Inline>();

            foreach (var inline in merged._Inlines)
            {
                if (!inline.IsLineEndCharacter)
                {
                    mergedInlines.Add(inline);
                }
            }

            mergedInlines.ForEach(
                inline => {
                merged.Remove(inline);
                target.InsertAfter(inline);
            }
                );

            var parent = merged.Parent as Block;

            if (parent != null)
            {
                parent.Remove(merged);
            }
        }
Example #2
0
        /// <summary>
        /// splittedには以前MergeLineSegments()に渡したmergedを渡す.
        /// undoでのmergeとの対称性のため.
        /// </summary>
        public LineSegment SplitLineSegment(LineSegment line, int inlineIndexInLine, LineSegment splitted)
        {
            Contract.Requires(line != null);

            var parent    = line.Parent as Block;
            var lineIndex = parent._Lines.IndexOf(line);

            var moveds = new List <Inline>();

            for (int i = inlineIndexInLine, len = line._Inlines.Count; i < len - 1; ++i)
            {
                /// 最後のline breakは移動しなくてよい
                moveds.Add(line._Inlines[i]);
            }

            moveds.ForEach(
                moved => {
                line.Remove(moved);
                splitted.InsertAfter(moved);
            }
                );

            parent.Insert(lineIndex + 1, splitted);

            return(splitted);
        }