Skip to content

Strange right arrow completion #14137

Closed

Description

@oscarbenjamin

I don't really know how to explain a full reproducer for this because it depends on the history of things that I have typed into ipython. Right now I can reproduce this as follows but I am not sure what previous things I have done that cause this to happen.

First just setup a few pieces:

In [4]: solve = lambda *a, **kw: None

In [5]: syms = E = None

Now I run this command:

In [6]: solve(E, syms)

Now I want to rerun this but change it to solve(groebner(E), syms) so I follow these steps carefully:

Push <up>, then <home> then <right> 6 times and type groebner(. Now I have this:

In [7]: solve(groebner(E, syms)

and my cursor is flashing on the E.

I want to add the closing bracket ) after the E so I press <right> and then something weird happens:

In [7]: solve(groebner(, syms, dict=True)E, syms)

Somehow pressing <right> inserted the text , syms, dict=True) and then left my cursor at the end of that text.

Is this a bug? Have I perhaps somehow accidentally configured something that makes this happen?

Adding the text , syms, dict=True) is certainly something that I have previously done as an edit so maybe ipython "remembers" that somehow?

Note that if I change anything about this like if I delete the s from the start of the line then it does not happen. Somehow this is specific to the exact text that I am editing e.g. if I have this then I can use both <left> and <right> normally:

In [7]: olve(groebner(E, syms)

I think it is trying to complete from the history somehow e.g. if I have this:

In [7]: solve(groebner(E, syms),

then the completer offers:
image
It seems that the completion is being used when the cursor is not at the end of the line somehow.

Activity

  1. codtiger commented on Nov 20, 2023

    @codtiger

    Running into the same issue on WSL2 / Windows 10. Pretty strange behavior that right arrow at some random points triggers auto-completion mid line, while the expected behavior is to only complete when the cursor's on the end character and a suggestion is shown. Has anyone been trying to look at this or try to replicate it?
    Python Version: 3.10.12
    IPython Version: 8.7.12

  2. iftekhart commented on Mar 28, 2024

    @iftekhart

    Reporting the same issue in ipython version 8.22.2

  3. k4lizen commented on Sep 5, 2024

    @k4lizen

    repro:

    In [15]: 123
    Out[15]: 123
    
    In [16]: 132

    Enter 123 in, press Enter. Then write down 2. Press Left. Type 1 (in front of the 2). Press right arrow key. A 3 is autocompleted and it results in 132.

  4. oscarbenjamin commented on Sep 5, 2024

    @oscarbenjamin
    Author

    repro:

    Thanks, I can reproduce it with that as well. I guess it sees that 12 can be completed to 123 and so inserts 3 but the cursor is in the wrong position.

    It only happens if the cursor is not at the end of the line when you add the 1 so that the match occurs while the cursor is in the wrong position.

  5. t4rf9 commented on Dec 31, 2024

    @t4rf9

    Same problem!
    I wish it would be possible to disable auto completion while the cursor is not at the end, if there is no other particular reason to allow this. I think this is where the problem lies.

  6. captnjameskirk commented on Feb 17, 2025

    @captnjameskirk

    Same here and driving me nuts, macOS 15.3 with ipython 8.32.0 and python 3.13.2. The only "fix" I've found is to set TerminalInteractiveShell.editing_mode=vi, hit ESC to enter normal mode, and use j/k to move left/right instead of the arrow keys, then hit i to enter insert mode when I get to the position I want edit. Using the right arrow key in vi insert mode still has this bug, so using vi normal mode for movement within the line is the only way to avoid it.

  7. Carreau commented on Feb 26, 2025

    @Carreau
    Member

    There has been a number of updates the autosuggestions, and completion in 9.0 (main), and I hve published a beta, I would appreciate for some of you to try,

    but as I can't reproduce, I can't debug.

    Please also check your prompt toolkit version; my hunch is that it's the autosuggestions, not the completions. It should not be triggered when not at end of line.

  8. k4lizen commented on Mar 6, 2025

    @k4lizen

    @Carreau
    I can reproduce on main (a6a4b0a)

    Please also check your prompt toolkit version

    how?

  9. k4lizen commented on Mar 6, 2025

    @k4lizen

    It occurs to me almost every time I write somefunction() then <left arrow>, <fill in the function arguments>, <right arrow> ... and attempt to continue typing the rest of the line, which is instead filled with autocompleted stuff (which is always wrong, as in the 123 -> 132 case).

    This is often enough that ipython is unusable for me, and I have been using regular python since encountering this bug

  10. added a commit that references this issue on Mar 6, 2025
  11. Carreau commented on Mar 6, 2025

    @Carreau
    Member
    In [1]: import prompt_toolkit
    
    In [2]: prompt_toolkit.__version__
    Out[2]: '3.0.49'`
    

    Could you try #14823 ?

    I think I managed to reproduce, but that requires a bit more setup than what is described here,
    for example it is likely that @oscarbenjamin you may have typed solve(groebner(E, syms), syms, dict=True) or something similar in the past ?

    here is my attempt at reproducing, then trying a fix.

    Screen.Recording.2025-03-06.at.16.33.24.mov
  12. added this to the 8.34 milestone on Mar 6, 2025
  13. k4lizen commented on Mar 6, 2025

    @k4lizen

    My prompt toolkit version is 3.0.50. The 123 reproducer #14137 (comment) doesn't work for you?

    I can confirm your branch fixes the issue for me. Awesome :D

  14. Carreau commented on Mar 6, 2025

    @Carreau
    Member

    The 123 reproducer #14137 (comment) doesn't work for you?

    Well, it depends, I could make it to reproduce but I can make it do anything,
    like for me 1000002

    Untitled.2.mov
  15. oscarbenjamin commented on Mar 6, 2025

    @oscarbenjamin
    Author

    Well, it depends, I could make it to reproduce but I can make it do anything,
    like for me 1000002

    Do you not consider that to be a bug?

    The behaviour I would expect here is that when the cursor is not at the end of the line the right arrow key always just moves the cursor and does not insert text or anything else. Any other behaviour means you lose the ability to navigate around the line using the left and right arrow keys.

  16. Carreau commented on Mar 6, 2025

    @Carreau
    Member

    Yeah I consider it a bug (hence the PR to fix it that needs more test).

  17. added a commit that references this issue on Mar 8, 2025
  18. linked a pull request that will close this issueFix accept invisible completions #14823on Mar 8, 2025
  19. Carreau commented on Mar 8, 2025

    @Carreau
    Member

    closed by #14823

  20. oscarbenjamin commented on Mar 8, 2025

    @oscarbenjamin
    Author

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions