diff options
author | Marcin Zawada <marcinzw@gmail.com> | 2017-07-23 13:37:26 +0200 |
---|---|---|
committer | Marcin Zawada <marcinzw@gmail.com> | 2017-07-24 11:17:54 +0200 |
commit | 57df5b72d00b140a5083c0bc1427c5542b44221d (patch) | |
tree | f6b669e2b9feed54fe8aede84a7dd219663a267c /ranger | |
parent | 1bbee381f5c25f903cd70d2d56d6204cadf373dd (diff) | |
download | ranger-57df5b72d00b140a5083c0bc1427c5542b44221d.tar.gz |
Fix issue #852 incorrect cursor movement
Fix bug with incorrect cursor movement in console mode for text length greater than terminal width
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/gui/widgets/console.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 2d905f62..159405c6 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -87,6 +87,15 @@ class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many- fobj.close() Widget.destroy(self) + def _calculate_offset(self): + wid = self.wid - 2 + whalf = wid // 2 + if self.pos < whalf or len(self.line) < wid: + return 0 + if self.pos > len(self.line) - (wid - whalf): + return len(self.line) - wid + return self.pos - whalf + def draw(self): self.win.erase() if self.question_queue: @@ -97,11 +106,9 @@ class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many- self.addstr(0, 0, self.prompt) line = WideString(self.line) - overflow = -self.wid + len(self.prompt) + len(line) + 1 - if overflow > 0: - self.addstr(0, len(self.prompt), str(line[overflow:])) - else: - self.addstr(0, len(self.prompt), self.line) + if line: + x = self._calculate_offset() + self.addstr(0, len(self.prompt), str(line[x:])) def finalize(self): move = self.fm.ui.win.move @@ -112,7 +119,8 @@ class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many- pass else: try: - pos = uwid(self.line[0:self.pos]) + len(self.prompt) + x = self._calculate_offset() + pos = uwid(self.line[x:self.pos]) + len(self.prompt) move(self.y, self.x + min(self.wid - 1, pos)) except curses.error: pass |