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]
if type(l:contents) != v:t_list
" Create the terminal
terminal
exe has("nvim") ? "terminal" : "terminal ++curwin"
call SetBuffer(a:ctrlId)
end
let contents = g:win_ctrl_buf_list[a:ctrlId]
@ -21,11 +21,19 @@ fun! GotoBuffer(ctrlId)
end
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
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"
return
end
@ -34,7 +42,7 @@ fun! SetBuffer(ctrlId)
return
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
fun! SendTerminalCommand(ctrlId, command)
@ -52,10 +60,11 @@ fun! SendTerminalCommand(ctrlId, command)
echo "Unable to send command to terminal"
end
let job_id = l:contents[0]
call chansend(l:job_id, a:command)
if has("nvim")
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