Modify

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#12925 closed defect (fixed)

linkresolvers should be sorted by name

Reported by: Jun Omae Owned by: Peter Suter
Priority: normal Component: WikiAutoCompletePlugin
Severity: normal Keywords:
Cc: Trac Release: 1.0

Description (last modified by Jun Omae)

Currently, linkresolvers suggests unsorted link names. I think the suggestion should be sorted by name.

The 20 link resolvers are defined by Trac core.

>>> from trac.test import EnvironmentStub
>>> from trac.loader import load_components
>>> from trac.wiki.api import WikiSystem
>>> env = EnvironmentStub()
>>> load_components(env)
>>> wikisys = WikiSystem(env)
>>> names = set()
>>> for provider in wikisys.syntax_providers:
...   for name, resolver in provider.get_link_resolvers():
...     names.add(name)
...
>>> names = sorted(names)
>>> len(names)
20
>>> names
['attachment', 'browser', 'bug', 'changeset', 'comment', 'diff', 'export', 'htdocs', 'log', 'milestone', 'query', 'raw-attachment', 'report', 'repos', 'search', 'sha', 'source', 'ticket', 'timeline', 'wiki']
  • wikiautocomplete/htdocs/js/wikiautocomplete.js

    diff --git a/wikiautocomplete/htdocs/js/wikiautocomplete.js b/wikiautocomplete/htdocs/js/wikiautocomplete.js
    index 22e1899..34da355 100644
    a b jQuery(document).ready(function($) { 
    7878
    7979    ], {
    8080        appendTo: $('body'),
     81        maxCount: 20
    8182    });
    8283});
  • wikiautocomplete/web_ui.py

    diff --git a/wikiautocomplete/web_ui.py b/wikiautocomplete/web_ui.py
    index 4afa1f4..ea81c25 100644
    a b class WikiAutoCompleteModule(Component): 
    7474
    7575        if strategy == 'linkresolvers':
    7676            wiki = WikiSystem(self.env)
    77             completions = []
    78             for provider in wiki.syntax_providers:
    79                 for name, resolver in provider.get_link_resolvers():
    80                     if name.startswith(term):
    81                         completions.append(name)
    82             self._send_json(req, completions)
     77            completions = set(name for provider in wiki.syntax_providers
     78                                   for name, resolver
     79                                        in provider.get_link_resolvers()
     80                                   if name.startswith(term))
     81            self._send_json(req, sorted(completions))
    8382
    8483        elif strategy == 'ticket':
    8584            try:

Attachments (0)

Change History (5)

comment:1 Changed 8 years ago by Jun Omae

Description: modified (diff)

comment:2 Changed 8 years ago by Peter Suter

maxCount: 20

I agree it is unfortunate that not all available resolvers are shown. I also agree that 10 (the default) is maybe often too small. But increasing maxCount is not a perfect solution. It will still be too small when plugins add more resolvers. 20 seems maybe a bit too large to me on smaller screens, but maybe acceptable.

I filed an issue upstream about scrolling through longer lists.

I think the suggestion should be sorted by name.

Sounds good. Please commit, thanks.

comment:3 Changed 8 years ago by Jun Omae

The owner of jquery-textcomplete suggests to use max-height with large maxCount in the issue comment.

What about modifying like this?

  • wikiautocomplete/htdocs/css/jquery.textcomplete.css

    diff --git a/wikiautocomplete/htdocs/css/jquery.textcomplete.css b/wikiautocomplete/htdocs/css/jquery.textcomplete.css
    index 37a761b..ea83431 100644
    a b  
    33.dropdown-menu {
    44    border: 1px solid #ddd;
    55    background-color: white;
     6    max-height: 20em;
     7    overflow-x: hidden;
     8    overflow-y: auto;
    69}
    710
    811.dropdown-menu li {
  • wikiautocomplete/htdocs/js/wikiautocomplete.js

    diff --git a/wikiautocomplete/htdocs/js/wikiautocomplete.js b/wikiautocomplete/htdocs/js/wikiautocomplete.js
    index 2b14015..47579a1 100644
    a b jQuery(document).ready(function($) { 
    7878
    7979    ], {
    8080        appendTo: $('body'),
     81        maxCount: 10000
    8182    });
    8283});

comment:4 Changed 8 years ago by Peter Suter

Looks great, thanks!

comment:5 Changed 8 years ago by Jun Omae

Resolution: fixed
Status: newclosed

In 15946:

WikiAutoCompletePlugin: sort suggestion from linkresolvers and make the suggestion scrollable (closes #12925)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Peter Suter.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.