Match the position of the reverse-search match in the prompt

This commit is contained in:
Anthony Sottile
2020-01-07 17:31:41 -08:00
parent 817b542861
commit f1e8bcca3d
4 changed files with 31 additions and 15 deletions

View File

@@ -370,7 +370,7 @@ class Prompt:
for search_idx in range(reverse_idx, -1, -1):
if reverse_s in self._lst[search_idx]:
reverse_idx = self._y = search_idx
self._x = len(self._s)
self._x = self._lst[search_idx].index(reverse_s)
break
else:
reverse_failed = True
@@ -396,6 +396,7 @@ class Prompt:
elif key.keyname == b'^M':
return self._s
else:
self._x = len(self._s)
return None
def _cancel(self) -> PromptResult:

View File

@@ -120,6 +120,14 @@ class PrintsErrorRunner(Runner):
# this is a bit of a hack, the in-process fake defers all execution
callback()
@contextlib.contextmanager
def on_error(self):
try:
yield
except AssertionError: # pragma: no cover (only on failure)
self.screenshot()
raise
@contextlib.contextmanager
def and_exit(h):

View File

@@ -234,7 +234,11 @@ class DeferredRunner:
def _get_wch(self):
while not isinstance(self._ops[self._i], KeyPress):
self._i += 1
self._ops[self._i - 1](self.screen)
try:
self._ops[self._i - 1](self.screen)
except AssertionError: # pragma: no cover (only on failures)
self.screen.screenshot()
raise
self._i += 1
print(f'KEY: {self._ops[self._i - 1].wch!r}')
return self._ops[self._i - 1].wch
@@ -344,21 +348,11 @@ class DeferredRunner:
raise AssertionError(self.ops[i:])
@contextlib.contextmanager
def screenshot_on_assert(h):
try:
yield h
except AssertionError: # pragma: no cover
h.screenshot()
raise
@contextlib.contextmanager
def run_fake(*cmd, **kwargs):
h = DeferredRunner(cmd, **kwargs)
with screenshot_on_assert(h):
h.await_text(babi.VERSION_STR)
yield h
h.await_text(babi.VERSION_STR)
yield h
@contextlib.contextmanager
@@ -367,7 +361,7 @@ def run_tmux(*args, colors=256, **kwargs):
quoted = ' '.join(shlex.quote(p) for p in cmd)
term = 'screen-256color' if colors == 256 else 'screen'
cmd = ('bash', '-c', f'export TERM={term}; exec {quoted}')
with PrintsErrorRunner(*cmd, **kwargs) as h, screenshot_on_assert(h):
with PrintsErrorRunner(*cmd, **kwargs) as h, h.on_error():
# startup with coverage can be slow
h.await_text(babi.VERSION_STR, timeout=2)
yield h

View File

@@ -239,6 +239,19 @@ def test_search_reverse_search_history(run, xdg_data_home, ten_lines):
h.await_cursor_position(x=0, y=4)
def test_search_reverse_search_pos_during(run, xdg_data_home, ten_lines):
xdg_data_home.join('babi/history/search').ensure().write(
'line_3\n',
)
with run(str(ten_lines)) as h, and_exit(h):
h.press('^W')
h.press('^R')
h.press('ne')
h.await_text('search(reverse-search)`ne`: line_3')
h.await_cursor_position(y=23, x=30)
h.press('^C')
def test_search_reverse_search_pos_after(run, xdg_data_home, ten_lines):
xdg_data_home.join('babi/history/search').ensure().write(
'line_3\n',