Skip to content
This repository has been archived by the owner on Jul 27, 2018. It is now read-only.

Commit

Permalink
refine matching for chinese characters. this has not been completely …
Browse files Browse the repository at this point in the history
…fixed yet
  • Loading branch information
roxma committed Feb 23, 2017
1 parent d36ebc5 commit 340d9a5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
3 changes: 0 additions & 3 deletions pythonx/cm_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ def _refresh_completions(self,ctx):

col = ctx['col']
startcol = col
base = ctx['typed'][startcol-1:]

# basick processing per source
for name in names:
Expand Down Expand Up @@ -391,7 +390,6 @@ def _refresh_completions(self,ctx):

def process_matches(self,name,ctx,startcol,matches):

base = ctx['typed'][startcol-1:]
abbr = self._sources[name].get('abbreviation','')

# formalize datastructure
Expand All @@ -405,7 +403,6 @@ def process_matches(self,name,ctx,startcol,matches):
formalized.append(e)

# filtering and sorting
# result = [ e for e in formalized if self._matcher(base=base,item=e)]
result = cm.get_matcher(self._nvim).process(name,ctx,startcol,formalized)

# fix some text
Expand Down
11 changes: 10 additions & 1 deletion pythonx/cm_matchers/fuzzy_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ def __init__(self,nvim,chcmp,*args):

def process(self,name,ctx,startcol,matches):

base = ctx['typed'][startcol-1:]
# fix for chinese characters
# `你好 abcd|`
# has col('.')==11 on vim
# the evaluated startcol is: startcol[8] typed[你好 abcd]
# but in python, "你好 abcd"[8] is not a valid index
begin = -(ctx['col'] - startcol)
base = ''
if begin:
base = ctx['typed'][begin:]


tmp = []
for item in matches:
Expand Down
18 changes: 13 additions & 5 deletions pythonx/cm_matchers/prefix_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ def __init__(self,nvim,chcmp,*args):

def process(self,name,ctx,startcol,matches):

base = ctx['typed'][startcol-1:]

matches = [m for m in matches if self._match(base,m)]
# fix for chinese characters
# `你好 abcd|`
# has col('.')==11 on vim
# the evaluated startcol is: startcol[8] typed[你好 abcd]
# but in python, "你好 abcd"[8] is not a valid index
begin = -(ctx['col'] - startcol)
base = ''
if begin:
base = ctx['typed'][begin:]

ret = [m for m in matches if self._match(base,m)]

# in python, 'A' sort's before 'a', we need to swapcase for the 'a'
# sorting before 'A'
matches.sort(key=lambda e: e['word'].swapcase())
ret.sort(key=lambda e: e['word'].swapcase())

return matches
return ret

def _match(self,base,item):
if len(base)>len(item['word']):
Expand Down

0 comments on commit 340d9a5

Please sign in to comment.