Commits

Georg Brandl committed ae6437e

Fix #727: Fix the links to search results with custom object types.

Comments (0)

Files changed (3)

 Release 1.0.8 (Sep 23, 2011)
 ============================
 
+* #727: Fix the links to search results with custom object types.
+
 * #648: Fix line numbers reported in warnings about undefined
   references.
 
         self._mapping = {}
         # objtype -> index
         self._objtypes = {}
-        # objtype index -> objname (localized)
+        # objtype index -> (domain, type, objname (localized))
         self._objnames = {}
 
     def load(self, stream, format):
                     continue
                 if prio < 0:
                     continue
-                # XXX splitting at dot is kind of Python specific
                 prefix, name = rpartition(fullname, '.')
                 pdict = rv.setdefault(prefix, {})
                 try:
-                    i = otypes[domainname, type]
+                    typeindex = otypes[domainname, type]
                 except KeyError:
-                    i = len(otypes)
-                    otypes[domainname, type] = i
+                    typeindex = len(otypes)
+                    otypes[domainname, type] = typeindex
                     otype = domain.object_types.get(type)
                     if otype:
                         # use unicode() to fire translation proxies
-                        onames[i] = unicode(domain.get_type_name(otype))
+                        onames[typeindex] = (domainname, type,
+                            unicode(domain.get_type_name(otype)))
                     else:
-                        onames[i] = type
-                pdict[name] = (fn2index[docname], i, prio)
+                        onames[typeindex] = (domainname, type, type)
+                if anchor == fullname:
+                    shortanchor = ''
+                elif anchor == type + '-' + fullname:
+                    shortanchor = '-'
+                else:
+                    shortanchor = anchor
+                pdict[name] = (fn2index[docname], typeindex, prio, shortanchor)
         return rv
 
     def get_terms(self, fn2index):

sphinx/themes/basic/static/searchtools.js

           var fullname = (prefix ? prefix + '.' : '') + name;
           if (fullname.toLowerCase().indexOf(object) > -1) {
             match = objects[prefix][name];
-            descr = objnames[match[1]] + _(', in ') + titles[match[0]];
-            // XXX the generated anchors are not generally correct
-            // XXX there may be custom prefixes
-            result = [filenames[match[0]], fullname, '#'+fullname, descr];
+            descr = objnames[match[1]][0] + _(', in ') + titles[match[0]];
+            anchor = match[3];
+            if (anchor == '')
+              anchor = fullname;
+            else if (anchor == '-')
+              anchor = objnames[match[1]][1] + '-' + fullname;
+            result = [filenames[match[0]], fullname, '#'+anchor, descr];
             switch (match[2]) {
             case 1: objectResults.push(result); break;
             case 0: importantResults.push(result); break;