Skip to content

Commit

Permalink
fix(macros): put the bs at the start of the typeahead not the end of …
Browse files Browse the repository at this point in the history
…it (#53)

* fix(macros): put the bs at the start of the typeahead not the end of it

* fix(path): fix up the code path for clear_empty_lines

* refactor: properly fix clear_empty_lines

* doc: remove readme warning
  • Loading branch information
Sam-programs authored Jan 5, 2024
1 parent 2d75c37 commit d62cf3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
26 changes: 14 additions & 12 deletions lua/better_escape.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ end

---@param keys string keys to feed
--- Replace keys with termcodes and feed them
local function feed(keys)
local function feed(keys, mode)
api.nvim_feedkeys(
api.nvim_replace_termcodes(keys, true, true, true),
"n",
mode or "n",
false
)
end
Expand All @@ -65,15 +65,14 @@ end

local function check_timeout()
if waiting then
feed("<BS><BS>") -- delete the characters from the mapping
feed(get_keys())
if settings.clear_empty_lines then
local current_line = api.nvim_get_current_line()
if string.match(current_line, "^%s+j$") then
vim.schedule(function()
feed('0"_D')
end)
end
local current_line = api.nvim_get_current_line()
if settings.clear_empty_lines and current_line:match("^%s+j$") then
vim.schedule(function()
api.nvim_set_current_line("")
feed(get_keys(), "in")
end)
else
feed("<BS><BS>" .. get_keys(), "in") -- delete the characters from the mapping
end

waiting = false -- more timely
Expand Down Expand Up @@ -129,7 +128,10 @@ local function validate_settings()

if settings.timeout then
assert(type(settings.timeout) == "number", "Timeout must be a number.")
assert(settings.timeout >= 100, "Timeout must be greater than or equal to 100.")
assert(
settings.timeout >= 100,
"Timeout must be greater than or equal to 100."
)
end

assert(
Expand Down
4 changes: 0 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ This looks like this (see below for a gif):

## ✨Features

> [!Warning]
> There were some cases where macros using this plugin didn't work as expected.
> If you have issues with a macro you should use `<esc>` to exit insert mode instead.
- Escape without getting delay when typing in insert mode
- Customizable mapping and timeout
- Use multiple mappings
Expand Down

0 comments on commit d62cf3c

Please sign in to comment.