Skip to content

Commit

Permalink
fix: cursor behavior on link insertion (#48)
Browse files Browse the repository at this point in the history
- use `feedkeys` with mode "n" instead of "t" -> more robust against
  user remaps
- only go into insert mode when executed from insert mode
- make `put` behave like `p` and not `P`
  • Loading branch information
taeruh authored Apr 4, 2024
1 parent 418f8fd commit 2fb1177
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lua/telescope/_extensions/neorg/insert_file_link.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ end

return function(opts)
opts = opts or {}
local mode = vim.api.nvim_get_mode().mode

pickers
.new(opts, {
Expand Down Expand Up @@ -110,8 +111,10 @@ return function(opts)

vim.api.nvim_put({
"{" .. ":$" .. entry.relative .. ":" .. "}" .. "[" .. (entry.title or file_name) .. "]",
}, "c", false, true)
vim.api.nvim_feedkeys("hf]a", "t", false)
}, "c", true, true)
if mode == "i" then
vim.api.nvim_feedkeys("a", "n", false)
end
end)
return true
end,
Expand Down
9 changes: 6 additions & 3 deletions lua/telescope/_extensions/neorg/insert_link.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ end
return function(opts)
opts = opts or {}
local links = generate_links()
local mode = vim.api.nvim_get_mode().mode

pickers
.new(opts, {
Expand Down Expand Up @@ -158,16 +159,18 @@ return function(opts)
"[%*#%|_]",
"\\%1"
) .. "}" .. "[" .. entry.linkable:gsub(":$", "") .. "]",
}, "c", false, true)
}, "c", true, true)
else
vim.api.nvim_put({
"{" .. inserted_file .. entry.ordinal:gsub("^(%W+)%s+.+", "%1 ") .. entry.linkable:gsub(
"[%*#%|_]",
"\\%1"
) .. "}",
}, "c", false, true)
}, "c", true, true)
end
if mode == "i" then
vim.api.nvim_feedkeys("a", "n", false)
end
vim.api.nvim_feedkeys("hf]a", "t", false)
end)
return true
end,
Expand Down

0 comments on commit 2fb1177

Please sign in to comment.