diff --git a/meld/filediff.py b/meld/filediff.py
index 430b621..9868382 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -56,14 +56,42 @@ class CachedSequenceMatcher(object):
         self.cache = {}
 
     def __call__(self, text1, textn):
+        self._populate_cache(text1, textn)
+        return self.cache[(text1, textn)][0]
+
+    def _populate_cache(self, text1, textn):
         try:
             self.cache[(text1, textn)][1] = time.time()
-            return self.cache[(text1, textn)][0]
         except KeyError:
             matcher = matchers.MyersSequenceMatcher(None, text1, textn)
             opcodes = matcher.get_opcodes()
-            self.cache[(text1, textn)] = [opcodes, time.time()]
-            return opcodes
+            blocks = matcher.get_matching_blocks()
+            self.cache[(text1, textn)] = [opcodes, time.time(), blocks]
+
+    def _get_blocks(self, text1, textn):
+        self._populate_cache(text1, textn)
+        return self.cache[(text1, textn)][2]
+
+    def remap(self, indexes, text_filtered, text_unfiltered):
+        """Remap the indexes from text_filtered to text_unfiltered
+        """ 
+        blocks = self._get_blocks(text_filtered, text_unfiltered)
+        remapped_indexes = []
+        for index in indexes:
+            for block in reversed(blocks):
+                #print block, index
+                if block[0]>index-1:
+                    continue
+                if block[2] == 0: # this is the dummy triple, see http://docs.python.org/library/difflib.html#difflib.SequenceMatcher.get_matching_blocks
+                    remapped_indexes.append(block[1]-1)
+                elif block[0] + block[2] < index:
+                    print "this should not happen: ", block, index
+                    remapped_indexes.append(-1)
+                else:
+                    remapped_indexes.append(block[1] + index - block[0])
+                break
+        return remapped_indexes 
+
 
     def clean(self, size_hint):
         """Clean the cache if necessary
@@ -1074,11 +1107,15 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
 
                     # We don't use self.buffer_texts here, as removing line
                     # breaks messes with inline highlighting in CRLF cases
-                    text1 = bufs[0].get_text(starts[0], ends[0], False)
-                    text1 = unicode(text1, 'utf8')
-                    textn = bufs[1].get_text(starts[1], ends[1], False)
-                    textn = unicode(textn, 'utf8')
-
+                    text1_unfiltered = bufs[0].get_text(starts[0], ends[0], False)
+                    text1_unfiltered = unicode(text1_unfiltered, 'utf8')
+                    textn_unfiltered = bufs[1].get_text(starts[1], ends[1], False)
+                    textn_unfiltered = unicode(textn_unfiltered, 'utf8')
+
+                    # davide: not clear to me why they are in this "reverse" order
+                    textn = "\n".join(self.buffer_filtered[0][c[1]:c[2]])
+                    text1 = "\n".join(self.buffer_filtered[self.num_panes-1][c[3]:c[4]])
+ 
                     # For very long sequences, bail rather than trying a very slow comparison
                     inline_limit = 8000 # arbitrary constant
                     if len(text1) + len(textn) > inline_limit:
@@ -1086,7 +1123,8 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                             bufs[i].apply_tag(tags[i], starts[i], ends[i])
                         continue
 
-                    #print "<<<\n%s\n---\n%s\n>>>" % (text1, textn)
+                    #print "<<<original \n%s\n---\n%s\n>>>" % (text1_unfiltered, textn_unfiltered)
+                    #print "<<<filtered \n%s\n---\n%s\n>>>" % (text1, textn)
                     back = (0,0)
                     for o in self._cached_match(text1, textn):
                         if o[0] == "equal":
@@ -1094,9 +1132,14 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                                 back = o[4]-o[3], o[2]-o[1]
                             continue
                         for i in range(2):
+                            indexes=(o[1+2*i] - back[i], o[2+2*i])
                             s,e = starts[i].copy(), starts[i].copy()
-                            s.forward_chars( o[1+2*i] - back[i] )
-                            e.forward_chars( o[2+2*i] )
+                            if i == 0:
+                                indexes = self._cached_match.remap(indexes,text1, text1_unfiltered)
+                            else:
+                                indexes = self._cached_match.remap(indexes,textn, textn_unfiltered)
+                            s.forward_chars( indexes[0] )
+                            e.forward_chars( indexes[1] )
                             bufs[i].apply_tag(tags[i], s, e)
                         back = (0,0)
                     yield 1
