diff options
author | hut <hut@hut.pm> | 2017-12-20 00:46:08 +0100 |
---|---|---|
committer | hut <hut@hut.pm> | 2017-12-20 00:46:08 +0100 |
commit | 5ec275e8bdb772af46efefde548e4dc8ea0e912c (patch) | |
tree | 083c5d40dee7217e5cbc51245180f4f876cd652f | |
parent | a7ae37db0cb6a945de799c8abeeb9bf5370d159c (diff) | |
parent | 79a003cb547dd28b09028553562853a365b83e46 (diff) | |
download | ranger-5ec275e8bdb772af46efefde548e4dc8ea0e912c.tar.gz |
Merge branch 'fix-cursor-movement' of https://github.com/0xjmz/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 6bcf20e9..13201e34 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 |