parent
155044696f
commit
3b10120e58
|
@ -396,7 +396,7 @@ class ToggleMargins(Method):
|
||||||
class CenterView(Method):
|
class CenterView(Method):
|
||||||
'''Move view to center on cursor'''
|
'''Move view to center on cursor'''
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
w.center_view()
|
w.center_view(force=True)
|
||||||
class SetMark(Method):
|
class SetMark(Method):
|
||||||
'''Set the mark to the current cursor location'''
|
'''Set the mark to the current cursor location'''
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
|
|
35
window.py
35
window.py
|
@ -221,7 +221,7 @@ class Window(object):
|
||||||
def last_is_visible(self):
|
def last_is_visible(self):
|
||||||
return self.point_is_visible(self.buffer.get_buffer_end())
|
return self.point_is_visible(self.buffer.get_buffer_end())
|
||||||
|
|
||||||
def center_view(self):
|
def center_view(self, force=False):
|
||||||
(x, y) = self.logical_cursor().xy()
|
(x, y) = self.logical_cursor().xy()
|
||||||
counter = 0
|
counter = 0
|
||||||
while counter < self.height / 2:
|
while counter < self.height / 2:
|
||||||
|
@ -234,6 +234,14 @@ class Window(object):
|
||||||
(x, y) = (0, 0)
|
(x, y) = (0, 0)
|
||||||
break
|
break
|
||||||
counter += 1
|
counter += 1
|
||||||
|
|
||||||
|
# make sure we aren't "centering" on the end of the file (where half the
|
||||||
|
# screen is empty). that is, unless that's what the user wants
|
||||||
|
# (indicated by force=True).
|
||||||
|
if not force:
|
||||||
|
(x2, y2) = self.last_visible_coords()
|
||||||
|
if y2 < y or x2 < x:
|
||||||
|
x, y = x2, y2
|
||||||
self.first = Point(x - (x % self.width), y)
|
self.first = Point(x - (x % self.width), y)
|
||||||
self.redraw()
|
self.redraw()
|
||||||
def lower_view(self):
|
def lower_view(self):
|
||||||
|
@ -267,11 +275,13 @@ class Window(object):
|
||||||
self.first = Point(x - (x % self.width), y)
|
self.first = Point(x - (x % self.width), y)
|
||||||
self.redraw()
|
self.redraw()
|
||||||
def assure_visible_cursor(self):
|
def assure_visible_cursor(self):
|
||||||
p = self.logical_cursor()
|
if not self.cursor_is_visible():
|
||||||
if self.first > p:
|
self.center_view()
|
||||||
self.upper_view()
|
#p = self.logical_cursor()
|
||||||
elif p > self.last:
|
#if self.first > p:
|
||||||
self.lower_view()
|
# self.upper_view()
|
||||||
|
#elif p > self.last:
|
||||||
|
# self.lower_view()
|
||||||
|
|
||||||
# moving in buffer
|
# moving in buffer
|
||||||
def forward(self):
|
def forward(self):
|
||||||
|
@ -457,7 +467,13 @@ class Window(object):
|
||||||
self.assure_visible_cursor()
|
self.assure_visible_cursor()
|
||||||
def goto_end(self, force=False):
|
def goto_end(self, force=False):
|
||||||
self.cursor = self.buffer.get_buffer_end()
|
self.cursor = self.buffer.get_buffer_end()
|
||||||
(x, y) = self.logical_cursor().xy()
|
(x, y) = self.last_visible_coords()
|
||||||
|
if force or not self.cursor_is_visible():
|
||||||
|
self.first = Point(x - (x % self.width), y)
|
||||||
|
self.redraw()
|
||||||
|
|
||||||
|
def last_visible_coords(self):
|
||||||
|
(x, y) = self.buffer.get_buffer_end().xy()
|
||||||
if x == 0:
|
if x == 0:
|
||||||
y -= 1
|
y -= 1
|
||||||
x = len(self.buffer.lines[y])
|
x = len(self.buffer.lines[y])
|
||||||
|
@ -474,10 +490,7 @@ class Window(object):
|
||||||
(x, y) = (0, 0)
|
(x, y) = (0, 0)
|
||||||
break
|
break
|
||||||
counter += 1
|
counter += 1
|
||||||
|
return (x, y)
|
||||||
if force or not self.cursor_is_visible():
|
|
||||||
self.first = Point(x - (x % self.width), y)
|
|
||||||
self.redraw()
|
|
||||||
|
|
||||||
# mark manipulation
|
# mark manipulation
|
||||||
def set_mark_point(self, p):
|
def set_mark_point(self, p):
|
||||||
|
|
Loading…
Reference in New Issue