Skip to content

Commit d54588f

Browse files
committed
Branch sidebar tree with Remote section; Alt+F12 toggles terminal; terminal + follows tabs
Local branches and every remote's branches are grouped into folders by their name prefix (feature/, hotfix/), PhpStorm style, with one node per remote under a Remote section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Faq4edqhkSFNm9LMD8KnUP
1 parent a0b965e commit d54588f

5 files changed

Lines changed: 210 additions & 101 deletions

File tree

‎flutter/lib/l10n/translations.dart‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ const Map<String, Map<String, String>> translations = {
149149
'editor_cursor_position': 'Ln {line}, Col {col}',
150150
'editor_select_file': 'Select a file from the project tree to start editing.',
151151
'branches_local': 'On this computer',
152-
'branches_only_on_remote': 'Only on {remote}',
153-
'branches_remote_hint': 'Double-click to get a local copy',
152+
'branches_remote': 'Remote',
154153
'branch_local_only': 'Only on this computer (not pushed)',
155154
'branch_on_remote': 'Also on {remote}',
156155
'branch_ahead': '{n} commits to push to {remote}',
@@ -588,8 +587,7 @@ const Map<String, Map<String, String>> translations = {
588587
'editor_cursor_position': 'سطر {line}، عمود {col}',
589588
'editor_select_file': 'اختر ملفًا من شجرة المشروع لبدء التحرير.',
590589
'branches_local': 'على هذا الحاسوب',
591-
'branches_only_on_remote': 'فقط على {remote}',
592-
'branches_remote_hint': 'انقر مرتين للحصول على نسخة محلية',
590+
'branches_remote': 'المستودعات البعيدة',
593591
'branch_local_only': 'على هذا الحاسوب فقط (غير مدفوع)',
594592
'branch_on_remote': 'موجود أيضًا على {remote}',
595593
'branch_ahead': '{n} إيداعات للدفع إلى {remote}',
@@ -1027,8 +1025,7 @@ const Map<String, Map<String, String>> translations = {
10271025
'editor_cursor_position': 'خط {line}، ستون {col}',
10281026
'editor_select_file': 'برای شروع ویرایش، فایلی را از درخت پروژه انتخاب کنید.',
10291027
'branches_local': 'روی این کامپیوتر',
1030-
'branches_only_on_remote': 'فقط روی {remote}',
1031-
'branches_remote_hint': 'برای گرفتن نسخه محلی دوبار کلیک کنید',
1028+
'branches_remote': 'ریموت',
10321029
'branch_local_only': 'فقط روی این کامپیوتر (push نشده)',
10331030
'branch_on_remote': 'روی {remote} هم هست',
10341031
'branch_ahead': '{n} کامیت برای push به {remote}',

‎flutter/lib/repo/branch_sidebar.dart‎

Lines changed: 172 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ class _BranchSidebarState extends State<BranchSidebar> {
160160

161161
bool _localExpanded = true;
162162
bool _remoteExpanded = true;
163+
164+
/// Folder and remote nodes the user collapsed, keyed by
165+
/// "local:feature", "remote:origin" or "remote:origin/feature".
166+
final Set<String> _collapsed = {};
163167
bool _isSearching = false;
164168
final TextEditingController _searchController = TextEditingController();
165169
String _searchQuery = '';
@@ -670,6 +674,48 @@ class _BranchSidebarState extends State<BranchSidebar> {
670674
return null;
671675
}
672676

677+
/// Folders stay open while searching, so every match is visible.
678+
bool _isExpanded(String key) =>
679+
_searchQuery.trim().isNotEmpty || !_collapsed.contains(key);
680+
681+
void _toggleFolder(String key) => setState(() {
682+
if (!_collapsed.remove(key)) _collapsed.add(key);
683+
});
684+
685+
/// Rows for [folder]: its sub-folders first, then its branches, each
686+
/// indented by [depth]. [key] prefixes the folder keys in [_collapsed].
687+
List<Widget> _treeRows(
688+
_BranchFolder folder, {
689+
required String key,
690+
required int depth,
691+
}) {
692+
final names = folder.folders.keys.toList()
693+
..sort((a, b) => a.toLowerCase().compareTo(b.toLowerCase()));
694+
return [
695+
for (final name in names) ...[
696+
_FolderRow(
697+
name: name,
698+
icon: Icons.folder_outlined,
699+
depth: depth,
700+
count: folder.folders[name]!.branchCount,
701+
expanded: _isExpanded('$key$name'),
702+
onToggle: () => _toggleFolder('$key$name'),
703+
),
704+
if (_isExpanded('$key$name'))
705+
..._treeRows(
706+
folder.folders[name]!,
707+
key: '$key$name/',
708+
depth: depth + 1,
709+
),
710+
],
711+
for (final branch in folder.branches)
712+
Padding(
713+
padding: EdgeInsetsDirectional.only(start: depth * _treeIndent),
714+
child: _buildBranchRow(branch, label: branch.name.split('/').last),
715+
),
716+
];
717+
}
718+
673719
Widget _buildBranchRow(BranchEntry branch, {String? label}) {
674720
return _BranchTile(
675721
branch: branch,
@@ -703,23 +749,16 @@ class _BranchSidebarState extends State<BranchSidebar> {
703749
_sort,
704750
);
705751

706-
// Remote branches that a local branch already stands for are shown on
707-
// that local row (cloud + ahead/behind), so only the rest are listed,
708-
// grouped by remote ("origin/main" -> "origin").
709-
final represented = {
710-
for (final branch in widget.branches)
711-
if (!branch.isRemote && branch.remoteCounterpart != null)
712-
branch.remoteCounterpart!,
713-
};
752+
// Every remote branch, grouped by remote ("origin/main" -> "origin").
714753
final remotesByName = <String, List<BranchEntry>>{};
715754
for (final branch in remote) {
716-
if (represented.contains(branch.name) || branch.name.endsWith('/HEAD')) {
717-
continue;
718-
}
755+
if (branch.name.endsWith('/HEAD')) continue;
719756
final slash = branch.name.indexOf('/');
720757
final remoteName = slash == -1 ? '' : branch.name.substring(0, slash);
721758
remotesByName.putIfAbsent(remoteName, () => []).add(branch);
722759
}
760+
final remoteCount =
761+
remotesByName.values.fold<int>(0, (sum, list) => sum + list.length);
723762

724763
final watching = widget.watchIntervalMinutes != null;
725764

@@ -817,35 +856,44 @@ class _BranchSidebarState extends State<BranchSidebar> {
817856
),
818857
),
819858
if (_localExpanded)
820-
for (final branch in local) _buildBranchRow(branch),
859+
..._treeRows(
860+
_BranchFolder.of(local, (branch) => branch.name),
861+
key: 'local:',
862+
depth: 0,
863+
),
821864
if (remotesByName.isNotEmpty) ...[
822865
Padding(
823866
padding: const EdgeInsets.fromLTRB(8, 12, 8, 12),
824867
child: Divider(height: 1, thickness: 1, color: b.line),
825868
),
826-
for (final entry in remotesByName.entries) ...[
827-
_SectionHeader(
828-
title: translate('branches_only_on_remote')
829-
.replaceAll('{remote}', entry.key),
830-
icon: Icons.cloud_outlined,
831-
count: entry.value.length,
832-
expanded: _remoteExpanded,
833-
onToggle: () =>
834-
setState(() => _remoteExpanded = !_remoteExpanded),
835-
),
836-
if (_remoteExpanded)
837-
_RemoteOnlyBox(
838-
children: [
839-
for (final branch in entry.value)
840-
_buildBranchRow(
841-
branch,
842-
label: _shortRemoteName(branch.name),
843-
),
844-
],
869+
_SectionHeader(
870+
title: translate('branches_remote'),
871+
icon: Icons.cloud_outlined,
872+
count: remoteCount,
873+
expanded: _remoteExpanded,
874+
onToggle: () =>
875+
setState(() => _remoteExpanded = !_remoteExpanded),
876+
),
877+
if (_remoteExpanded)
878+
for (final entry in remotesByName.entries) ...[
879+
_FolderRow(
880+
name: entry.key,
881+
icon: Icons.dns_outlined,
882+
depth: 0,
883+
count: entry.value.length,
884+
expanded: _isExpanded('remote:${entry.key}'),
885+
onToggle: () => _toggleFolder('remote:${entry.key}'),
845886
),
846-
if (entry.key != remotesByName.keys.last)
847-
const SizedBox(height: 16),
848-
],
887+
if (_isExpanded('remote:${entry.key}'))
888+
..._treeRows(
889+
_BranchFolder.of(
890+
entry.value,
891+
(branch) => _shortRemoteName(branch.name),
892+
),
893+
key: 'remote:${entry.key}/',
894+
depth: 1,
895+
),
896+
],
849897
],
850898
],
851899
),
@@ -1061,16 +1109,8 @@ class _BranchTile extends StatelessWidget {
10611109
final b = context.branchi;
10621110
final current = branch.isHead;
10631111
final base = branch.isRemote ? null : baseLabel;
1064-
final name = Text.rich(
1065-
TextSpan(children: [
1066-
// Remote rows always say where they live.
1067-
if (branch.isRemote && label != branch.name)
1068-
TextSpan(
1069-
text: branch.name.substring(0, branch.name.length - label.length),
1070-
style: TextStyle(color: b.off),
1071-
),
1072-
TextSpan(text: label),
1073-
]),
1112+
final name = Text(
1113+
label,
10741114
maxLines: 1,
10751115
overflow: TextOverflow.ellipsis,
10761116
style: TextStyle(
@@ -1289,63 +1329,102 @@ class _SyncState extends StatelessWidget {
12891329
}
12901330
}
12911331

1292-
/// Dashed box around branches that exist only on a remote, so they can't
1293-
/// be mistaken for local ones.
1294-
class _RemoteOnlyBox extends StatelessWidget {
1295-
const _RemoteOnlyBox({required this.children});
1332+
/// How far each tree level is indented.
1333+
const double _treeIndent = 14;
1334+
1335+
/// Branches grouped by their "/"-separated name parts: "feature/login"
1336+
/// lands in folder "feature".
1337+
class _BranchFolder {
1338+
final Map<String, _BranchFolder> folders = {};
1339+
final List<BranchEntry> branches = [];
1340+
1341+
/// Builds the tree from [branches] (kept in their order), placed by the
1342+
/// path [pathOf] gives each one.
1343+
static _BranchFolder of(
1344+
List<BranchEntry> branches,
1345+
String Function(BranchEntry) pathOf,
1346+
) {
1347+
final root = _BranchFolder();
1348+
for (final branch in branches) {
1349+
final parts = pathOf(branch).split('/');
1350+
var node = root;
1351+
for (final part in parts.take(parts.length - 1)) {
1352+
if (part.isEmpty) continue;
1353+
node = node.folders.putIfAbsent(part, _BranchFolder.new);
1354+
}
1355+
node.branches.add(branch);
1356+
}
1357+
return root;
1358+
}
1359+
1360+
int get branchCount => folders.values
1361+
.fold(branches.length, (sum, folder) => sum + folder.branchCount);
1362+
}
1363+
1364+
/// A collapsible folder (or remote) row in the branch tree.
1365+
class _FolderRow extends StatelessWidget {
1366+
const _FolderRow({
1367+
required this.name,
1368+
required this.icon,
1369+
required this.depth,
1370+
required this.count,
1371+
required this.expanded,
1372+
required this.onToggle,
1373+
});
12961374

1297-
final List<Widget> children;
1375+
final String name;
1376+
final IconData icon;
1377+
final int depth;
1378+
final int count;
1379+
final bool expanded;
1380+
final VoidCallback onToggle;
12981381

12991382
@override
13001383
Widget build(BuildContext context) {
13011384
final b = context.branchi;
1302-
return CustomPaint(
1303-
painter: _DashedBorderPainter(color: b.off),
1304-
child: Padding(
1305-
padding: const EdgeInsets.fromLTRB(2, 6, 2, 6),
1306-
child: Column(
1307-
crossAxisAlignment: CrossAxisAlignment.stretch,
1308-
children: [
1309-
...children,
1310-
Padding(
1311-
padding: const EdgeInsets.fromLTRB(8, 2, 8, 2),
1312-
child: Text(
1313-
translate('branches_remote_hint'),
1314-
style: TextStyle(fontSize: 11, color: b.muted),
1315-
),
1385+
return Padding(
1386+
padding: EdgeInsetsDirectional.only(
1387+
start: depth * _treeIndent,
1388+
bottom: 2,
1389+
),
1390+
child: Material(
1391+
color: Colors.transparent,
1392+
borderRadius: BorderRadius.circular(6),
1393+
child: InkWell(
1394+
onTap: onToggle,
1395+
borderRadius: BorderRadius.circular(6),
1396+
hoverColor: b.hover,
1397+
splashFactory: NoSplash.splashFactory,
1398+
child: Padding(
1399+
padding: const EdgeInsetsDirectional.fromSTEB(2, 5, 8, 5),
1400+
child: Row(
1401+
children: [
1402+
Icon(
1403+
expanded
1404+
? Icons.keyboard_arrow_down
1405+
: (Directionality.of(context) == TextDirection.rtl
1406+
? Icons.keyboard_arrow_left
1407+
: Icons.keyboard_arrow_right),
1408+
size: 14,
1409+
color: b.muted,
1410+
),
1411+
const SizedBox(width: 2),
1412+
Icon(icon, size: 13, color: b.muted),
1413+
const SizedBox(width: 6),
1414+
Expanded(
1415+
child: Text(
1416+
name,
1417+
maxLines: 1,
1418+
overflow: TextOverflow.ellipsis,
1419+
style: TextStyle(fontSize: 13, color: b.muted),
1420+
),
1421+
),
1422+
Text('$count', style: TextStyle(fontSize: 11, color: b.off)),
1423+
],
13161424
),
1317-
],
1425+
),
13181426
),
13191427
),
13201428
);
13211429
}
13221430
}
1323-
1324-
class _DashedBorderPainter extends CustomPainter {
1325-
_DashedBorderPainter({required this.color});
1326-
1327-
final Color color;
1328-
1329-
@override
1330-
void paint(Canvas canvas, Size size) {
1331-
final paint = Paint()
1332-
..color = color
1333-
..style = PaintingStyle.stroke
1334-
..strokeWidth = 1;
1335-
final path = Path()
1336-
..addRRect(
1337-
RRect.fromRectAndRadius(
1338-
Offset.zero & size,
1339-
const Radius.circular(8),
1340-
).deflate(0.5),
1341-
);
1342-
for (final metric in path.computeMetrics()) {
1343-
for (var d = 0.0; d < metric.length; d += 7) {
1344-
canvas.drawPath(metric.extractPath(d, d + 4), paint);
1345-
}
1346-
}
1347-
}
1348-
1349-
@override
1350-
bool shouldRepaint(_DashedBorderPainter old) => old.color != color;
1351-
}

‎flutter/lib/terminal/terminal_panel.dart‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,12 @@ class _TerminalPanelState extends State<TerminalPanel> {
165165
height: 32,
166166
child: Row(
167167
children: [
168-
Expanded(
168+
// Tabs take only the room they need, so the + button
169+
// follows the last tab; they scroll once they fill
170+
// the row.
171+
Flexible(
169172
child: ListView.builder(
173+
shrinkWrap: true,
170174
scrollDirection: Axis.horizontal,
171175
itemCount: sessions.length,
172176
itemBuilder: (context, index) {

0 commit comments

Comments
 (0)