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
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 13 additions & 6 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 @@ -1359,7 +1361,11 @@ def display_line_with_prompt(self):

@property
def current_cursor_line_without_suggestion(self):
"""Current line, either output/input or Python prompt + code"""
"""
Current line, either output/input or Python prompt + code

:returns: FmtStr
"""
value = self.current_output_line + (
"" if self.coderunner.running else self.display_line_with_prompt
)
Expand Down Expand Up @@ -1556,7 +1562,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,
wcswidth(self.current_stdouterr_line)
+ wcswidth(self.stdin.current_line[: self.stdin.cursor_offset]),
width,
)
assert cursor_column >= 0, cursor_column
Expand All @@ -1574,12 +1581,12 @@ def move_screen_up(current_line_start_row):
len(self.current_line),
self.cursor_offset,
)
else:
else: # Common case for determining cursor position
cursor_row, cursor_column = divmod(
(
len(self.current_cursor_line_without_suggestion)
- len(self.current_line)
+ self.cursor_offset
wcswidth(self.current_cursor_line_without_suggestion.s)
- 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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def initialize_options(self):
"curtsies >=0.1.18",
"greenlet",
"six >=1.5",
"wcwidth"
]

extras_require = {
Expand Down