Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gornostal committed Sep 2, 2017
1 parent ba350a1 commit f1d2f98
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions data/preferences/src/api/fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ function generateExtensionRecord (extId, name, numOfPrefs = 3, url = 'https://gi
type: 'input',
name: 'Max Number of Posts',
default_value: '5',
description: 'This is description',
user_value: null,
value: '5'
},
Expand All @@ -139,6 +140,7 @@ function generateExtensionRecord (extId, name, numOfPrefs = 3, url = 'https://gi
type: 'text',
name: 'Default Message',
default_value: '',
description: 'This is description',
user_value: 'Hello Steve!',
value: 'Hello Steve!'
}
Expand Down
3 changes: 3 additions & 0 deletions data/preferences/src/components/pages/ExtensionConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@
v-if="pref.type == 'keyword'"
:label="`${pref.name} Keyword`"
class="keyword-input"
:description="pref.description"
>
<b-form-input :ref="pref.id" :value="pref.value"></b-form-input>
</b-form-fieldset>

<b-form-fieldset
v-if="pref.type == 'input'"
:label="pref.name"
:description="pref.description"
>
<b-form-input :ref="pref.id" :value="pref.value"></b-form-input>
</b-form-fieldset>

<b-form-fieldset
v-if="pref.type == 'text'"
:label="pref.name"
:description="pref.description"
>
<b-form-input textarea :ref="pref.id" :value="pref.value" :rows="3"></b-form-input>
</b-form-fieldset>
Expand Down
4 changes: 3 additions & 1 deletion tests/util/test_text_highlighter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# encoding: utf8
from functools import partial

from ulauncher.util.text_highlighter import highlight_text


def test_highlight_text():
hl = partial(highlight_text, open_tag='<i>', close_tag='</i>')
assert hl('fifox', 'Firefox') == '<i>Fi</i>re<i>fox</i>'
assert hl(u'fifox', u'Firefox') == '<i>Fi</i>re<i>fox</i>'
assert hl('fifox', 'Firefox') == '<i>Fi</i>re<i>fox</i>'
assert hl('hell wo', 'hello world') == '<i>hell</i>o<i> wo</i>rld'
assert hl('ttesti', 'testik_ls-ttestk') == '<i>testi</i>k_ls-ttestk'
assert hl('dome', 'Documents') == '<i>Do</i>cu<i>me</i>nts'
assert hl('dome', 'Docu & Ments') == '<i>Do</i>cu &amp; <i>Me</i>nts'
assert hl('e tom', u'São tomé & príncipe') == u'São<i> tom</i>é &amp; príncip<i>e</i>'
3 changes: 1 addition & 2 deletions ulauncher/api/shared/item/ExtensionResultItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ class ExtensionResultItem(ResultItem):

def __init__(self, *args, **kw):
super(ExtensionResultItem, self).__init__(*args, **kw)
self._highlightable = False
self.extension_path = os.path.dirname(sys.argv[0])
if self._on_enter and not isinstance(self._on_enter, BaseAction):
raise Exception("Incorrect type of on_enter argument")

def get_icon(self):
if isinstance(self._icon, str):
if isinstance(self._icon, basestring):
icon_path = self._icon

if not icon_path.startswith('/'):
Expand Down
7 changes: 5 additions & 2 deletions ulauncher/util/text_highlighter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ulauncher.util.fuzzy_search import get_matching_indexes
from ulauncher.util.string import force_unicode


def highlight_text(query, text, open_tag='<span foreground="white">', close_tag='</span>'):
Expand All @@ -7,19 +8,21 @@ def highlight_text(query, text, open_tag='<span foreground="white">', close_tag=
:returns: string with Pango markup
"""
positions = get_matching_indexes(query, text)
query = force_unicode(query)
text = force_unicode(text)

# use positions to highlight text with tags
hl_started = False
hlted = []
for i in range(len(text)):
for i, char in enumerate(text):
if i in positions and not hl_started:
hl_started = True
hlted.append(open_tag)
elif i not in positions and hl_started:
hl_started = False
hlted.append(close_tag)

hlted.append(text[i])
hlted.append(char)

if hl_started:
# don't forget to close tag if it is opened
Expand Down

0 comments on commit f1d2f98

Please sign in to comment.