nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.79k stars 833 forks source link

Pickers that do not change buffer change last insert mode in the original buffer #856

Open muniter opened 3 years ago

muniter commented 3 years ago

Description

Pickers that do not go to a different buffer change the last insert mode location ("^" mark) of the buffer it was called from. When the action select was performed while the prompt is in insert mode.

Expected Behavior

Telescope should not modify the buffer it was called from, last insert mode location ("^" mark) should not change to the line telescope was called from.

Actual Behavior

Telescope changes the last insert mode location which disrupt the flow of the user since now gi is the location telescope was called from. This only happens if the picker does not change the buffer

For some reason stopinsert is not working. https://github.com/nvim-telescope/telescope.nvim/blob/1fefd0098e92315569b71a99725b63521594991e/lua/telescope/actions/init.lua#L209-L211

Details

Reproduce 1. nvim -nu test.vim 2. enter insert mode 3. add a few lines to the file: ``` 1 2 3 4 ``` 4. leave insert mode 5. check your last insert mode location `marks ^` 6. move to a diferent line that's not the last insert mode location 7. :Telescope current_buffer_fuzzy_find 8. pick any entry from the picker but do not leave insert mode in the picker/prompt using `` 9. check the last insert mode location `marks ^` it's now the line the picker was called from This happens with all the pickers I've tried that do not change buffers (current_buffer_fuzzy_find, colorschemes, planets) Small video demonstration https://user-images.githubusercontent.com/9699804/119183571-e0a8e780-ba39-11eb-9f37-40fd7b2f46bd.mp4
Environment - nvim --version output: NVIM v0.5.0-dev+1319-g7c9569702 - Operating system: Linux 5.8.0-53-generic #60~20.04.1-Ubuntu x86_64 GNU/Linux - Telescope commit: 69eb5ea
Configuration

```viml " Plug Configuration {{{ call plug#begin('~/.config/nvim/plugged') Plug 'nvim-lua/popup.nvim' Plug 'nvim-lua/plenary.nvim' Plug 'nvim-telescope/telescope.nvim' call plug#end() lua require('telescope').setup() ```

l-kershaw commented 3 years ago

I can reproduce this, but can't figure out what's causing it.


If you check the mark (using vim.api.nvim_buf_get_mark) after key_func here, the mark is still as expected. But if you check it after the mapping has completed (and the user has control again), the mark has changed. I don't know what could possibly be changing the mark between these two points in time.

oconnor663 commented 1 year ago

This bug still repros for me, and I'd love to help fix it, because "1) open file, 2) gi" is a really common workflow for me. It may be relevant that although gi (insert at last edit) and '^ (jump to end of last edit) are affected, '. (jump to start of last edit) is not affected.