diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-02 09:23:40 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-02 09:23:40 +0200 |
commit | 97f7bb2ea488e62df31b43c50bbfb0eaf5d63422 (patch) | |
tree | 5258bca3e59e1d4dd8961a80557d3dfb62bee0fb /ui/tunnelspage.go | |
parent | ui: add multiple tunnel deletion (diff) | |
download | wireguard-windows-97f7bb2ea488e62df31b43c50bbfb0eaf5d63422.tar.xz wireguard-windows-97f7bb2ea488e62df31b43c50bbfb0eaf5d63422.zip |
ui: select closest tunnel after deletion
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/tunnelspage.go')
-rw-r--r-- | ui/tunnelspage.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ui/tunnelspage.go b/ui/tunnelspage.go index bf80107d..33b2c03e 100644 --- a/ui/tunnelspage.go +++ b/ui/tunnelspage.go @@ -394,9 +394,27 @@ func (tp *TunnelsPage) onDelete() { walk.MsgBoxYesNo|walk.MsgBoxIconWarning) { return } + + selectTunnelAfter := "" + if len(indices) < len(tp.tunnelsView.model.tunnels) { + sort.Ints(indices) + max := 0 + for i, idx := range indices { + if idx+1 < len(tp.tunnelsView.model.tunnels) && (i+1 == len(indices) || idx+1 != indices[i+1]) { + max = idx + 1 + } else if idx-1 >= 0 && (i == 0 || idx-1 != indices[i-1]) { + max = idx - 1 + } + } + selectTunnelAfter = tp.tunnelsView.model.tunnels[max].Name + } + for _, i := range indices { tp.deleteTunnel(&tp.tunnelsView.model.tunnels[i]) } + if len(selectTunnelAfter) > 0 { + tp.tunnelsView.selectTunnel(selectTunnelAfter) + } } func (tp *TunnelsPage) onImport() { |