MCPcopy Create free account
hub / github.com/ipython/ipython / _swap_autosuggestion

Function _swap_autosuggestion

IPython/terminal/shortcuts/auto_suggest.py:609–630  ·  view source on GitHub ↗

We skip most recent history entry (in either direction) if it equals the current autosuggestion because if user cycles when auto-suggestion is shown they most likely want something else than what was suggested (otherwise they would have accepted the suggestion).

(
    buffer: Buffer,
    provider: NavigableAutoSuggestFromHistory,
    direction_method: Callable,
)

Source from the content-addressed store, hash-verified

607
608
609def _swap_autosuggestion(
610 buffer: Buffer,
611 provider: NavigableAutoSuggestFromHistory,
612 direction_method: Callable,
613):
614 """
615 We skip most recent history entry (in either direction) if it equals the
616 current autosuggestion because if user cycles when auto-suggestion is shown
617 they most likely want something else than what was suggested (otherwise
618 they would have accepted the suggestion).
619 """
620 suggestion = buffer.suggestion
621 if not suggestion:
622 return
623
624 query = _get_query(buffer.document)
625 current = query + suggestion.text
626
627 direction_method(query=query, other_than=current, history=buffer.history)
628
629 new_suggestion = provider.get_suggestion(buffer, buffer.document)
630 buffer.suggestion = new_suggestion
631
632
633def swap_autosuggestion_up(event: KeyPressEvent):

Callers 2

swap_autosuggestion_upFunction · 0.85
swap_autosuggestion_downFunction · 0.85

Calls 2

_get_queryFunction · 0.85
get_suggestionMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…