Skip to content

Commit 8619dee

Browse files
authored
Merge pull request #157 from vim-denops/fix-reconnect
🐛 Fix `buffer` module on reconnection
2 parents 80825fb + 6e1b704 commit 8619dee

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

denops_std/buffer/buffer.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,45 @@ async function ensurePrerequisites(denops: Denops): Promise<string> {
8787
endfunction
8888
8989
function! DenopsStdBufferConcreteRestore_${suffix}() abort
90-
if !exists('b:denops_std_buffer_concrete_cache_${suffix}')
90+
let cache = get(s:denops_std_buffer_concrete_cache_${suffix}, bufnr(), v:null)
91+
if cache is# v:null
9192
return
9293
endif
9394
call DenopsStdBufferReplace_${suffix}(
9495
\\ bufnr('%'),
95-
\\ b:denops_std_buffer_concrete_cache_${suffix}.content,
96+
\\ cache.content,
9697
\\ v:null,
9798
\\ v:null,
9899
\\)
99-
let &filetype = b:denops_std_buffer_concrete_cache_${suffix}.filetype
100+
let &filetype = cache.filetype
100101
endfunction
101102
102103
function! DenopsStdBufferConcreteStore_${suffix}() abort
103-
let b:denops_std_buffer_concrete_cache_${suffix} = {
104+
let s:denops_std_buffer_concrete_cache_${suffix}[bufnr()] = {
104105
\\ 'filetype': &filetype,
105106
\\ 'content': getline(1, '$'),
106107
\\}
107108
endfunction
109+
110+
let s:denops_std_buffer_concrete_cache_${suffix} = {}
111+
112+
augroup denops_std_buffer_${suffix}
113+
autocmd!
114+
autocmd User DenopsStopped,DenopsClosed ++once
115+
\\ silent! unlet! s:denops_std_buffer_concrete_cache_${suffix}
116+
autocmd User DenopsStopped,DenopsClosed ++once
117+
\\ augroup denops_std_buffer_reload_${suffix} |
118+
\\ autocmd! |
119+
\\ augroup END
120+
autocmd User DenopsStopped,DenopsClosed ++once
121+
\\ augroup denops_std_buffer_concrete_${suffix} |
122+
\\ autocmd! |
123+
\\ augroup END
124+
autocmd User DenopsStopped,DenopsClosed ++once
125+
\\ augroup denops_std_buffer_${suffix} |
126+
\\ autocmd! |
127+
\\ augroup END
128+
augroup END
108129
`;
109130
await execute(denops, script);
110131
return suffix;

0 commit comments

Comments
 (0)