less cursor jumping on auto-ident; close #28

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-11-11 00:27:40 -05:00
parent 5a72e293c7
commit abc6898fd1
1 changed files with 20 additions and 12 deletions

View File

@ -478,20 +478,28 @@ class InsertTab(Method):
'''Insert tab into buffer, or tabbify line, depending on mode''' '''Insert tab into buffer, or tabbify line, depending on mode'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
cursor = w.logical_cursor() cursor = w.logical_cursor()
if w.mode.tabber: x = cursor.x
i = w.mode.tabber.get_level(cursor.y) y = cursor.y
else:
i = None
if i is None: # get the correct indentation lvl, if applicable
if w.mode.tabber:
lvl = w.mode.tabber.get_level(y)
else:
lvl = None
# if no lvl, insert a literal tab
if lvl is None:
w.insert_string_at_cursor(' ' * w.mode.tabwidth) w.insert_string_at_cursor(' ' * w.mode.tabwidth)
else: return
j = w.buffer.count_leading_whitespace(cursor.y)
if i != j: # insert the correct amount of whitespace
KillWhitespace().execute(w) ws = w.buffer.count_leading_whitespace(y)
w.insert_string(Point(0, cursor.y), ' ' * i) if lvl != ws:
else: w.delete(Point(0, y), Point(ws, y))
w.goto(Point(j, cursor.y)) w.insert_string(Point(0, y), ' ' * lvl)
x2 = max(x, lvl)
if w.logical_cursor().x < x2:
w.goto(Point(x2, y))
class KillWhitespace(Method): class KillWhitespace(Method):
'''Delete leading whitespace on current line''' '''Delete leading whitespace on current line'''