Don't base pane validity on count
This introduced an implicit dependency on zero-based pane indexing. This code now checks that the desired pane is one of the current pane indexes. Closes #42 - Off by one error in runner_pane with base-index 1 in tmux
This commit is contained in:
parent
d56939fa94
commit
8d064375e5
@ -95,7 +95,7 @@ function! s:KillRunnerPane()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ActivePaneIndex()
|
function! s:ActivePaneIndex()
|
||||||
return s:SendTmuxCommand("display-message -p \"#{pane_index}\"")
|
return str2nr(s:SendTmuxCommand("display-message -p \"#{pane_index}\""))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:TmuxPanes()
|
function! s:TmuxPanes()
|
||||||
@ -229,7 +229,7 @@ function! s:PromptForRunnerToAttach()
|
|||||||
endif
|
endif
|
||||||
echohl String | let desired_pane = input('Pane #: ') | echohl None
|
echohl String | let desired_pane = input('Pane #: ') | echohl None
|
||||||
if desired_pane != ''
|
if desired_pane != ''
|
||||||
call s:AttachToPane(str2nr(desired_pane))
|
call s:AttachToPane(desired_pane)
|
||||||
else
|
else
|
||||||
call s:EchoError("No pane specified. Cancelling.")
|
call s:EchoError("No pane specified. Cancelling.")
|
||||||
endif
|
endif
|
||||||
@ -244,13 +244,14 @@ function! s:CurrentMajorOrientation()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:AttachToPane(desired_pane)
|
function! s:AttachToPane(desired_pane)
|
||||||
if s:ValidRunnerPaneNumber(a:desired_pane)
|
let desired_pane = str2nr(a:desired_pane)
|
||||||
let s:runner_pane = a:desired_pane
|
if s:ValidRunnerPaneNumber(desired_pane)
|
||||||
|
let s:runner_pane = desired_pane
|
||||||
let s:vim_pane = s:ActivePaneIndex()
|
let s:vim_pane = s:ActivePaneIndex()
|
||||||
let s:vtr_orientation = s:CurrentMajorOrientation()
|
let s:vtr_orientation = s:CurrentMajorOrientation()
|
||||||
echohl String | echo "\rRunner pane set to: " . a:desired_pane | echohl None
|
echohl String | echo "\rRunner pane set to: " . desired_pane | echohl None
|
||||||
else
|
else
|
||||||
call s:EchoError("Invalid pane number: " . a:desired_pane)
|
call s:EchoError("Invalid pane number: " . desired_pane)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -258,9 +259,13 @@ function! s:EchoError(message)
|
|||||||
echohl ErrorMsg | echo "\rVTR: ". a:message | echohl None
|
echohl ErrorMsg | echo "\rVTR: ". a:message | echohl None
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:DesiredPaneExists(desired_pane)
|
||||||
|
return count(s:PaneIndices(), a:desired_pane) == 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:ValidRunnerPaneNumber(desired_pane)
|
function! s:ValidRunnerPaneNumber(desired_pane)
|
||||||
if a:desired_pane == s:ActivePaneIndex() | return 0 | endif
|
if a:desired_pane == s:ActivePaneIndex() | return 0 | endif
|
||||||
if a:desired_pane > (s:PaneCount() - 1) | return 0 | endif
|
if s:DesiredPaneExists(a:desired_pane) | return 0 | endif
|
||||||
return 1
|
return 1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user