def __init__(self): super().__init__() self._history = history.History( history.read(), max_items=api.settings.command_history_limit.value) self.mode = None self.returnPressed.connect(self._on_return_pressed) self.editingFinished.connect(self._history.reset) self.textEdited.connect(self._on_text_edited) self.textChanged.connect(self._incremental_search) self.cursorPositionChanged.connect(self._on_cursor_position_changed) QCoreApplication.instance().aboutToQuit.connect(self._on_app_quit) api.modes.COMMAND.entered.connect(self._on_entered) styles.apply(self)
def init(self) -> None: """Lazy-initialize command-line when first entering command mode.""" from vimiv.commands import history self._history = history.History( self.PREFIXES, max_items=api.settings.command.history_limit.value, ) self.returnPressed.connect(self._on_return_pressed) self.textEdited.connect(self._on_text_edited) self.textChanged.connect(self._incremental_search) self.cursorPositionChanged.connect(self._on_cursor_position_changed) QCoreApplication.instance().aboutToQuit.connect( # type: ignore self._history.write) styles.apply(self)
def test_substring_search_history(): hist = history.History(["first", "final", "useless"]) assert hist.substr_cycle(HistoryDirection.Next, "fi") == "first" assert hist.substr_cycle(HistoryDirection.Next, "fi") == "final" assert hist.substr_cycle(HistoryDirection.Next, "fi") == "fi" assert hist.substr_cycle(HistoryDirection.Prev, "fi") == "final"
def test_clear_temporary_history_element(): hist = history.History(["first"]) hist.cycle(HistoryDirection.Next, "temporary") hist.update("second") assert "temporary" not in hist
def test_do_not_fail_cycle_on_empty_history(): hist = history.History([]) result = hist.cycle(HistoryDirection.Next, "temporary") assert result == ""
def test_cycle_through_history(): hist = history.History(["first", "second", "third"]) assert hist.cycle(HistoryDirection.Next, "temporary") == "first" assert hist.cycle(HistoryDirection.Next, "") == "second" assert hist.cycle(HistoryDirection.Prev, "") == "first" assert hist.cycle(HistoryDirection.Prev, "") == "temporary"
def test_never_exceed_history_max_elements(): hist = history.History([], 20) for i in range(25): hist.update("test-%d" % (i)) assert len(hist) == 20
def test_update_history_with_duplicates(): hist = history.History([]) hist.update("test") hist.update("test") assert len(hist) == 1
def test_update_history(): hist = history.History([]) hist.update("test") assert "test" in hist