From 84fc2454384c1f65e58060f75b81456d4d40dee2 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 11 Nov 2020 13:06:05 -0500 Subject: [PATCH] Return early from Finish functions when buffer is not displayed When bufwinnr() returns -1, the buffer isn't currently displayed. In this case, we need to return so the contents of a different buffer aren't used for recipients/options. --- autoload/gnupg.vim | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/autoload/gnupg.vim b/autoload/gnupg.vim index c35661a..2dae193 100644 --- a/autoload/gnupg.vim +++ b/autoload/gnupg.vim @@ -769,8 +769,14 @@ function s:GPGFinishRecipientsBuffer() " go to buffer before doing work if (bufnr("%") != expand("")) - " switch to scratch buffer window - execute 'silent! ' . bufwinnr(expand(":p")) . "wincmd w" + let winnr = bufwinnr(expand(':p')) + if winnr >= 0 + " switch to scratch buffer window + execute 'silent! ' . winnr . "wincmd w" + else + call s:GPGDebug(3, '<<<<<<<< Leaving s:GPGFinishRecipientsBuffer() early because buffer is not displayed') + return + endif endif " get the recipients from the scratch buffer @@ -915,8 +921,14 @@ function s:GPGFinishOptionsBuffer() " go to buffer before doing work if (bufnr("%") != expand("")) - " switch to scratch buffer window - execute 'silent! ' . bufwinnr(expand(":p")) . "wincmd w" + let winnr = bufwinnr(expand(':p')) + if winnr >= 0 + " switch to scratch buffer window + execute 'silent! ' . winnr . "wincmd w" + else + call s:GPGDebug(3, '<<<<<<<< Leaving s:GPGFinishOptionsBuffer() early because buffer is not displayed') + return + endif endif " clear options and unknownOptions