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'''
def _execute(self, w, **vargs):
cursor = w.logical_cursor()
if w.mode.tabber:
i = w.mode.tabber.get_level(cursor.y)
else:
i = None
x = cursor.x
y = cursor.y
if i is None:
w.insert_string_at_cursor(' ' * w.mode.tabwidth)
# get the correct indentation lvl, if applicable
if w.mode.tabber:
lvl = w.mode.tabber.get_level(y)
else:
j = w.buffer.count_leading_whitespace(cursor.y)
if i != j:
KillWhitespace().execute(w)
w.insert_string(Point(0, cursor.y), ' ' * i)
else:
w.goto(Point(j, cursor.y))
lvl = None
# if no lvl, insert a literal tab
if lvl is None:
w.insert_string_at_cursor(' ' * w.mode.tabwidth)
return
# insert the correct amount of whitespace
ws = w.buffer.count_leading_whitespace(y)
if lvl != ws:
w.delete(Point(0, y), Point(ws, 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):
'''Delete leading whitespace on current line'''