source: tagsplugin/tags/0.11/tractags/wikiautocomplete.py

Last change on this file was 17068, checked in by Ryan J Ollos, 6 years ago

TracTags 0.10dev: Suggest completions on OR queries

Patch by Pete Suter.

Refs #13072.

File size: 1.2 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2018 Ryan J Ollos <ryan.j.ollos@gmail.com>
4#
5# This software is licensed as described in the file COPYING, which
6# you should have received as part of this distribution.
7#
8
9from __future__ import absolute_import
10
11from trac.core import Component, implements
12from wikiautocomplete.api import IWikiAutoCompleteStrategyProvider
13
14from tractags.api import TagSystem
15
16
17class TagsWikiAutoComplete(Component):
18
19    implements(IWikiAutoCompleteStrategyProvider)
20
21    # IWikiAutoCompleteStrategyProvider
22
23    def get_wiki_auto_complete_strategies(self):
24        return [(
25            {
26                'name': 'tag',
27                'match': (
28                    r'\b(tag:|tagged:)'  # tag: or tagged: query
29                    r'("(?:\S+ )*)?'  # Optional: Quotes allow multiple OR-tags
30                    r'(\S*)$'  # tag-prefix to complete
31                ),
32                'index': 3,
33                'replace_prefix': '$1$2',
34                'cache': True,
35            },
36            self._suggest_tags,
37        )]
38
39    def _suggest_tags(self, req):
40        all_tags = TagSystem(self.env).get_all_tags(req)
41        return [{'value': tag} for tag in sorted(all_tags)]
Note: See TracBrowser for help on using the repository browser.