Skip to content

[compatible mode] 'Insert' mode is exited once focus is lost #7926

@zdohnal

Description

@zdohnal

Vim exists 'Insert' mode if compatible mode is turned on and you switch into a different application and back.

How to reproduce:
0) ./configure --enable-gui=no --with-features=huge && make

  1. ./src/vim -U NONE -u NONE -i NONE -c ':set compatible'
  2. switch to 'Insert' mode by 'i'
  3. write some text and don't leave 'Insert' mode
  4. lose focus on Vim - f.e. by switching to a different window/application
  5. switch back to Vim and try to write again

Actual behavior:
The insert mode is gone and you need to type 'i' again.

Expected behavior:
The insert mode stays active until user presses Esc.

Environment:

  • Vim version 8.2.2562 - compiled the current master branch from github
  • OS: Fedora 32
  • Terminal:GNOME Terminal

Additional context
The issue is reported by user for Fedora - the behavior started with adding the feature in 8.2. 2345 and can be worked around by unsetting t_fd and t_fe like :set t_fd= and :set t_fe=.

There is an incomplete analysis in the bug, where I was able to track down the reason why the bug appears. check_termcode() uses typebuf struct for comparing with termcodes list which will determine the key_name which is used later. typebuf has a different tb_off in compatible mode and in nocompatible, which seems to cause wrong interpretation of the incoming event - so Vim will interpret FOCUS_LOST as FOCUS_GAINED.
typebuf structure is used on many places and I wasn't able to track the issue further down...

Would you mind looking into it?

Thank you in advance!

Zdenek

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions