Skip to content

Commit 803c045

Browse files
committed
fix: Add boundary checks and error handling to hint drawing in easymotion.py
1 parent 2307c0e commit 803c045

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

easymotion.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,15 @@ def main(stdscr):
180180
for line_num, col, char, hint in pane.positions:
181181
y = pane.start_y + line_num
182182
x = pane.start_x + col
183-
if y < pane.start_y + pane.height and x < pane.start_x + pane.width:
184-
stdscr.addstr(y, x, hint[0], curses.color_pair(RED))
185-
char_width = get_char_width(char)
186-
if x + char_width < pane.start_x + pane.width:
183+
if (y < pane.start_y + pane.height and
184+
x < pane.start_x + pane.width and
185+
x + get_char_width(char) + 1 < pane.start_x + pane.width):
186+
try:
187+
stdscr.addstr(y, x, hint[0], curses.color_pair(RED))
188+
char_width = get_char_width(char)
187189
stdscr.addstr(y, x + char_width, hint[1], curses.color_pair(GREEN))
190+
except curses.error:
191+
pass
188192
stdscr.refresh()
189193

190194
# Handle hint selection
@@ -207,8 +211,13 @@ def main(stdscr):
207211
y = pane.start_y + line_num
208212
x = pane.start_x + col
209213
char_width = get_char_width(char)
210-
if x + char_width < pane.start_x + pane.width:
211-
stdscr.addstr(y, x + char_width, hint[1], curses.color_pair(GREEN))
214+
if (y < pane.start_y + pane.height and
215+
x < pane.start_x + pane.width and
216+
x + char_width + 1 < pane.start_x + pane.width):
217+
try:
218+
stdscr.addstr(y, x + char_width, hint[1], curses.color_pair(GREEN))
219+
except curses.error:
220+
pass
212221
stdscr.refresh()
213222

214223
ch2 = stdscr.getkey()

0 commit comments

Comments
 (0)