Skip to content

Commit

Permalink
Track typed char
Browse files Browse the repository at this point in the history
So that expansion isn't triggered by <BS>, for example.
  • Loading branch information
dcampos committed Jan 12, 2022
1 parent 9cbc1b8 commit 3c67072
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lua/snippy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ local function get_snippet_at_cursor(auto_trigger)
local current_line_to_col = api.nvim_get_current_line():sub(1, col):gsub('^%s*', '')

if current_line_to_col then
if auto_trigger and not (Snippy_last_char and vim.endswith(current_line_to_col, Snippy_last_char)) then
return nil, nil
end

local word = current_line_to_col:match('(%S*)$') -- Remove leading whitespace
local word_bound = true
local scopes = shared.get_scopes()
Expand Down Expand Up @@ -471,6 +475,7 @@ end

function M.expand(auto)
local word, snippet = get_snippet_at_cursor(auto)
Snippy_last_char = nil
if word and snippet then
return M.expand_snippet(snippet, word)
end
Expand Down Expand Up @@ -535,7 +540,8 @@ function M.read_snippets()
vim.cmd([[
augroup snippy_auto
autocmd!
autocmd TextChangedI,TextChangedP * lua require 'snippy'.expand(true)
autocmd TextChangedI * lua require 'snippy'.expand(true)
autocmd InsertCharPre * lua Snippy_last_char = vim.v.char
augroup END
]])
end
Expand Down

0 comments on commit 3c67072

Please sign in to comment.