nvim-telekasten / telekasten.nvim

A Neovim (lua) plugin for working with a markdown zettelkasten / wiki and mixing it with a journal, based on telescope.nvim
MIT License
1.37k stars 86 forks source link

[BUG] insert link yields weird cursor behaviour #147

Closed qwertzui11 closed 1 year ago

qwertzui11 commented 2 years ago

Please confirm

Describe the bug

When I enter insert mode, and then call telekasten.insert_link() it's getting inserted after the cursor. eg. abc<cursor>def --> insert --> becomes abcd[[link]]<cursor>ef. However in my opinion it should become abc[[link]]<cursor>def. That would be the same behaviour eg like when pressing C-r to insert from a register.

when I use telekasten.insert_link({i=true}) the link gets added on the wrong position too AND the cursor jumps to the end of the line.

https://asciinema.org/a/X2wNICpkOyVJiL8ZphSAm1Yqu

Operating system (please complete the following information):

Additional context

my neovim config

local use = require('packer').use
require('packer').startup(function()
  use 'wbthomason/packer.nvim'
  use {'nvim-telescope/telescope.nvim', requires = {{'nvim-lua/plenary.nvim'}} }
  use 'renerocksai/telekasten.nvim'
end)

local telescope = require('telescope')
telescope.setup()

-- https://github.com/renerocksai/telekasten.nvim#0-install-and-setup
local telekasten = require('telekasten')
local home = vim.fn.expand("~/zettelkasten")
telekasten.setup()

-- https://github.com/renerocksai/telekasten.nvim#3-bind-it
vim.keymap.set('n', '<leader>zf', telekasten.find_notes)
vim.keymap.set('n', '<leader>zz', telekasten.panel)
vim.keymap.set('n', '<leader>zp', telekasten.search_notes)
vim.keymap.set('n', '<leader>zg', telekasten.follow_link)
vim.keymap.set('n', '<leader>zn', telekasten.new_note)
vim.keymap.set('n', '<leader>zr', telekasten.rename_note)
vim.keymap.set('n', '<leader>zt', telekasten.show_tags)

local insert_link = function ()
  -- telekasten.insert_link({i=true})
  telekasten.insert_link()
end
vim.keymap.set('i', '<leader>zl', insert_link)
vim.keymap.set('n', '<leader>zl', insert_link)
lambtho12 commented 2 years ago

I cannot reproduce on my setup. When I insert a link it inserts at the cursor position as expected. abc|def -> abc[[mylink]]def

Can someone test that?


If I have i=true it jumps at the end of the line indeed, this is expected.

Now that you mention it, we should instead always jump after the link rather than directly at the end of the line. I think that the jump to the end of the line was made for when you are pasting the link as you write, so it effectively goes after the link. But this is not really useful when editing a pre-existing sentence.

qwertzui11 commented 2 years ago

I cannot reproduce on my setup. When I insert a link it inserts at the cursor position as expected. abc|def -> abc[[mylink]]def

that's weird. I was afraid, that it's difficult to reproduce. That's why I did a minimal init.lua. hm. You did test the nvim tag version 0.7.0?

lambtho12 commented 2 years ago

Yes. I am using nvim 0.7.0

I will try using a minimal init.lua as well when I have some time.