Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Focus loss in glow #73

Closed
Mykhailo-Sichkaruk opened this issue Jan 29, 2024 · 5 comments · Fixed by AstroNvim/astrocommunity#921
Closed

Focus loss in glow #73

Mykhailo-Sichkaruk opened this issue Jan 29, 2024 · 5 comments · Fixed by AstroNvim/astrocommunity#921

Comments

@Mykhailo-Sichkaruk
Copy link

I have an issue with opened docs via glow. When I select some docs to be opened my neovim loses focus and I simply can't do anything with my keyboard in the neovim window. I need to click with my mouse over neovim to be able to navigate with the keyboard. Here are my settings:

{
    "luckasRanarison/nvim-devdocs",
    dependencies = {
      "nvim-lua/plenary.nvim", "nvim-telescope/telescope.nvim",
      "nvim-treesitter/nvim-treesitter"
    },
    lazy = false,
    enable = true,
    opts = {
      dir_path = vim.fn.stdpath("data") .. "/devdocs", -- installation directory
      telescope = {}, -- passed to the telescope picker
      filetypes = {},
      float_win = { -- passed to nvim_open_win(), see :h api-floatwin
        relative = "editor",
        height = 500,
        width = 800,
        border = "rounded"
      },
      wrap = true, -- text wrap, only applies to floating window
      previewer_cmd = "glow", -- for example: "glow"
      cmd_args = { "-w", "80", "-s", "dark", "-p" },
      cmd_ignore = {}, -- ignore cmd rendering for the listed docs
      picker_cmd = true, -- use cmd previewer in picker preview
      picker_cmd_args = { "-w", "80", "-s", "dark", "-p" },
      ensure_installed = {
        "node", "javascript", "typescript", "npm", "sass", "css", "html",
        "lua-5.4", "cpp", "go", "python-3.12", "jsdoc", "git"
      }, -- get automatically installed
      mappings = { open_in_browser = "" },
      after_open = function(bufnr) end -- callback that runs after the Devdocs window is opened. Devdocs buffer ID will be passed in
    }
  }

What am I doing wrong?

My setup:
nvim: 0.9.5
fedora: 38
alacritty: 0.13.1
X11

@Mykhailo-Sichkaruk
Copy link
Author

Sorry my bad, it was terminal mode and Ctrl+\ and then Ctrl+n fix the issue).

I was struggling with the settings of the plugins and other stuff but it was so easy.

@gipo355
Copy link

gipo355 commented Feb 4, 2024

hey @Mykhailo-Sichkaruk having the same problem, do we need to press ctrl+\ and ctrl+n everytime we open it or is there a persistent solution

@Mykhailo-Sichkaruk
Copy link
Author

hey @Mykhailo-Sichkaruk having the same problem, do we need to press ctrl+\ and ctrl+n everytime we open it or is there a persistent solution

As I understood Terminal mode is a feature of the nvim, not a bug. For example, you can try :terminal command in your nvim and you will get into terminal where you can write shell commands as usual while normal nvim's motions and commands line w,e,d,i won't work. Nvim's commands/motions won't work because all input is redirected to the shell. Then you can press Ctrl + \ Ctrl + n and you will be in the nvim's Normal mode.

So, a workaround I see - adding a more convenient shortcut to exit Terminal mode. I use: Map('t', '<A-a>', '<C-\\><C-n>')

@RayJameson
Copy link

RayJameson commented Apr 19, 2024

If someone else stumble across this issue, the workaround is to use after_open in config options

---@type LazySpec
return {
  "luckasRanarison/nvim-devdocs",
  cond = not vim.g.vscode,
  dependencies = {
    "nvim-lua/plenary.nvim",
    "nvim-telescope/telescope.nvim",
    "nvim-treesitter/nvim-treesitter",
  },
  cmd = {
    "DevdocsFetch",
    "DevdocsInstall",
    "DevdocsUninstall",
    "DevdocsOpen",
    "DevdocsOpenCurrent",
    "DevdocsOpenFloat",
    "DevdocsUpdate",
    "DevdocsUpdateAll",
    "DevdocsOpenCurrentFloat",
  },
  keys = {
    {
      "<leader>fd",
      function()
        if vim.bo.ft == "python" then
          local check_version_cmd = [[python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))']]
          local python_version = "python-" .. vim.fn.system(check_version_cmd)
          local cmd = ("DevdocsOpenFloat %s"):format(python_version)
          vim.cmd(cmd)
        else
          vim.cmd("DevdocsOpenCurrentFloat")
        end
      end,
      desc = "Find Devdocs for current ft",
      mode = { "n" },
    },
    { "<leader>fD", "<cmd>DevdocsOpenFloat<CR>", desc = "Find Devdocs", mode = { "n" } },
  },
  opts = {
    previewer_cmd = vim.fn.executable("glow") == 1 and "glow" or nil,
    cmd_args = { "-s", "dark", "-w", "80" },
    picker_cmd = true,
    picker_cmd_args = { "-s", "dark", "-w", "50" },
    float_win = { -- passed to nvim_open_win(), see :h api-floatwin
      relative = "editor",
      height = 35,
      width = 125,
      border = "rounded",
    },
    after_open = function()
      vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-\\><C-n>", true, false, true), "n", true)
    end,
  },
}

@gipo355
Copy link

gipo355 commented Apr 19, 2024

Thank you @RayJameson !!! copypasted this right away

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants