Prevent errors from undefined s:previous_context (#251)

Prevent errors processing textchanged that don't come from insert mode.

When using asyncomplete with vim-ripple, I get these errors:

    Error detected while processing TextChangedI Autocommands for "*"..function <SNR>43_on_text_changed_i[1]..<SNR>43_maybe_notify_on_change:
    line   15:
    E121: Undefined variable: s:previous_context

    Error detected while processing InsertLeave Autocommands for "*"..function <SNR>43_on_insert_leave:
    line    1:
    E108: No such variable: "s:previous_context"

ripple uses :startinsert, but I can't replicate the error with just that
command. Not sure what's wrong, but this seems like a reasonable fix.

Plugins
=======
    asyncomplete
    ripple

Repro
=====
Hit CR when on a blank line:
    gvim +"RippleCreate lua"
    down arrow
    CR
This commit is contained in:
David Briscoe
2021-05-04 00:31:43 -07:00
committed by GitHub
parent dffee28005
commit aa5ceb02d4

View File

@@ -41,7 +41,7 @@ function! s:on_insert_enter() abort
endfunction
function! s:on_insert_leave() abort
unlet s:previous_context
unlet! s:previous_context
endfunction
function! s:on_text_changed_i() abort
@@ -53,6 +53,9 @@ function! s:on_text_changed_p() abort
endfunction
function! s:maybe_notify_on_change() abort
if !exists('s:previous_context')
return
endif
" We notify on_change callbacks only when the cursor position
" has changed.
" Unfortunatelly we need this check because in insert mode it