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
w.insert_string_at_cursor(' ' * w.mode.tabwidth) if w.mode.tabber:
lvl = w.mode.tabber.get_level(y)
else: else:
j = w.buffer.count_leading_whitespace(cursor.y) lvl = None
if i != j:
KillWhitespace().execute(w) # if no lvl, insert a literal tab
w.insert_string(Point(0, cursor.y), ' ' * i) if lvl is None:
else: w.insert_string_at_cursor(' ' * w.mode.tabwidth)
w.goto(Point(j, cursor.y)) 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): class KillWhitespace(Method):
'''Delete leading whitespace on current line''' '''Delete leading whitespace on current line'''