rasulomaroff / reactive.nvim

Reactivity. Right in your neovim.
Apache License 2.0
183 stars 1 forks source link

Telescope picker opens files in insert mode when using reactive.nvim #17 #5

Open ImmanuelHaffner opened 7 months ago

ImmanuelHaffner commented 7 months ago

Error Description

When using Telescope together with reactive.nvim plugin, opening files from the picker immediately enters insert mode.

X-posted in Telescope

Potentially Related Issues

My reactive config

return {
    { 'rasulomaroff/reactive.nvim',
        config = function()
            local reactive = require'reactive'
            reactive.add_preset{
                name = 'default',
                init = function()
                    -- making our cursor to use `MyCursor` highlight group
                    vim.opt.guicursor:append('a:MyCursor')
                    vim.opt.cursorline = true

                    -- Configure colors of cursorline and colorcolumn
                    vim.cmd[[
                    hi! ColorColumn guifg=Red guibg='#380000'
                    hi! CursorLine guibg=#021020
                    hi! CursorLineNr gui=bold
                    ]]
                end,
                lazy = false,
                priority = 100,
                modes = {
                    n = {
                        winhl = {
                            -- we use `winhl` because we want to highlight CursorLine only in a current window, not in all of them
                            -- if you want to change global highlights, use the `hl` field instead.
                            CursorLine = { bg = '#102947' },
                            CursorLineNr = { fg = '#0b1d33', bg = '#98c379' },
                        },
                    },
                    no = {
                        -- You can also specify winhl and hl that will be applied with every operator
                        winhl = {},
                        hl = {},
                        operators = {
                            d = {
                                winhl = {
                                    CursorLine = { bg = '#450a0a' },
                                },
                                hl = {
                                    MyCursor = { bg = '#fca5a5' },
                                },
                            },
                            y = {
                                winhl = {
                                    CursorLine = { bg = '#422006' },
                                },
                                hl = {
                                    MyCursor = { bg = '#fdba74' },
                                }
                            }
                        }
                    },
                    i = {
                        winhl = {
                            CursorLine = { bg = '#0b1d33' },
                            CursorLineNr = { fg = '#0b1d33', bg = '#61afef' },
                        },
                        hl = {
                            MyCursor = { bg = '#ff6b6b' },
                        },
                    },
                    [{ 'v', 'V', '\x16' }] = {
                        winhl = {
                            CursorLineNr = { fg = '#0b1d33', bg = '#c678dd' },
                        },
                    },
                },
            }
        end,
    }
}
rasulomaroff commented 7 months ago

Hi there! Do you mean it enters file in insert mode or highlights it as insert one, but actually in normal mode? Because if it's the first one, I don't really know how it can be possible as I don't use nvim_feedkeys or :startinsert to actually change mode, but I'll recheck the codebase again.

Did you see this comment in that issue? Can you please try this autocommand? https://github.com/nvim-telescope/telescope.nvim/issues/2027#issuecomment-1561836585

ImmanuelHaffner commented 7 months ago

Hey @rasulomaroff , thanks for the quick response. I meant it enters insert mode. I did already see the comment you linked and I am using that workaround. Still, I wanted to raise awareness for that issue.

Could it be that you are clearing some augroup that Telescope is using? Just a wild guess. I don't know your or Telescope code base.

rasulomaroff commented 7 months ago

Hmm, don't think so

The only place where I could possibly lose third-party highlights is the "winhl" option, but I save all the previous window highlights before applying mine and then apply them together.

You don't have troubles with highlights themselves, right? Or do you?

You pointed that your problem is that Telescope enters insert mode, so, I would wait for their clarification, 'cause as I said I don't manipulate modes at any level.

ImmanuelHaffner commented 7 months ago

Highlights are not affected. Sure, let's see what Telescope folks have to say. So far, they say it may be because of a nvim issue that has already been fixed upstream. I don't run nightly, though. Might give it a shot to see if it fixes things.

thelinmichael commented 6 months ago

Unsure if related, but seems so. With reactive enabled, the third buffer opened through telescope consistently opens in insert mode.

nvim-telescope on tag 0.1.5, reactive on tag 1.2.0

Seems to be fixed by https://github.com/neovim/neovim/pull/27051. When building neovim on commit 2fce95ec4 or later (i.e. NVIM v0.10.0-dev-2110+g2fce95ec4 I can't reproduce the issue anymore.

reactive config:

  {
    "rasulomaroff/reactive.nvim",
    config = function()
      require("reactive").setup({
        builtin = {
          cursor = true,
        },
      })
    end,
  },

Also fixed by adding https://github.com/nvim-telescope/telescope.nvim/issues/2501#issuecomment-1561838990 when running older versions of neovim:

-- Quickfix for this issue https://github.com/nvim-telescope/telescope.nvim/issues/2501
api.nvim_create_augroup('my_telescope', { clear = true })
api.nvim_create_autocmd({ 'WinLeave' }, {
  group = 'my_telescope',
  pattern = '*',
  callback = function()
    if vim.bo.ft == "TelescopePrompt" and fn.mode() == "i" then
            api.nvim_feedkeys(api.nvim_replace_termcodes("<Esc>", true, false, true), "i", false)
        end
  end,
})
rasulomaroff commented 6 months ago

@thelinmichael just tested on my machine and there's no such a problem.. Seems a bit crazy for me because I don't really know how I can trigger insert mode without firing something like :startinsert or other methods

thelinmichael commented 6 months ago

@thelinmichael just tested on my machine and there's no such a problem.. Seems a bit crazy for me because I don't really know how I can trigger insert mode without firing something like :startinsert or other methods

Hm, I suppose the change to insert mode is done by TelescopePrompt.

infinite-ops commented 4 months ago

I think I have the same issue, but its not really insert mode it just looks like it. With reactive enabled, using telescope to find a file and open, status line shows mode as insert, but its not actually... its still in normal mode but it displays as insert. Disabling reactive, it does not do this and reflects the mode correctly.

ahh I think mine is how I'm getting the mode in heirline, changing from heirline to mini.statusline as a quick test, the issue goes away.

In my particular case it seems to be this in heirline which causes it when reactive is enabled. Removing this update makes the issue stop presenting and it looks to still behave as expected (heirline).

  update = {
    "ModeChanged",
    pattern = "*:*",
    callback = vim.schedule_wrap(function()
      vim.cmd "redrawstatus"
    end),
  },

Perhaps this might give some clues to help solve this issue

rasulomaroff commented 4 months ago

@infinite-ops hi there! As far as I know the issue was fixed in the upstream Neovim. It wasn't reactive issue because the only thing that reactive does is updates highlights when a mode changes and redraws pending screen updates. From the latest commit pushed, it only does it when there's at least one highlight to update, but skips if there aren't.

Unfortunately, I see a lot of issues that are coming up when using those redraw and redrawstatus commands. May be something in the Neovim core...

xfzv commented 4 days ago

I'm using Neovim nightly and I do have the issue. https://github.com/nvim-telescope/telescope.nvim/issues/2501#issuecomment-1561838990 doesn't make any difference.

% nvim -v
NVIM v0.11.0-dev-632+g33464189b-dirty
Build type: Release
LuaJIT 2.1.1716656478
Run "nvim -V1 -v" for more info

My reactive.nvim config

return {
  "rasulomaroff/reactive.nvim",
  event = { "BufEnter", "WinEnter" },
  opts = {
    load = { "catppuccin-mocha-cursor", "catppuccin-mocha-cursorline" },
  },
}