Fix dedent at beginning of line
This commit is contained in:
2
babi.py
2
babi.py
@@ -1052,7 +1052,7 @@ class File:
|
||||
n = self._dedent_line(self.lines[self.y])
|
||||
if n:
|
||||
self.lines[self.y] = self.lines[self.y][n:]
|
||||
self.x = self.x_hint = self.x - n
|
||||
self.x = self.x_hint = max(self.x - n, 0)
|
||||
|
||||
def shift_tab(self, margin: Margin) -> None:
|
||||
if self.select_start:
|
||||
|
||||
@@ -55,6 +55,8 @@ class Screen:
|
||||
self.lines[y] = (line[:x] + s + line[x:])[:self.width]
|
||||
|
||||
def move(self, y, x):
|
||||
assert 0 <= y < self.height
|
||||
assert 0 <= x < self.width
|
||||
print(f'MOVE: y: {y}, x: {x}')
|
||||
self.y, self.x = y, x
|
||||
|
||||
|
||||
@@ -86,6 +86,14 @@ def test_dedent_selection(run, tmpdir):
|
||||
h.await_text('\n1\n2\n 3\n')
|
||||
|
||||
|
||||
def test_dedent_beginning_of_line(run, tmpdir):
|
||||
f = tmpdir.join('f')
|
||||
f.write(' hi\n')
|
||||
with run(str(f)) as h, and_exit(h):
|
||||
h.press('BTab')
|
||||
h.await_text('\nhi\n')
|
||||
|
||||
|
||||
def test_dedent_selection_does_not_make_selection_negative(run):
|
||||
with run() as h, and_exit(h):
|
||||
h.press('Tab')
|
||||
|
||||
Reference in New Issue
Block a user