Beispiel #1
0
        private static IResolved <T> ResolveConflict <T>(Insert <T> a, IChange <T> b)
        {
            switch (b)
            {
            case Delete <T> delete:
                if (delete.OldRange.Contains(a.OldRange, includeStart: false))
                {
                    return(Resolved.AsConflict(delete, a, "[B] is deleting text that [A] is inserting into."));
                }
                else
                {
                    return(Resolved.AsNoMerge(delete, a));
                }

            case Insert <T> insert:
                if (a.NewRange.Start == insert.NewRange.Start)
                {
                    if (a.Value.Equals(insert.Value))
                    {
                        return(Resolved.AsMerge(a, insert, a));
                    }
                    else
                    {
                        return(Resolved.AsConflict(a, insert, "[A] && [B] are inserting text at the same location."));
                    }
                }
                else
                {
                    return(Resolved.AsNoMerge(a, insert));
                }

            default:
                throw new ArgumentException($"Unknown change type: {b.GetType().Name}.");
            }
        }
Beispiel #2
0
        private static IResolved <T> ResolveConflict <T>(Delete <T> a, IChange <T> b)
        {
            switch (b)
            {
            case Delete <T> delete:
                if (a.OldRange.OverlapsWith(delete.OldRange))
                {
                    var value = a.Value;
                    var range = Range.Join(a.OldRange, delete.OldRange);

                    var newDelete = new Delete <T>
                                    (
                        value: a.Value,
                        deletedRange: Range.Join(a.OldRange, delete.OldRange),
                        newPosition: a.NewRange.Start
                                    );

                    return(Resolved.AsMerge(a, delete, newDelete));
                }
                else
                {
                    return(Resolved.AsNoMerge(a, delete));
                }

            case Insert <T> insert:
                if (a.OldRange.Contains(insert.OldRange, includeStart: false))
                {
                    return(Resolved.AsConflict(a, insert, "[A] is deleting text that [B] is inserting into."));
                }
                else
                {
                    return(Resolved.AsNoMerge(a, insert));
                }

            default:
                throw new ArgumentException($"Unknown change type: {b.GetType().Name}.");
            }
        }