Fix up end scroll and support END key to scroll to bottom

This commit is contained in:
Kevin Lange 2017-01-10 17:15:26 +09:00
parent a4e9fc0123
commit 711b837c52

View File

@ -121,10 +121,10 @@ You can also <link target=\"special:contents\">check the Table of Contents</link
self.update_text_buffer()
def update_text_buffer(self):
if self.text_buffer:
self.text_buffer.destroy()
self.text_buffer = yutani.GraphicsBuffer(self.width - self.decorator.width(),self.height-self.decorator.height()+80)
if self.size_changed or not self.text_buffer:
if self.text_buffer:
self.text_buffer.destroy()
self.text_buffer = yutani.GraphicsBuffer(self.width - self.decorator.width(),self.height-self.decorator.height()+80)
surface = self.text_buffer.get_cairo_surface()
ctx = cairo.Context(surface)
ctx.rectangle(0,0,surface.get_width(),surface.get_height())
@ -183,14 +183,13 @@ You can also <link target=\"special:contents\">check the Table of Contents</link
self.scroll_offset -= 1
self.text_offset += self.tr.line_height
while self.text_offset >= self.tr.line_height:
n = (len(self.tr.lines)-self.tr.visible_lines())+4
n = n if n >= 0 else 0
if self.scroll_offset >= n:
self.scroll_offset = n
self.text_offset = 0
break
self.scroll_offset += 1
self.text_offset -= self.tr.line_height
n = (len(self.tr.lines)-self.tr.visible_lines())+4
n = n if n >= 0 else 0
if self.scroll_offset >= n:
self.scroll_offset = n
self.text_offset = 0
self.update_text_buffer()
def text_under_cursor(self, msg):
@ -253,6 +252,12 @@ You can also <link target=\"special:contents\">check the Table of Contents</link
self.scroll_offset = 0
self.update_text_buffer()
return True
elif msg.event.keycode == yutani.Keycode.END:
n = (len(self.tr.lines)-self.tr.visible_lines())+4
self.scroll_offset = n if n >= 0 else 0
self.text_offset = 0
self.update_text_buffer()
return True
elif msg.event.keycode == yutani.Keycode.PAGE_UP:
self.scroll(int(-self.height/2))
return True