Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actions.close mapping leaves a terminal in insert mode #2785

Closed
ten3roberts opened this issue Nov 15, 2023 · 8 comments
Closed

actions.close mapping leaves a terminal in insert mode #2785

ten3roberts opened this issue Nov 15, 2023 · 8 comments
Labels
bug Something isn't working reproducible Bug that can be reproduced.

Comments

@ten3roberts
Copy link

Description

Using actions.close in the insert mappings for the telescope prompt does not restore the mode of the underlying terminal buffer.

Neovim version

NVIM v0.10.0-dev-2931+gd92dd2a0c-Homebrew
Build type: Release
LuaJIT 2.1.1699180677
Run "nvim -V1 -v" for more info

Operating system and version

macOS Sonoma

Telescope version / branch / rev

telescope 0.1.4

checkhealth telescope

==============================================================================
telescope: require("telescope.health").check()

Checking for required plugins ~
- OK plenary installed.
- OK nvim-treesitter installed.

Checking external dependencies ~
- OK rg: found ripgrep 13.0.0
- OK fd: found fd 8.7.0

===== Installed extensions ===== ~

Telescope Extension: `bookmarks` ~
- No healthcheck provided

Telescope Extension: `dap` ~
- No healthcheck provided

Telescope Extension: `fzf` ~
- OK lib working as expected
- OK file_sorter correctly configured
- OK generic_sorter correctly configured

Telescope Extension: `menufacture` ~
- No healthcheck provided

Telescope Extension: `smart_open` ~
- No healthcheck provided

Steps to reproduce

  • :term (opens in normal mode)
  • :Telescope find_files
  • <esc>

The terminal is now in insert/terminal mode, instead of normal mode.

Non terminal buffers correcly restore their mode to normal.

Expected behavior

The terminal buffer is restored to normal mode

Actual behavior

The terminal is left in the mode of the telescope prompt, I.e; insert mode

Minimal config

vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvim/site]])
local package_root = "/tmp/nvim/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
	require("packer").startup({
		{
			"wbthomason/packer.nvim",
			{
				"nvim-telescope/telescope.nvim",
				requires = {
					"nvim-lua/plenary.nvim",
					{ "nvim-telescope/telescope-fzf-native.nvim", run = "make" },
				},
			},
			-- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
		},
		config = {
			package_root = package_root,
			compile_path = install_path .. "/plugin/packer_compiled.lua",
			display = { non_interactive = true },
		},
	})
end
_G.load_config = function()
	require("telescope").setup({
		defaults = {
			mappings = {
				i = {
					["<esc>"] = require("telescope.actions").close,
				},
			},
		},
	})
	require("telescope").load_extension("fzf")
	-- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
end
if vim.fn.isdirectory(install_path) == 0 then
	print("Installing Telescope and dependencies.")
	vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]])
@ten3roberts ten3roberts added the bug Something isn't working label Nov 15, 2023
@robbplo
Copy link

robbplo commented Nov 15, 2023

This is also happening to me when i find_files from any other file, not even a terminal. Thought i was going crazy, adding jjjj to the top of all my files lol

@jamestrew
Copy link
Contributor

@ten3roberts thanks for the report, I'm able to reproduce this

@robbplo I'm not able to reproduce this outside of :term. We're tracking another issue where this seems to happen if you have something (like barbar.nvim with some settings) that looks at buffer options inside a BufWinLeave event. Feels like it's a general neovim issue (which has happened before).

Either way, both issues are somewhat related to #2766

@jamestrew jamestrew added ! Bug or issue has be opened for more than a week reproducible Bug that can be reproduced. and removed ! Bug or issue has be opened for more than a week labels Nov 16, 2023
@robbplo
Copy link

robbplo commented Nov 16, 2023

@jamestrew Hit the nail on the head, it no longer happens when i disable barbar.nvim.

@jamestrew
Copy link
Contributor

jamestrew commented Jan 13, 2024

Can people try out this PR? #2850

I may have accidentally fixed this 😁

edit: nope, nvm don't bother

@tbung
Copy link

tbung commented Jan 13, 2024

I tested it and it does not fix the issue. As far as I can tell the added call to stopinsert is only in the commands builtin, but the issue here is with buffers. I am not really familiar with telescope's code base, but a quick test showed, that adding

  vim.schedule(function()
    vim.cmd [[stopinsert]]
  end)

to the end of action_set.edit (about here

) at least goes back to normal mode, it does however not reset cursor position.

Edit: Ok I should have read the issue more closely. The issue I have, as I said in #2766, is with buffer when selecting a terminal buffer. I have now also tested the issue described here and it is also not fixed. Again, naive fix is to add stopinsert, but to actions.close.

@jamestrew
Copy link
Contributor

@tbung yeah you're right in that it doesn't fix it. Thanks for trying. I was messing up the testing.

Let me think about this some more. There's a ton of flaky behavior around switching modes when opening/closing telescope. I need to be careful I don't break something trying to fix something else. I'm not even fully convinced this isn't a neovim core issue (which has happened before).

@jamestrew
Copy link
Contributor

jamestrew commented Jan 14, 2024

Yeah this is actually reproducible without telescope. I'll create an issue with neovim and see if this is something that can be addressed upstream.

edit: actually nvm need to do some more exploring

@jamestrew
Copy link
Contributor

This looks to be fixed upstream via neovim/neovim#27033

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproducible Bug that can be reproduced.
Projects
None yet
Development

No branches or pull requests

4 participants