Fix dedent at beginning of line

This commit is contained in:
Anthony Sottile
2020-01-08 21:16:53 -08:00
parent de57f2cef2
commit 1030f1170a
3 changed files with 11 additions and 1 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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')