mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
Fix PTK shell sometimes not updating auto-suggest when up-arrow is pressed (#5787)
* fix combining consecutive history entries when loading ptk shell * add test case for combining history items * add news item for PTK history combining * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update ptk-history-combining.rst --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Andy Kipp <anki-code@users.noreply.github.com>
This commit is contained in:
parent
2cdcd6c976
commit
77ecefff34
3 changed files with 48 additions and 2 deletions
23
news/ptk-history-combining.rst
Normal file
23
news/ptk-history-combining.rst
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
**Added:**
|
||||||
|
|
||||||
|
* <news item>
|
||||||
|
|
||||||
|
**Changed:**
|
||||||
|
|
||||||
|
* <news item>
|
||||||
|
|
||||||
|
**Deprecated:**
|
||||||
|
|
||||||
|
* <news item>
|
||||||
|
|
||||||
|
**Removed:**
|
||||||
|
|
||||||
|
* <news item>
|
||||||
|
|
||||||
|
**Fixed:**
|
||||||
|
|
||||||
|
* prompt toolkit: Fixed autosuggest sometimes not updating when up-arrow is pressed (#5787).
|
||||||
|
|
||||||
|
**Security:**
|
||||||
|
|
||||||
|
* <news item>
|
|
@ -8,6 +8,7 @@ import pytest
|
||||||
from xonsh.platform import minimum_required_ptk_version
|
from xonsh.platform import minimum_required_ptk_version
|
||||||
from xonsh.shell import Shell
|
from xonsh.shell import Shell
|
||||||
from xonsh.shells.ptk_shell import tokenize_ansi
|
from xonsh.shells.ptk_shell import tokenize_ansi
|
||||||
|
from xonsh.shells.ptk_shell.history import PromptToolkitHistory
|
||||||
|
|
||||||
# verify error if ptk not installed or below min
|
# verify error if ptk not installed or below min
|
||||||
|
|
||||||
|
@ -145,3 +146,24 @@ def test_ptk_default_append_history(cmd, exp_append_history, ptk_shell, monkeypa
|
||||||
assert len(append_history_calls) == 1
|
assert len(append_history_calls) == 1
|
||||||
else:
|
else:
|
||||||
assert len(append_history_calls) == 0
|
assert len(append_history_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_ptk_combine_history(monkeypatch):
|
||||||
|
"""Test that consecutive identical history items are combined into a single item
|
||||||
|
when loading xonsh history items into prompt-toolkit history."""
|
||||||
|
|
||||||
|
def all_items(*args, **kwargs):
|
||||||
|
lines = [
|
||||||
|
"one two three",
|
||||||
|
"four five six",
|
||||||
|
"four five six",
|
||||||
|
"one two three",
|
||||||
|
]
|
||||||
|
for line in lines:
|
||||||
|
yield {"inp": line}
|
||||||
|
|
||||||
|
monkeypatch.setattr("xonsh.built_ins.XSH.history.all_items", all_items)
|
||||||
|
|
||||||
|
shell_hist = PromptToolkitHistory()
|
||||||
|
hist_strs = list(shell_hist.load_history_strings())
|
||||||
|
assert len(hist_strs) == 3
|
||||||
|
|
|
@ -25,11 +25,12 @@ class PromptToolkitHistory(prompt_toolkit.history.History):
|
||||||
hist = XSH.history
|
hist = XSH.history
|
||||||
if hist is None:
|
if hist is None:
|
||||||
return
|
return
|
||||||
|
prev_line = None
|
||||||
for cmd in hist.all_items(newest_first=True):
|
for cmd in hist.all_items(newest_first=True):
|
||||||
line = cmd["inp"].rstrip()
|
line = cmd["inp"].rstrip()
|
||||||
strs = self.get_strings()
|
if line != prev_line:
|
||||||
if len(strs) == 0 or line != strs[-1]:
|
|
||||||
yield line
|
yield line
|
||||||
|
prev_line = line
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
return self.get_strings()[index]
|
return self.get_strings()[index]
|
||||||
|
|
Loading…
Add table
Reference in a new issue