From 234bca8d90fa3284905c95da21cd5f7144d82e1c Mon Sep 17 00:00:00 2001 From: "stanislav.baranov" Date: Mon, 29 Aug 2022 23:21:02 +0400 Subject: [PATCH] Fixes #28. Fixes Alt+Enter. Fixes Alt+Enter for hotkeys and commands with placeholders. --- lua/cheatsheet/telescope/actions.lua | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lua/cheatsheet/telescope/actions.lua b/lua/cheatsheet/telescope/actions.lua index c30fb95..bf2ffb5 100644 --- a/lua/cheatsheet/telescope/actions.lua +++ b/lua/cheatsheet/telescope/actions.lua @@ -11,22 +11,28 @@ local function select_current_item(prompt_bufnr, execute) t_actions.close(prompt_bufnr) - if string.len(cheat) == 1 then + if string.len(cheat) == 0 then print("Cheatsheet: No command could be executed") return end - -- Extract command from cheat, eg: - -- ":%bdelete" -> No change - -- ":set hls!" -> No change - -- ":edit [file]" -> ":edit " - -- ":set shiftwidth={n}" -> ":set shiftwidth=" - local command = cheat:match("^:[^%[%{]+") - if command ~= nil then - if execute then - vim.api.nvim_command(cheat) + if execute then + if cheat:find(":") then + -- Extract command from cheat, eg: + -- ":%bdelete" -> No change + -- ":set hls!" -> No change + -- ":edit [file]" -> ":edit " + -- ":set shiftwidth={n}" -> ":set shiftwidth=" + local command = cheat:match("^:[^%[%{]+") + if command == cheat then + vim.api.nvim_command(cheat) + else + vim.api.nvim_feedkeys(command, "n", true) + end else - vim.api.nvim_feedkeys(command, "n", true) + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes(cheat, true, true, true) + , "x", false) end else vim.api.nvim_echo(