@@ -402,7 +402,7 @@ def __init__(
402
402
# so we're just using the same object
403
403
self .interact = self .status_bar
404
404
405
- # line currently being edited, without ps1 (usually '>>> ')
405
+ # logical line currently being edited, without ps1 (usually '>>> ')
406
406
self ._current_line = ""
407
407
408
408
# current line of output - stdout and stdin go here
@@ -744,8 +744,9 @@ def process_key_event(self, e):
744
744
)
745
745
and self .config .curtsies_right_arrow_completion
746
746
and self .cursor_offset == len (self .current_line )
747
+ # if at end of current line and user presses RIGHT (to autocomplete)
747
748
):
748
-
749
+ # then autocomplete
749
750
self .current_line += self .current_suggestion
750
751
self .cursor_offset = len (self .current_line )
751
752
elif e in ("<UP>" ,) + key_dispatch [self .config .up_one_line_key ]:
@@ -1435,6 +1436,23 @@ def current_output_line(self, value):
1435
1436
self .current_stdouterr_line = ""
1436
1437
self .stdin .current_line = "\n "
1437
1438
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
+
1438
1456
def paint (
1439
1457
self ,
1440
1458
about_to_exit = False ,
@@ -1620,7 +1638,8 @@ def move_screen_up(current_line_start_row):
1620
1638
wcswidth (self .current_cursor_line_without_suggestion .s )
1621
1639
- wcswidth (self .current_line )
1622
1640
+ wcswidth (self .current_line [: self .cursor_offset ])
1623
- ),
1641
+ )
1642
+ + self .number_of_padding_chars_on_current_cursor_line (),
1624
1643
width ,
1625
1644
)
1626
1645
assert cursor_column >= 0 , (
0 commit comments