Skip to content

Commit 7396ce3

Browse files
committed
refactor: launcher page switcher auto-selection (#1937)
Signed-off-by: leo <[email protected]>
1 parent e7bd7bb commit 7396ce3

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/ViewModels/LauncherPagesCommandPalette.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,69 @@ private void UpdateVisible()
9494
var repos = new List<RepositoryNode>();
9595
CollectVisibleRepository(repos, Preferences.Instance.RepositoryNodes);
9696

97+
var autoSelectPage = _selectedPage;
98+
var autoSelectRepo = _selectedRepo;
99+
100+
if (_selectedPage != null)
101+
{
102+
if (pages.Contains(_selectedPage))
103+
{
104+
// Keep selection
105+
}
106+
else if (pages.Count > 0)
107+
{
108+
autoSelectPage = pages[0];
109+
}
110+
else if (repos.Count > 0)
111+
{
112+
autoSelectPage = null;
113+
autoSelectRepo = repos[0];
114+
}
115+
else
116+
{
117+
autoSelectPage = null;
118+
}
119+
}
120+
else if (_selectedRepo != null)
121+
{
122+
if (repos.Contains(_selectedRepo))
123+
{
124+
// Keep selection
125+
}
126+
else if (repos.Count > 0)
127+
{
128+
autoSelectRepo = repos[0];
129+
}
130+
else if (pages.Count > 0)
131+
{
132+
autoSelectPage = pages[0];
133+
autoSelectRepo = null;
134+
}
135+
else
136+
{
137+
autoSelectRepo = null;
138+
}
139+
}
140+
else if (pages.Count > 0)
141+
{
142+
autoSelectPage = pages[0];
143+
autoSelectRepo = null;
144+
}
145+
else if (repos.Count > 0)
146+
{
147+
autoSelectPage = null;
148+
autoSelectRepo = repos[0];
149+
}
150+
else
151+
{
152+
autoSelectPage = null;
153+
autoSelectRepo = null;
154+
}
155+
97156
VisiblePages = pages;
98157
VisibleRepos = repos;
158+
SelectedPage = autoSelectPage;
159+
SelectedRepo = autoSelectRepo;
99160
}
100161

101162
private void CollectVisiblePages(List<LauncherPage> pages)

0 commit comments

Comments
 (0)