Skip to content

PMenu selection is not retained if multiline text is inserted #17394

Description

@habamax

Steps to reproduce

If inserted text is multilined it could shift selected pmenu item to another one:

asciicast

In the asciicast you can see that after selecting the second item it inserts contents but selection is shifted to the first(previous) menu item.

Will try to come up with a simple reproducible steps later.

Context: I have added registers completion source for custom autocomplete to be able to complete the whole contents of registers in contrast to CTRL-X CTRL-R that completes only words from registers.

Expected behaviour

Selection in Pmenu should be retained

Version of Vim

9.1.1418

Environment

Debian12, bash

Logs and stack traces

Activity

  1. habamax commented on May 29, 2025

    @habamax
    ContributorAuthor

    Minimal repro steps:

    1. vim --clean
    2. paste following and :source
    vim9script
    
    set completeopt=menuone,popup,noselect,fuzzy
    set infercase
    set complete=.^1,FMyComplete^5
    def g:MyComplete(findstart: number, base: string): any
        if findstart == 1
            return col('.')  - 1
        endif
        var items = ["one\ntwo\nthree", "four five six", "hello\nworld\nhere"]
        return items
    enddef
    
    1. execute Go<CTRL-N><CTRL-N>

    You can see

    one
    two
    three
    

    inserted but selection is gone.

    If you continue pressing CTRL-N multiple times, you might get segmentation fault:

    asciicast

  2. habamax commented on May 29, 2025

    @habamax
    ContributorAuthor

    @girishji this doesn't happen if I use completefunc with C-X C-U:

    vim9script
    
    set completeopt=menuone,popup,noselect,fuzzy
    set completefunc=MyComplete
    def g:MyComplete(findstart: number, base: string): any
        if findstart == 1
            return col('.')  - 1
        endif
        var items = ["one\ntwo\nthree", "four five six", "hello\nworld\nhere"]
        return items
    enddef
    

    No segfault and menu selection is correct:
    asciicast

    PS

    Also works fine with this:

    vim9script
    
    set completeopt=menuone,popup,noselect,fuzzy
    set completefunc=MyComplete
    set complete=F
    def g:MyComplete(findstart: number, base: string): any
        if findstart == 1
            return col('.')  - 1
        endif
        var items = ["one\ntwo\nthree", "four five six", "hello\nworld\nhere"]
        return items
    enddef
    

    pressing C-n -- no segfault

    However if you add .^1 or any other limit -- it has this issue (wrong pmenu selection and eventual segfault on continuous C-n presses)

    vim9script
    
    set completeopt=menuone,popup,noselect,fuzzy
    set completefunc=MyComplete
    set complete=.^1,F
    def g:MyComplete(findstart: number, base: string): any
        if findstart == 1
            return col('.')  - 1
        endif
        var items = ["one\ntwo\nthree", "four five six", "hello\nworld\nhere"]
        return items
    enddef
    
  3. girishji commented on May 29, 2025

    @girishji
    Contributor

    I'll take a look.

  4. added a commit that references this issue on May 29, 2025
  5. added a commit that references this issue on Jun 1, 2025
    6c40df0
  6. added 2 commits that reference this issue on Jun 2, 2025
    d25ebc7
    525c02a
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions