[tui] fix source position (closes #119019)

  • update position after key processed to get the new position
  • for source smaller that available displaying area, we set the position to 0% if the user want to go up and 100% if the user want to go down.
authoralain leufroy <alain@leufroy.fr>
changeset2b76a860ac92
branchstable
phasepublic
hiddenno
parent revision#7cf5859668a2 [tui] fix source area stroke
child revision#67bf01870819 [tui] warn about urwid<1.0.0 bug using the "curses" interface (closes #119019), #1407f8d23767 merge stable
files modified by this revision
hgviewlib/curses/hgrepoviewer.py
# HG changeset patch
# User alain leufroy <alain@leufroy.fr>
# Date 1366930876 -7200
# Fri Apr 26 01:01:16 2013 +0200
# Branch stable
# Node ID 2b76a860ac92fc4ce699e5eb7a65e6902c7ac033
# Parent 7cf5859668a2d1b4e6a8654c675254027f702331
[tui] fix source position (closes #119019)

- update position after key processed to get the *new* position
- for source smaller that available displaying area, we set the position to
0% if the user want to go up and 100% if the user want to go down.

diff --git a/hgviewlib/curses/hgrepoviewer.py b/hgviewlib/curses/hgrepoviewer.py
@@ -138,24 +138,24 @@
1          self.text = SourceText(text, wrap='clip')
2          self.position = 0
3          body = ScrollableListBox([self.text])
4          super(SourceViewer, self).__init__(body=body, *args, **kwargs)
5 
6 -    def update_position(self, size):
7 +    def update_position(self, size, isdown):
8          curr, fullheight = self.body.inset_fraction
9          _, displayedheight = size
10          stroke = fullheight - displayedheight
11          if stroke <= 0: # fully displayed
12 -            self.position = 100
13 +            self.position = 100 if isdown else 0
14          else:
15              self.position = max(min(curr * 100 / stroke, 100), 0)
16          signals.emit_signal(self, 'translated')
17 
18      def keypress(self, size, key):
19 +        super(SourceViewer, self).keypress(size, key)
20          if key.endswith(('up', 'down')):
21 -            self.update_position(size)
22 -        super(SourceViewer, self).keypress(size, key)
23 +            self.update_position(size, key.endswith('down'))
24 
25      def mouse_event(self, size, event, button, col, row, focus):
26          """Scroll content"""
27          if is_mouse_press(event) and button in (4, 5):
28              self.update_position(size)