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

When the marks are deleted, <Tab> will jump to the deleted mark. #303

Closed
vinoff opened this issue Oct 9, 2021 · 3 comments
Closed

When the marks are deleted, <Tab> will jump to the deleted mark. #303

vinoff opened this issue Oct 9, 2021 · 3 comments

Comments

@vinoff
Copy link

vinoff commented Oct 9, 2021

Say you are on a .py file and you trigger a 'For' snippet. You immediately deleted the snippet and then you press Tab. You will be jumped to the deleted mark for the For snippet. This, of course, when you have tab setup to jump marks.

As far as I remember, before the "breaking changes", this did not happen.

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 9, 2021

Please minimal repro.

@hrsh7th hrsh7th closed this as completed Oct 9, 2021
@vinoff
Copy link
Author

vinoff commented Oct 9, 2021

repro? you mean config? Here is my cmp config:

local has_words_before = function()
  local line, col = unpack(vim.api.nvim_win_get_cursor(0))
  return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end

local luasnip = require("luasnip")
local cmp = require("cmp")

cmp.setup({

  -- ... Your other configuration ...
    snippet = {
        expand = function(args)
            require("luasnip").lsp_expand(args.body)
        end,
    },

  mapping = {

    -- ... Your other mappings ...

    ["<Tab>"] = cmp.mapping(function(fallback)
      if luasnip.expand_or_jumpable() then
        luasnip.expand_or_jump()
      -- elseif vim.fn.pumvisible() == 1 then
      --   feedkey("<C-n>")
      elseif cmp.visible() then
        cmp.select_next_item()
      elseif has_words_before() then
        cmp.complete()
      else
        fallback()
      end
    end, { "i", "s" }),

    ["<S-Tab>"] = cmp.mapping(function(fallback)
      if cmp.visible() then
        cmp.select_prev_item()
      elseif luasnip.jumpable(-1) then
        luasnip.jump(-1)
      else
        fallback()
      end
    end, { "i", "s" }),

    -- ... Your other mappings ...
  },

  sources = {
    { name = "luasnip" },
    { name = "nvim_lsp" },
    { name = "buffer" },
    { name = "path" },
  },
  -- ... Your other configuration ...
})

If "repro" means reproduction, here it is.

  1. Open .py file, say test.py;
  2. Type "for" and press tab to expand snippet;
  3. After snippet is expanded, select the whole snippet (using visual mode) and delete it;
  4. Go into insert mode and press tab;
  5. Cursor jumps into the next (invisible) mark, that was deleted previously;

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 9, 2021

Your <Tab> mapping checks luasnip.expand_or_jumpable() so it seems LuaSnip problem to me.

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

No branches or pull requests

2 participants