@@ -52,18 +52,27 @@ private void TabListView_SelectionChanged(object sender, SelectionChangedEventAr
5252 }
5353
5454 private void CloseTabButton_Click ( object sender , RoutedEventArgs e )
55+ {
56+ var button = ( Button ) sender ;
57+ var tab = ( Tab ) button . DataContext ;
58+ CloseTab ( tab ) ;
59+ }
60+
61+ private void CloseTab ( Tab tab )
5562 {
5663 if ( MainViewModel . MainVM . Tabs . Count > 1 )
5764 {
58- var button = ( Button ) sender ;
59- var tab = ( Tab ) button . DataContext ;
6065 int index = MainViewModel . MainVM . Tabs . IndexOf ( tab ) ;
6166 tab . WebContentInstance . WebContentControl . Close ( ) ;
6267 tab . WebContentInstance = null ;
6368 if ( index == 0 )
69+ {
6470 TabListView . SelectedIndex = 1 ;
71+ }
6572 else
66- TabListView . SelectedIndex = MainViewModel . MainVM . Tabs . Count - 2 ;
73+ {
74+ TabListView . SelectedIndex = index - 1 ;
75+ }
6776 MainViewModel . MainVM . Tabs . Remove ( tab ) ;
6877 }
6978 else
@@ -72,6 +81,7 @@ private void CloseTabButton_Click(object sender, RoutedEventArgs e)
7281 }
7382 }
7483
84+
7585 private Tab _selectedTab ;
7686
7787 public Tab SelectedTab
@@ -144,26 +154,10 @@ private void Grid_PointerPressed(object sender, PointerRoutedEventArgs e)
144154 var pointer = e . GetCurrentPoint ( sender as Grid ) ;
145155 if ( pointer . Properties . IsMiddleButtonPressed )
146156 {
147- if ( MainViewModel . MainVM . Tabs . Count > 1 )
148- {
149- var button = ( Grid ) sender ;
150- var tab = ( Tab ) button . DataContext ;
151- int index = MainViewModel . MainVM . Tabs . IndexOf ( tab ) ;
152- tab . WebContentInstance . WebContentControl . Close ( ) ;
153- tab . WebContentInstance = null ;
154- if ( index == 0 )
155- TabListView . SelectedIndex = 1 ;
156- else
157- TabListView . SelectedIndex = MainViewModel . MainVM . Tabs . Count - 2 ;
158- MainViewModel . MainVM . Tabs . Remove ( tab ) ;
159- }
160- else
161- {
162- WindowHelper . CloseMainWindow ( ) ;
163- }
157+ var button = ( Grid ) sender ;
158+ var tab = ( Tab ) button . DataContext ;
159+ CloseTab ( tab ) ;
164160 }
165-
166-
167161 }
168162
169163 Tab CTXSelectedTab ;
0 commit comments