Skip to content

Corrected cursor positioning on inputs with full-width (2 column) characters #817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 14, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added functionality for full-width character input
- Works with normal input and stdin input
- There still are issues with line wrapping when using full-width chars
  • Loading branch information
rybarczykj committed Jul 1, 2020
commit febbb88e0712c501c8878a3133e53c23b90ba94e
11 changes: 7 additions & 4 deletions bpython/curtsiesfrontend/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from bpython._py3compat import PythonLexer
from pygments.formatters import TerminalFormatter

from wcwidth import wcswidth

import blessings

import curtsies
Expand Down Expand Up @@ -1556,7 +1558,8 @@ def move_screen_up(current_line_start_row):

if self.stdin.has_focus:
cursor_row, cursor_column = divmod(
len(self.current_stdouterr_line) + self.stdin.cursor_offset,
len(self.current_stdouterr_line)
+ wcswidth(self.stdin.current_line[: self.stdin.cursor_offset]),
width,
)
assert cursor_column >= 0, cursor_column
Expand All @@ -1577,9 +1580,9 @@ def move_screen_up(current_line_start_row):
else:
cursor_row, cursor_column = divmod(
(
len(self.current_cursor_line_without_suggestion)
- len(self.current_line)
+ self.cursor_offset
self.current_cursor_line_without_suggestion.width
- wcswidth(self.current_line)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the distinction here between the wcswidth and .width, are some of these FmtStrs and some of them plain strs? (and if it's not clear, could you add comments to the definitions or initialization lines?)

+ wcswidth(self.current_line[: self.cursor_offset])
),
width,
)
Expand Down