예제 #1
0
        Tuple <List <Cairo.Rectangle>, List <Cairo.Rectangle> > GetDiffPaths(List <Mono.TextEditor.Utils.Hunk> diff, TextEditor editor, Hunk hunk)
        {
            if (!diffCache.ContainsKey(diff))
            {
                diffCache[diff] = new Dictionary <Hunk, Tuple <List <Cairo.Rectangle>, List <Cairo.Rectangle> > > ();
            }
            var pathCache = diffCache[diff];

            Tuple <List <Cairo.Rectangle>, List <Cairo.Rectangle> > result;

            if (pathCache.TryGetValue(hunk, out result))
            {
                return(result);
            }

            var words    = BreakTextInWords(editor, hunk.RemoveStart, hunk.Removed);
            var cmpWords = BreakTextInWords(MainEditor, hunk.InsertStart, hunk.Inserted);

            var wordDiff = new List <Hunk> (Diff.GetDiff(words.Select(w => editor.GetTextAt(w)).ToArray(),
                                                         cmpWords.Select(w => MainEditor.GetTextAt(w)).ToArray()));

            result = Tuple.Create(CalculateChunkPath(editor, wordDiff, words, true),
                                  CalculateChunkPath(MainEditor, wordDiff, cmpWords, false));

            pathCache[hunk] = result;
            return(result);
        }