Skip to content

Commit 1a9225e

Browse files
committed
refactor: optimize match finding algorithm to improve smartcase and smartsign matching
1 parent 0a318d7 commit 1a9225e

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

easymotion.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -540,24 +540,17 @@ def find_matches(panes, search_ch):
540540

541541
for pane in panes:
542542
for line_num, line in enumerate(pane.lines):
543-
pos = 0
544-
while pos < len(line):
545-
found = False
543+
# 對每個字符位置檢查所有可能的匹配
544+
for pos in range(len(line)):
546545
for ch in search_chars:
547546
if CASE_SENSITIVE:
548-
idx = line.find(ch, pos)
547+
if pos < len(line) and line[pos] == ch:
548+
visual_col = sum(get_char_width(c) for c in line[:pos])
549+
matches.append((pane, line_num, visual_col))
549550
else:
550-
idx = line.lower().find(ch.lower(), pos)
551-
if idx != -1:
552-
visual_col = sum(get_char_width(c) for c in line[:idx])
553-
matches.append((pane, line_num, visual_col))
554-
found = True
555-
pos = idx + 1
556-
break
557-
if not found:
558-
# if no match found, move to next position, consider character width
559-
if pos < len(line):
560-
pos += 1
551+
if pos < len(line) and line[pos].lower() == ch.lower():
552+
visual_col = sum(get_char_width(c) for c in line[:pos])
553+
matches.append((pane, line_num, visual_col))
561554

562555
return matches
563556

0 commit comments

Comments
 (0)