@@ -402,7 +402,7 @@ def __init__(
402402 # so we're just using the same object
403403 self .interact = self .status_bar
404404
405- # line currently being edited, without ps1 (usually '>>> ')
405+ # logical line currently being edited, without ps1 (usually '>>> ')
406406 self ._current_line = ""
407407
408408 # current line of output - stdout and stdin go here
@@ -744,8 +744,9 @@ def process_key_event(self, e):
744744 )
745745 and self .config .curtsies_right_arrow_completion
746746 and self .cursor_offset == len (self .current_line )
747+ # if at end of current line and user presses RIGHT (to autocomplete)
747748 ):
748-
749+ # then autocomplete
749750 self .current_line += self .current_suggestion
750751 self .cursor_offset = len (self .current_line )
751752 elif e in ("<UP>" ,) + key_dispatch [self .config .up_one_line_key ]:
@@ -1435,6 +1436,23 @@ def current_output_line(self, value):
14351436 self .current_stdouterr_line = ""
14361437 self .stdin .current_line = "\n "
14371438
1439+ def number_of_padding_chars_on_current_cursor_line (self ):
1440+ """ To avoid cutting off two-column characters at the end of lines where
1441+ there's only one column left, curtsies adds a padding char (u' ').
1442+ It's important to know about these for cursor positioning.
1443+
1444+ Should return zero unless there are fullwidth characters. """
1445+ full_line = self .current_cursor_line_without_suggestion
1446+ line_with_padding = "" .join (
1447+ line .s
1448+ for line in paint .display_linize (
1449+ self .current_cursor_line_without_suggestion .s , self .width
1450+ )
1451+ )
1452+
1453+ # the difference in length here is how much padding there is
1454+ return len (line_with_padding ) - len (full_line )
1455+
14381456 def paint (
14391457 self ,
14401458 about_to_exit = False ,
@@ -1620,7 +1638,8 @@ def move_screen_up(current_line_start_row):
16201638 wcswidth (self .current_cursor_line_without_suggestion .s )
16211639 - wcswidth (self .current_line )
16221640 + wcswidth (self .current_line [: self .cursor_offset ])
1623- ),
1641+ )
1642+ + self .number_of_padding_chars_on_current_cursor_line (),
16241643 width ,
16251644 )
16261645 assert cursor_column >= 0 , (
0 commit comments