Merge pull request #2 from JimboKearn/fix-gotobuffer

Fix gotobuffer
This commit is contained in:
ThePrimeagen 2020-11-13 07:26:38 -08:00 committed by GitHub
commit 346e271800
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,7 @@ fun! GotoBuffer(ctrlId)
let contents = g:win_ctrl_buf_list[a:ctrlId] let contents = g:win_ctrl_buf_list[a:ctrlId]
if type(l:contents) != v:t_list if type(l:contents) != v:t_list
" Create the terminal " Create the terminal
terminal exe has("nvim") ? "terminal" : "terminal ++curwin"
call SetBuffer(a:ctrlId) call SetBuffer(a:ctrlId)
end end
let contents = g:win_ctrl_buf_list[a:ctrlId] let contents = g:win_ctrl_buf_list[a:ctrlId]
@ -21,11 +21,19 @@ fun! GotoBuffer(ctrlId)
end end
let bufh = l:contents[1] let bufh = l:contents[1]
call nvim_win_set_buf(0, l:bufh) if !bufexists(bufh)
" Create the terminal
exe has("nvim") ? "terminal" : "terminal ++curwin"
call SetBuffer(a:ctrlId)
endif
let contents = g:win_ctrl_buf_list[a:ctrlId]
let bufh = l:contents[1]
exe "b" . l:bufh
endfun endfun
fun! SetBuffer(ctrlId) fun! SetBuffer(ctrlId)
if has_key(b:, "terminal_job_id") == 0 if &buftype != "terminal"
echo "You must be in a terminal to execute this command" echo "You must be in a terminal to execute this command"
return return
end end
@ -34,7 +42,7 @@ fun! SetBuffer(ctrlId)
return return
end end
let g:win_ctrl_buf_list[a:ctrlId] = [b:terminal_job_id, nvim_win_get_buf(0)] let g:win_ctrl_buf_list[a:ctrlId] = [has_key(b:, "terminal_job_id") ? b:terminal_job_id : 0, bufnr()]
endfun endfun
fun! SendTerminalCommand(ctrlId, command) fun! SendTerminalCommand(ctrlId, command)
@ -52,10 +60,11 @@ fun! SendTerminalCommand(ctrlId, command)
echo "Unable to send command to terminal" echo "Unable to send command to terminal"
end end
let job_id = l:contents[0] if has("nvim")
call chansend(l:job_id, a:command) let job_id = l:contents[0]
call chansend(l:job_id, a:command)
else
let bufh = l:contents[1]
call term_sendkeys(l:bufh, a:command)
endif
endfun endfun