1
This commit is contained in:
1 parent
85fe316cf1
commit
96358eae07
29 files changed
+11610
-503
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/providers/distro_provider.dart';
|
||||
import 'package:code_editor/providers/git_provider.dart';
|
||||
import 'package:code_editor/providers/project_provider.dart';
|
||||
import 'package:code_editor/providers/run_provider.dart';
|
||||
import 'package:code_editor/providers/tab_provider.dart';
|
||||
@@ -9,6 +10,7 @@ import 'package:code_editor/utils/dialog_utils.dart';
|
||||
import 'package:code_editor/views/project_management_view.dart';
|
||||
import 'package:code_editor/widgets/project_history_widget.dart';
|
||||
import 'package:code_editor/widgets/file_tree_widget.dart';
|
||||
import 'package:code_editor/widgets/git/git_panel_widget.dart';
|
||||
import 'package:code_editor/widgets/search/search_panel_widget.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -142,6 +144,7 @@ class _CodeEditorDrawerState extends State<CodeEditorDrawer> {
|
||||
required int index,
|
||||
required IconData icon,
|
||||
required String label,
|
||||
int? badgeCount,
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
final isSelected = _selectedIndex == index;
|
||||
@@ -188,6 +191,36 @@ class _CodeEditorDrawerState extends State<CodeEditorDrawer> {
|
||||
? colorScheme.primary
|
||||
: colorScheme.onSurfaceVariant.withValues(alpha: 0.7),
|
||||
),
|
||||
if (badgeCount != null && badgeCount > 0)
|
||||
Positioned(
|
||||
right: 4,
|
||||
bottom: 5,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 1),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 16,
|
||||
minHeight: 16,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.primary,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: theme.colorScheme.surfaceContainerLow,
|
||||
width: 1.2,
|
||||
),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
badgeCount > 99 ? '99+' : badgeCount.toString(),
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: colorScheme.onPrimary,
|
||||
height: 1.1,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -200,6 +233,9 @@ class _CodeEditorDrawerState extends State<CodeEditorDrawer> {
|
||||
AppLocalizations l10n,
|
||||
ThemeData theme,
|
||||
) {
|
||||
final gitProvider = context.watch<GitProvider?>();
|
||||
final gitBadgeCount = (gitProvider?.isGitRepo ?? false) ? (gitProvider?.totalChangedCount ?? 0) : 0;
|
||||
|
||||
return Container(
|
||||
width: 48,
|
||||
decoration: BoxDecoration(
|
||||
@@ -236,6 +272,7 @@ class _CodeEditorDrawerState extends State<CodeEditorDrawer> {
|
||||
index: 2,
|
||||
icon: Icons.alt_route_rounded,
|
||||
label: l10n.drawerTabGit,
|
||||
badgeCount: gitBadgeCount,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -449,45 +486,6 @@ class _CodeEditorDrawerState extends State<CodeEditorDrawer> {
|
||||
|
||||
|
||||
|
||||
Widget _buildGitPlaceholder(
|
||||
BuildContext context,
|
||||
AppLocalizations l10n,
|
||||
ThemeData theme,
|
||||
) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.primaryContainer,
|
||||
),
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
left: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 14.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.drawerTabGit,
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Expanded(child: SizedBox.shrink()),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
@@ -502,12 +500,12 @@ class _CodeEditorDrawerState extends State<CodeEditorDrawer> {
|
||||
children: [
|
||||
_buildActivityBar(context, l10n, theme),
|
||||
Expanded(
|
||||
child: IndexedStack(
|
||||
child: _LazyIndexedStack(
|
||||
index: _selectedIndex,
|
||||
children: [
|
||||
_buildExplorerPage(context, l10n, theme, rootPath, hasProject),
|
||||
const SearchPanelWidget(),
|
||||
_buildGitPlaceholder(context, l10n, theme),
|
||||
builders: [
|
||||
(ctx) => _buildExplorerPage(ctx, l10n, theme, rootPath, hasProject),
|
||||
(ctx) => const SearchPanelWidget(),
|
||||
(ctx) => const GitPanelWidget(),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -516,3 +514,53 @@ class _CodeEditorDrawerState extends State<CodeEditorDrawer> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 惰性按需挂载的 IndexedStack,仅在 Tab 首次被激活时实例化子 Widget,
|
||||
/// 并通过 Offstage + TickerMode 永久保持状态与滚动偏移,杜绝抽屉初次滑出时全量构建卡顿。
|
||||
class _LazyIndexedStack extends StatefulWidget {
|
||||
final int index;
|
||||
final List<WidgetBuilder> builders;
|
||||
|
||||
const _LazyIndexedStack({
|
||||
required this.index,
|
||||
required this.builders,
|
||||
});
|
||||
|
||||
@override
|
||||
State<_LazyIndexedStack> createState() => _LazyIndexedStackState();
|
||||
}
|
||||
|
||||
class _LazyIndexedStackState extends State<_LazyIndexedStack> {
|
||||
late final Set<int> _activatedIndices;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_activatedIndices = {widget.index};
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant _LazyIndexedStack oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
_activatedIndices.add(widget.index);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: List.generate(widget.builders.length, (i) {
|
||||
final isActivated = _activatedIndices.contains(i);
|
||||
final isSelected = widget.index == i;
|
||||
|
||||
return Offstage(
|
||||
offstage: !isSelected,
|
||||
child: TickerMode(
|
||||
enabled: isSelected,
|
||||
child: isActivated ? widget.builders[i](context) : const SizedBox.shrink(),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -501,47 +501,24 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
curOpt.pattern != query ||
|
||||
curOpt.caseSensitive != searchProvider.caseSensitive ||
|
||||
curOpt.regex != searchProvider.isRegex) {
|
||||
if (query.isEmpty) {
|
||||
if (curVal != null && curOpt?.pattern.isNotEmpty == true) {
|
||||
// 注意:不能直接调用 _findController!.close(),
|
||||
// 因为 re_editor 内部在 value == null 时会强制执行 widget.focusNode.requestFocus(),
|
||||
// 导致侧边抽屉中的搜索输入框在内容清空时瞬间失去焦点。
|
||||
// 此处同时临时锁定 _focusNode.canRequestFocus 并赋空匹配正则,彻底杜绝编辑器抢夺焦点。
|
||||
final wasCanRequest = _focusNode.canRequestFocus;
|
||||
_focusNode.canRequestFocus = false;
|
||||
try {
|
||||
_findController!.value = const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: r'(?!)',
|
||||
caseSensitive: false,
|
||||
regex: true,
|
||||
),
|
||||
replaceMode: false,
|
||||
searching: false,
|
||||
);
|
||||
} finally {
|
||||
_focusNode.canRequestFocus = wasCanRequest;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final wasCanRequest = _focusNode.canRequestFocus;
|
||||
_focusNode.canRequestFocus = false;
|
||||
try {
|
||||
_findController!.value = CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: query,
|
||||
caseSensitive: searchProvider.caseSensitive,
|
||||
regex: searchProvider.isRegex,
|
||||
),
|
||||
replaceMode: false,
|
||||
searching: true,
|
||||
);
|
||||
if (_findController!.findInputController.text != query) {
|
||||
_findController!.findInputController.text = query;
|
||||
}
|
||||
} finally {
|
||||
_focusNode.canRequestFocus = wasCanRequest;
|
||||
}
|
||||
// 严禁设置 _focusNode.canRequestFocus = false!
|
||||
// 在 Flutter 框架中,当编辑区拥有焦点时(用户正在编辑代码输入),
|
||||
// 将 canRequestFocus 置为 false 会强制触发 unfocus(),紧接着在输入时又重获焦点,
|
||||
// 造成软键盘反复弹起收起(一跳一跳的致命抖动)。
|
||||
// 同时此处保持 _findController.value 非 null(pattern 为 query),
|
||||
// re_editor 在 pattern 为空时会自动将 matches 清空,既彻底清除了高亮,
|
||||
// 又避免了在 value == null 时触发 re_editor 内部偷夺焦点的 requestFocus()。
|
||||
_findController!.value = CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: query,
|
||||
caseSensitive: searchProvider.caseSensitive,
|
||||
regex: searchProvider.isRegex,
|
||||
),
|
||||
replaceMode: false,
|
||||
searching: query.isNotEmpty,
|
||||
);
|
||||
if (_findController!.findInputController.text != query) {
|
||||
_findController!.findInputController.text = query;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -798,7 +775,11 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
} catch (_) {}
|
||||
|
||||
final searchProvider = context.watch<SearchProvider?>();
|
||||
_syncSearchHighlight(searchProvider);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
_syncSearchHighlight(searchProvider);
|
||||
}
|
||||
});
|
||||
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final hasNoProject = widget.rootPath == null || widget.rootPath!.trim().isEmpty;
|
||||
@@ -1130,7 +1111,18 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
|
||||
_controller = newController;
|
||||
_findController?.dispose();
|
||||
_findController = CodeFindController(newController);
|
||||
_findController = CodeFindController(
|
||||
newController,
|
||||
const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
replaceMode: false,
|
||||
searching: false,
|
||||
),
|
||||
);
|
||||
_currentLoadedPath = fullFilePath;
|
||||
_currentIndentSize = activeIndentSize;
|
||||
_errorMessage = null;
|
||||
@@ -1196,7 +1188,18 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
|
||||
_controller = newController;
|
||||
_findController?.dispose();
|
||||
_findController = CodeFindController(newController);
|
||||
_findController = CodeFindController(
|
||||
newController,
|
||||
const CodeFindValue(
|
||||
option: CodeFindOption(
|
||||
pattern: '',
|
||||
caseSensitive: false,
|
||||
regex: false,
|
||||
),
|
||||
replaceMode: false,
|
||||
searching: false,
|
||||
),
|
||||
);
|
||||
_currentLoadedPath = fullFilePath;
|
||||
_currentIndentSize = activeIndentSize;
|
||||
_errorMessage = null;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/models/file_item.dart';
|
||||
import 'package:code_editor/providers/git_provider.dart';
|
||||
import 'package:code_editor/providers/project_provider.dart';
|
||||
import 'package:code_editor/providers/tab_provider.dart';
|
||||
import 'package:code_editor/services/permission_service.dart';
|
||||
import 'package:code_editor/utils/dialog_utils.dart';
|
||||
import 'package:code_editor/utils/file_icon_utils.dart';
|
||||
import 'package:code_editor/utils/git_decoration_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -30,6 +32,14 @@ class _FileItemWidgetState extends State<FileItemWidget> {
|
||||
return listen ? context.watch<TabProvider>() : context.read<TabProvider>();
|
||||
}
|
||||
|
||||
static GitProvider? _getGitProvider(BuildContext context, {bool listen = false}) {
|
||||
try {
|
||||
return listen ? context.watch<GitProvider>() : context.read<GitProvider>();
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _buildFileItem(context, widget.fileItem);
|
||||
@@ -39,22 +49,41 @@ class _FileItemWidgetState extends State<FileItemWidget> {
|
||||
final theme = Theme.of(context);
|
||||
final projectProvider = _getProjectProvider(context, listen: true);
|
||||
final tabProvider = _getTabProvider(context, listen: true);
|
||||
final gitProvider = _getGitProvider(context, listen: true);
|
||||
final isDark = theme.brightness == Brightness.dark;
|
||||
|
||||
final indent = EdgeInsets.only(left: item.depth * 16.0 + 8.0, right: 8.0);
|
||||
|
||||
// 获取 Git 状态修饰
|
||||
final gitFileStatus = !item.isDirectory && gitProvider != null
|
||||
? gitProvider.getFileStatus(item.path)
|
||||
: null;
|
||||
final gitDirStatusType = item.isDirectory && gitProvider != null
|
||||
? gitProvider.getDirectoryStatus(item.path)
|
||||
: null;
|
||||
|
||||
final Color? gitColor = !item.isDirectory
|
||||
? (gitFileStatus != null
|
||||
? GitDecorationUtils.getStatusColor(gitFileStatus.statusType, isDark: isDark)
|
||||
: null)
|
||||
: (gitDirStatusType != null
|
||||
? GitDecorationUtils.getStatusColor(gitDirStatusType, isDark: isDark)
|
||||
: null);
|
||||
|
||||
// 判断该文件是否处于被剪切状态
|
||||
final isCut = projectProvider.isItemCut(item.path);
|
||||
|
||||
// 判断该文件是否为当前正在编辑/修改的文件
|
||||
final isSelected = !item.isDirectory && tabProvider.isFileSelected(item.path);
|
||||
|
||||
// 文字样式:剪切时变灰,选中时高亮,其余正常
|
||||
// 文字样式:剪切时变灰,选中时高亮,有 Git 状态时使用 Git 状态色,其余正常
|
||||
final itemTextStyle = theme.textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||
color: isCut
|
||||
? theme.colorScheme.onSurface.withValues(alpha: 0.38)
|
||||
: isSelected
|
||||
? theme.colorScheme.primary
|
||||
: null,
|
||||
: gitColor,
|
||||
);
|
||||
|
||||
final iconColor = isCut
|
||||
@@ -64,36 +93,95 @@ class _FileItemWidgetState extends State<FileItemWidget> {
|
||||
: null;
|
||||
|
||||
if (item.isDirectory) {
|
||||
Widget? dirTrailing;
|
||||
if (gitColor != null && gitDirStatusType != null) {
|
||||
dirTrailing = SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 7,
|
||||
height: 7,
|
||||
decoration: BoxDecoration(
|
||||
color: gitColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return GestureDetector(
|
||||
onLongPressStart: (details) {
|
||||
_showContextMenu(item, details.globalPosition);
|
||||
},
|
||||
child: ExpansionTile(
|
||||
key: PageStorageKey(item.path),
|
||||
initiallyExpanded: item.isOpen,
|
||||
tilePadding: indent,
|
||||
leading: Icon(
|
||||
item.isOpen ? Icons.folder_open_outlined : Icons.folder_outlined,
|
||||
color: isCut ? iconColor : null,
|
||||
size: 20,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 1.0),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: ListTile(
|
||||
contentPadding: indent,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
dense: true,
|
||||
leading: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
item.isOpen ? Icons.keyboard_arrow_down : Icons.keyboard_arrow_right,
|
||||
size: 16,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
item.isOpen ? Icons.folder_open_outlined : Icons.folder_outlined,
|
||||
color: isCut ? iconColor : (item.isOpen ? theme.colorScheme.primary : null),
|
||||
size: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
title: Text(
|
||||
item.name,
|
||||
style: itemTextStyle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
trailing: dirTrailing,
|
||||
onTap: () {
|
||||
final newExpanded = !item.isOpen;
|
||||
setState(() {
|
||||
item.isOpen = newExpanded;
|
||||
});
|
||||
_getProjectProvider(context).toggleDirectory(item, newExpanded);
|
||||
},
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
item.name,
|
||||
style: itemTextStyle,
|
||||
),
|
||||
dense: true,
|
||||
onExpansionChanged: (bool expanded) {
|
||||
setState(() {
|
||||
item.isOpen = expanded;
|
||||
});
|
||||
_getProjectProvider(context).toggleDirectory(item, expanded);
|
||||
},
|
||||
children: item.children
|
||||
.map((child) => FileItemWidget(fileItem: child))
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Widget? fileTrailing;
|
||||
if (gitColor != null && gitFileStatus != null) {
|
||||
final letter = GitDecorationUtils.getStatusLetter(gitFileStatus.statusType);
|
||||
if (letter != null && letter.isNotEmpty) {
|
||||
fileTrailing = SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: Center(
|
||||
child: Text(
|
||||
letter,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: gitColor,
|
||||
height: 1.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return GestureDetector(
|
||||
onLongPressStart: (details) {
|
||||
_showContextMenu(item, details.globalPosition);
|
||||
@@ -117,7 +205,10 @@ class _FileItemWidgetState extends State<FileItemWidget> {
|
||||
title: Text(
|
||||
item.name,
|
||||
style: itemTextStyle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
trailing: fileTrailing,
|
||||
dense: true,
|
||||
onTap: () {
|
||||
final scaffold = Scaffold.maybeOf(context);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/models/file_item.dart';
|
||||
import 'package:code_editor/providers/project_provider.dart';
|
||||
import 'package:code_editor/widgets/file_item_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -53,13 +54,27 @@ class FileTreeWidget extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
// 3. 动态扁平化已展开的目录树,使所有深度的文件节点均能通过 ListView.builder 获得真正的行级虚拟化
|
||||
final flatItems = <FileItem>[];
|
||||
void flatten(List<FileItem> list) {
|
||||
for (final it in list) {
|
||||
flatItems.add(it);
|
||||
if (it.isDirectory && it.isOpen && it.children.isNotEmpty) {
|
||||
flatten(it.children);
|
||||
}
|
||||
}
|
||||
}
|
||||
flatten(items);
|
||||
|
||||
return ListView.builder(
|
||||
key: const PageStorageKey('code_editor_file_tree_list'),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
||||
itemCount: items.length,
|
||||
itemCount: flatItems.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = flatItems[index];
|
||||
return FileItemWidget(
|
||||
fileItem: items[index],
|
||||
key: ValueKey(item.path),
|
||||
fileItem: item,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,110 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../models/git_model.dart';
|
||||
|
||||
/// VS Code 风格 Git 提交历史拓扑图绘制器
|
||||
class GitGraphPainter extends CustomPainter {
|
||||
final GitCommit commit;
|
||||
final bool isFirstCommit;
|
||||
final ColorScheme colorScheme;
|
||||
|
||||
static const double laneWidth = 14.0;
|
||||
static const double startOffset = 14.0;
|
||||
|
||||
// 经典多分支着色调色板
|
||||
static const List<Color> laneColors = [
|
||||
Color(0xFF2196F3), // 蓝
|
||||
Color(0xFF4CAF50), // 绿
|
||||
Color(0xFFFF9800), // 橙
|
||||
Color(0xFFE91E63), // 粉红
|
||||
Color(0xFF9C27B0), // 紫
|
||||
Color(0xFF00BCD4), // 青
|
||||
Color(0xFFFFEB3B), // 黄
|
||||
Color(0xFF795548), // 棕
|
||||
];
|
||||
|
||||
static Color getLaneColor(int lane) {
|
||||
return laneColors[lane % laneColors.length];
|
||||
}
|
||||
|
||||
const GitGraphPainter({
|
||||
required this.commit,
|
||||
required this.isFirstCommit,
|
||||
required this.colorScheme,
|
||||
});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final centerY = size.height / 2;
|
||||
final nodeX = startOffset + commit.lane * laneWidth;
|
||||
final nodeColor = getLaneColor(commit.lane);
|
||||
|
||||
final linePaint = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 2.0
|
||||
..strokeCap = StrokeCap.round;
|
||||
|
||||
// 1. 绘制穿透此行的其他活跃通道
|
||||
for (final lane in commit.activeLanes) {
|
||||
if (lane == commit.lane) continue;
|
||||
final x = startOffset + lane * laneWidth;
|
||||
linePaint.color = getLaneColor(lane);
|
||||
canvas.drawLine(Offset(x, 0), Offset(x, size.height), linePaint);
|
||||
}
|
||||
|
||||
// 2. 绘制进入当前节点的连线(如果不是首个展示的提交,说明上方有子提交连入)
|
||||
if (!isFirstCommit) {
|
||||
linePaint.color = nodeColor;
|
||||
canvas.drawLine(Offset(nodeX, 0), Offset(nodeX, centerY), linePaint);
|
||||
}
|
||||
|
||||
// 3. 绘制当前节点连向父提交的连线
|
||||
for (final targetLane in commit.outgoingLanes) {
|
||||
final targetX = startOffset + targetLane * laneWidth;
|
||||
linePaint.color = nodeColor;
|
||||
|
||||
if (targetLane == commit.lane) {
|
||||
// 直线向下连到下一行
|
||||
canvas.drawLine(Offset(nodeX, centerY), Offset(nodeX, size.height), linePaint);
|
||||
} else {
|
||||
// 跨分支弧线(贝塞尔平滑曲线)
|
||||
final path = Path();
|
||||
path.moveTo(nodeX, centerY);
|
||||
final controlY = centerY + (size.height - centerY) * 0.5;
|
||||
path.cubicTo(nodeX, controlY, targetX, controlY, targetX, size.height);
|
||||
canvas.drawPath(path, linePaint);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 绘制提交节点
|
||||
final bgPaint = Paint()
|
||||
..style = PaintingStyle.fill
|
||||
..color = colorScheme.surface;
|
||||
|
||||
final dotPaint = Paint()
|
||||
..style = PaintingStyle.fill
|
||||
..color = nodeColor;
|
||||
|
||||
// 节点外围背景微隔离圈,防止与连线黏连
|
||||
canvas.drawCircle(Offset(nodeX, centerY), 6.5, bgPaint);
|
||||
|
||||
if (commit.isHead) {
|
||||
// HEAD 节点:外圈光环 + 内部实心
|
||||
final haloPaint = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 2.2
|
||||
..color = nodeColor;
|
||||
canvas.drawCircle(Offset(nodeX, centerY), 6.0, haloPaint);
|
||||
canvas.drawCircle(Offset(nodeX, centerY), 3.2, dotPaint);
|
||||
} else {
|
||||
// 普通节点:实心圆
|
||||
canvas.drawCircle(Offset(nodeX, centerY), 4.5, dotPaint);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant GitGraphPainter oldDelegate) {
|
||||
return oldDelegate.commit != commit ||
|
||||
oldDelegate.isFirstCommit != isFirstCommit ||
|
||||
oldDelegate.colorScheme != colorScheme;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -459,6 +459,15 @@ class _SearchPanelWidgetState extends State<SearchPanelWidget> {
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
if (options.mode == SearchMode.fileName && result.fileResults.isNotEmpty) ...[
|
||||
IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
iconSize: 18,
|
||||
tooltip: l10n.expandAll,
|
||||
icon: const Icon(Icons.unfold_more),
|
||||
onPressed: () => searchProvider.loadAllFiles(),
|
||||
),
|
||||
],
|
||||
if (options.mode == SearchMode.text && result.fileResults.isNotEmpty) ...[
|
||||
IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
@@ -781,6 +790,44 @@ class _SearchPanelWidgetState extends State<SearchPanelWidget> {
|
||||
final visibleFiles = allFiles.take(visibleFilesCount).toList();
|
||||
final hasMoreFiles = allFiles.length > visibleFilesCount;
|
||||
final remainingFilesCount = allFiles.length - visibleFilesCount;
|
||||
final isFileNameMode = options.mode == SearchMode.fileName;
|
||||
|
||||
// 将搜索树状结构扁平化为一维条目列表,供单一 ListView.builder 进行真正的行级虚拟化
|
||||
final List<_SearchRowItem> flattenedItems = [];
|
||||
if (isFileNameMode) {
|
||||
for (final file in visibleFiles) {
|
||||
flattenedItems.add(_SearchFileNameRowItem(file));
|
||||
}
|
||||
} else {
|
||||
for (final file in visibleFiles) {
|
||||
flattenedItems.add(_SearchFileHeaderRowItem(file));
|
||||
if (file.isExpanded) {
|
||||
final currentMatchesLimit = searchProvider.getFileMatchesLimit(
|
||||
file.filePath,
|
||||
SearchPanelWidget.defaultFileMatchesPageSize,
|
||||
);
|
||||
final allMatches = file.matches;
|
||||
final visibleMatchesCount = allMatches.length < currentMatchesLimit
|
||||
? allMatches.length
|
||||
: currentMatchesLimit;
|
||||
for (var i = 0; i < visibleMatchesCount; i++) {
|
||||
flattenedItems.add(_SearchMatchLineRowItem(file, allMatches[i]));
|
||||
}
|
||||
if (allMatches.length > visibleMatchesCount) {
|
||||
flattenedItems.add(
|
||||
_SearchLoadMoreMatchesRowItem(
|
||||
file,
|
||||
allMatches.length - visibleMatchesCount,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasMoreFiles) {
|
||||
flattenedItems.add(_SearchLoadMoreFilesRowItem(remainingFilesCount));
|
||||
}
|
||||
|
||||
return MediaQuery.removePadding(
|
||||
context: context,
|
||||
@@ -789,377 +836,55 @@ class _SearchPanelWidgetState extends State<SearchPanelWidget> {
|
||||
key: const PageStorageKey('project_search_results_list'),
|
||||
controller: _scrollController,
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: visibleFiles.length + (hasMoreFiles ? 1 : 0),
|
||||
itemBuilder: (context, fileIndex) {
|
||||
if (fileIndex == visibleFiles.length) {
|
||||
return _buildLoadMoreFilesTile(
|
||||
theme,
|
||||
l10n,
|
||||
remainingFilesCount,
|
||||
searchProvider,
|
||||
);
|
||||
}
|
||||
|
||||
final fileResult = visibleFiles[fileIndex];
|
||||
final isExpanded = fileResult.isExpanded;
|
||||
final dirName = p.dirname(fileResult.relativePath);
|
||||
final hasDir = dirName != '.' && dirName.isNotEmpty;
|
||||
|
||||
final currentMatchesLimit = searchProvider.getFileMatchesLimit(
|
||||
fileResult.filePath,
|
||||
SearchPanelWidget.defaultFileMatchesPageSize,
|
||||
);
|
||||
final allMatches = fileResult.matches;
|
||||
final visibleMatchesCount = allMatches.length < currentMatchesLimit
|
||||
? allMatches.length
|
||||
: currentMatchesLimit;
|
||||
final visibleMatches = allMatches.take(visibleMatchesCount).toList();
|
||||
final hasMoreMatches = allMatches.length > visibleMatchesCount;
|
||||
final remainingMatchesCount = allMatches.length - visibleMatchesCount;
|
||||
|
||||
final isFileNameMode = options.mode == SearchMode.fileName;
|
||||
|
||||
if (isFileNameMode) {
|
||||
// 文件名/文件夹名匹配模式:普通扁平 item,不折叠,高亮直接绘制在主标题文件名上
|
||||
final match = fileResult.matches.isNotEmpty ? fileResult.matches.first : null;
|
||||
final iconData = FileIconUtils.getIcon(
|
||||
name: fileResult.fileName,
|
||||
isDirectory: fileResult.isDirectory,
|
||||
);
|
||||
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
if (fileResult.isDirectory) {
|
||||
// 点击文件夹搜索项:展开并跳转到目录
|
||||
final projectProvider = context.read<ProjectProvider?>();
|
||||
if (projectProvider != null) {
|
||||
final cleanRoot = projectProvider.rootPath;
|
||||
if (cleanRoot != null) {
|
||||
final updatedOpenPaths = List<String>.from(projectProvider.openDirectoryPaths);
|
||||
if (!updatedOpenPaths.contains(fileResult.filePath)) {
|
||||
updatedOpenPaths.add(fileResult.filePath);
|
||||
}
|
||||
await projectProvider.toggleDirectory(
|
||||
FileItem(
|
||||
path: fileResult.filePath,
|
||||
name: fileResult.fileName,
|
||||
relativePath: fileResult.relativePath,
|
||||
isDirectory: true,
|
||||
),
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 点击文件搜索项:打开并进入编辑该文件
|
||||
if (tabProvider != null) {
|
||||
await tabProvider.openFile(fileResult.filePath);
|
||||
}
|
||||
}
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).maybePop();
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10.0,
|
||||
vertical: 6.0,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
iconData,
|
||||
size: 18,
|
||||
color: fileResult.isDirectory
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// 主标题:文件名带关键词高亮
|
||||
_buildFileNameHighlightedTitle(
|
||||
fileResult.fileName,
|
||||
match,
|
||||
theme,
|
||||
),
|
||||
if (hasDir)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 2.0),
|
||||
child: Text(
|
||||
dirName,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.7),
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
itemCount: flattenedItems.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = flattenedItems[index];
|
||||
return switch (item) {
|
||||
_SearchFileNameRowItem(:final file) => _buildFileNameTile(
|
||||
context,
|
||||
theme,
|
||||
file,
|
||||
tabProvider,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 文本内容匹配模式:可折叠树形结构展示
|
||||
final iconData = FileIconUtils.getIcon(
|
||||
name: fileResult.fileName,
|
||||
isDirectory: fileResult.isDirectory,
|
||||
);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// 文件分组条目
|
||||
InkWell(
|
||||
onTap: () => searchProvider.toggleFileExpanded(fileResult),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10.0,
|
||||
vertical: 6.0,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
isExpanded
|
||||
? Icons.keyboard_arrow_down
|
||||
: Icons.keyboard_arrow_right,
|
||||
size: 18,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
iconData,
|
||||
size: 16,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// 主标题文件名,副标题相对路径(一上一下)
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
fileResult.fileName,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 13,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
if (hasDir)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 2.0),
|
||||
child: Text(
|
||||
dirName,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.7),
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
|
||||
// 匹配次数 Badge
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'${fileResult.matchCount}',
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 文件级全部替换按钮:仅在展开替换输入框时展示
|
||||
if (options.mode == SearchMode.text && options.isReplaceExpanded)
|
||||
IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
style: IconButton.styleFrom(
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
minimumSize: Size.zero,
|
||||
padding: const EdgeInsets.all(4),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 24,
|
||||
minHeight: 24,
|
||||
),
|
||||
iconSize: 16,
|
||||
icon: const Icon(Icons.find_replace),
|
||||
tooltip: l10n.replaceAllInFile,
|
||||
onPressed: tabProvider == null
|
||||
? null
|
||||
: () async {
|
||||
final confirmed = await DialogUtils.showConfirmDialog(
|
||||
context,
|
||||
title: l10n.confirmReplaceFileTitle,
|
||||
message: l10n.confirmReplaceFileMessage(
|
||||
fileResult.fileName,
|
||||
fileResult.matchCount,
|
||||
options.replaceText,
|
||||
),
|
||||
confirmText: l10n.replaceSingleMatch,
|
||||
);
|
||||
if (!confirmed || !context.mounted) return;
|
||||
|
||||
final count = await searchProvider.replaceFileMatches(
|
||||
file: fileResult,
|
||||
tabProvider: tabProvider,
|
||||
);
|
||||
if (context.mounted && count > 0) {
|
||||
DialogUtils.showSuccessToast(
|
||||
context,
|
||||
l10n.replaceSuccess(count),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_SearchFileHeaderRowItem(:final file) => _buildFileHeaderTile(
|
||||
context,
|
||||
theme,
|
||||
l10n,
|
||||
file,
|
||||
searchProvider,
|
||||
tabProvider,
|
||||
options,
|
||||
),
|
||||
|
||||
// 展开展示具体匹配行(按需分页加载)
|
||||
if (isExpanded) ...[
|
||||
...visibleMatches.map((match) {
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
if (tabProvider != null) {
|
||||
// 1. 打开文件并切换 tab
|
||||
await tabProvider.openFile(fileResult.filePath);
|
||||
// 2. 发送行定位与选区高亮事件
|
||||
tabProvider.navigateTo(
|
||||
filePath: fileResult.filePath,
|
||||
line: match.lineNumber - 1,
|
||||
column: match.matchStart,
|
||||
length: match.matchEnd - match.matchStart,
|
||||
);
|
||||
}
|
||||
// 3. 移动端抽屉收起(保留宽屏适配)
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).maybePop();
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(36.0, 4.0, 10.0, 4.0),
|
||||
child: Row(
|
||||
children: [
|
||||
// 行号
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(minWidth: 28),
|
||||
child: Text(
|
||||
'${match.lineNumber}:',
|
||||
style: TextStyle(
|
||||
fontFamily: 'JetBrains Mono',
|
||||
fontSize: 11.5,
|
||||
color: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
|
||||
// 代码文本摘要(黄色高亮匹配部分)
|
||||
Expanded(
|
||||
child: _buildHighlightedSnippet(match, theme),
|
||||
),
|
||||
|
||||
// 行单项替换按钮:仅在展开替换输入框时展示
|
||||
if (options.mode == SearchMode.text && options.isReplaceExpanded)
|
||||
IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
style: IconButton.styleFrom(
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
minimumSize: Size.zero,
|
||||
padding: const EdgeInsets.all(3),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 22,
|
||||
minHeight: 22,
|
||||
),
|
||||
iconSize: 15,
|
||||
icon: const Icon(Icons.redo),
|
||||
tooltip: l10n.replaceSingleMatch,
|
||||
onPressed: tabProvider == null
|
||||
? null
|
||||
: () async {
|
||||
final success = await searchProvider.replaceSingleMatch(
|
||||
file: fileResult,
|
||||
match: match,
|
||||
tabProvider: tabProvider,
|
||||
);
|
||||
if (context.mounted && success) {
|
||||
DialogUtils.showSuccessToast(
|
||||
context,
|
||||
l10n.replaceSuccess(1),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
|
||||
// 文件内更多匹配项加载按钮
|
||||
if (hasMoreMatches)
|
||||
InkWell(
|
||||
onTap: () {
|
||||
searchProvider.loadMoreMatches(
|
||||
fileResult.filePath,
|
||||
SearchPanelWidget.defaultFileMatchesPageSize,
|
||||
SearchPanelWidget.defaultFileMatchesPageSize,
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(36.0, 6.0, 10.0, 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.more_horiz,
|
||||
size: 16,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.searchLoadMoreMatches(remainingMatchesCount),
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
_SearchMatchLineRowItem(:final file, :final match) =>
|
||||
_buildMatchLineTile(
|
||||
context,
|
||||
theme,
|
||||
l10n,
|
||||
file,
|
||||
match,
|
||||
searchProvider,
|
||||
tabProvider,
|
||||
options,
|
||||
),
|
||||
_SearchLoadMoreMatchesRowItem(
|
||||
:final file,
|
||||
:final remainingMatchesCount
|
||||
) =>
|
||||
_buildLoadMoreMatchesTile(
|
||||
theme,
|
||||
l10n,
|
||||
file,
|
||||
remainingMatchesCount,
|
||||
searchProvider,
|
||||
),
|
||||
_SearchLoadMoreFilesRowItem(:final remainingFilesCount) =>
|
||||
_buildLoadMoreFilesTile(
|
||||
theme,
|
||||
l10n,
|
||||
remainingFilesCount,
|
||||
searchProvider,
|
||||
),
|
||||
};
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -1206,4 +931,426 @@ class _SearchPanelWidgetState extends State<SearchPanelWidget> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建文件名/目录名匹配模式的单项条目
|
||||
Widget _buildFileNameTile(
|
||||
BuildContext context,
|
||||
ThemeData theme,
|
||||
FileSearchResult fileResult,
|
||||
TabProvider? tabProvider,
|
||||
) {
|
||||
final match = fileResult.matches.isNotEmpty ? fileResult.matches.first : null;
|
||||
final iconData = FileIconUtils.getIcon(
|
||||
name: fileResult.fileName,
|
||||
isDirectory: fileResult.isDirectory,
|
||||
);
|
||||
final dirName = p.dirname(fileResult.relativePath);
|
||||
final hasDir = dirName != '.' && dirName.isNotEmpty;
|
||||
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
if (fileResult.isDirectory) {
|
||||
final projectProvider = context.read<ProjectProvider?>();
|
||||
if (projectProvider != null) {
|
||||
final cleanRoot = projectProvider.rootPath;
|
||||
if (cleanRoot != null) {
|
||||
final updatedOpenPaths = List<String>.from(projectProvider.openDirectoryPaths);
|
||||
if (!updatedOpenPaths.contains(fileResult.filePath)) {
|
||||
updatedOpenPaths.add(fileResult.filePath);
|
||||
}
|
||||
await projectProvider.toggleDirectory(
|
||||
FileItem(
|
||||
path: fileResult.filePath,
|
||||
name: fileResult.fileName,
|
||||
relativePath: fileResult.relativePath,
|
||||
isDirectory: true,
|
||||
),
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (tabProvider != null) {
|
||||
await tabProvider.openFile(fileResult.filePath);
|
||||
}
|
||||
}
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).maybePop();
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10.0,
|
||||
vertical: 6.0,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
iconData,
|
||||
size: 18,
|
||||
color: fileResult.isDirectory
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildFileNameHighlightedTitle(
|
||||
fileResult.fileName,
|
||||
match,
|
||||
theme,
|
||||
),
|
||||
if (hasDir)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 2.0),
|
||||
child: Text(
|
||||
dirName,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.7),
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建文本匹配模式下的文件分组头部条目
|
||||
Widget _buildFileHeaderTile(
|
||||
BuildContext context,
|
||||
ThemeData theme,
|
||||
AppLocalizations l10n,
|
||||
FileSearchResult fileResult,
|
||||
SearchProvider searchProvider,
|
||||
TabProvider? tabProvider,
|
||||
SearchOptions options,
|
||||
) {
|
||||
final isExpanded = fileResult.isExpanded;
|
||||
final dirName = p.dirname(fileResult.relativePath);
|
||||
final hasDir = dirName != '.' && dirName.isNotEmpty;
|
||||
final iconData = FileIconUtils.getIcon(
|
||||
name: fileResult.fileName,
|
||||
isDirectory: fileResult.isDirectory,
|
||||
);
|
||||
|
||||
return InkWell(
|
||||
onTap: () => searchProvider.toggleFileExpanded(fileResult),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10.0,
|
||||
vertical: 6.0,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
isExpanded
|
||||
? Icons.keyboard_arrow_down
|
||||
: Icons.keyboard_arrow_right,
|
||||
size: 18,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
iconData,
|
||||
size: 16,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// 主标题文件名,副标题相对路径(一上一下)
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
fileResult.fileName,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 13,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
if (hasDir)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 2.0),
|
||||
child: Text(
|
||||
dirName,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.7),
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
|
||||
// 匹配次数 Badge
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'${fileResult.matchCount}',
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 该文件折叠项全部展开按钮:一键展开并展示该文件内所有匹配行
|
||||
IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
style: IconButton.styleFrom(
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
minimumSize: Size.zero,
|
||||
padding: const EdgeInsets.all(4),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 24,
|
||||
minHeight: 24,
|
||||
),
|
||||
iconSize: 16,
|
||||
icon: const Icon(Icons.unfold_more_rounded),
|
||||
tooltip: l10n.searchExpandAllMatchesInFile,
|
||||
onPressed: () {
|
||||
searchProvider.expandAndLoadAllMatchesForFile(fileResult);
|
||||
},
|
||||
),
|
||||
|
||||
// 文件级全部替换按钮:仅在展开替换输入框时展示
|
||||
if (options.mode == SearchMode.text && options.isReplaceExpanded)
|
||||
IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
style: IconButton.styleFrom(
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
minimumSize: Size.zero,
|
||||
padding: const EdgeInsets.all(4),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 24,
|
||||
minHeight: 24,
|
||||
),
|
||||
iconSize: 16,
|
||||
icon: const Icon(Icons.find_replace),
|
||||
tooltip: l10n.replaceAllInFile,
|
||||
onPressed: tabProvider == null
|
||||
? null
|
||||
: () async {
|
||||
final confirmed = await DialogUtils.showConfirmDialog(
|
||||
context,
|
||||
title: l10n.confirmReplaceFileTitle,
|
||||
message: l10n.confirmReplaceFileMessage(
|
||||
fileResult.fileName,
|
||||
fileResult.matchCount,
|
||||
options.replaceText,
|
||||
),
|
||||
confirmText: l10n.replaceSingleMatch,
|
||||
);
|
||||
if (!confirmed || !context.mounted) return;
|
||||
|
||||
final count = await searchProvider.replaceFileMatches(
|
||||
file: fileResult,
|
||||
tabProvider: tabProvider,
|
||||
);
|
||||
if (context.mounted && count > 0) {
|
||||
DialogUtils.showSuccessToast(
|
||||
context,
|
||||
l10n.replaceSuccess(count),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建具体代码匹配行条目
|
||||
Widget _buildMatchLineTile(
|
||||
BuildContext context,
|
||||
ThemeData theme,
|
||||
AppLocalizations l10n,
|
||||
FileSearchResult fileResult,
|
||||
LineMatch match,
|
||||
SearchProvider searchProvider,
|
||||
TabProvider? tabProvider,
|
||||
SearchOptions options,
|
||||
) {
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
if (tabProvider != null) {
|
||||
// 1. 打开文件并切换 tab
|
||||
await tabProvider.openFile(fileResult.filePath);
|
||||
// 2. 发送行定位与选区高亮事件
|
||||
tabProvider.navigateTo(
|
||||
filePath: fileResult.filePath,
|
||||
line: match.lineNumber - 1,
|
||||
column: match.matchStart,
|
||||
length: match.matchEnd - match.matchStart,
|
||||
);
|
||||
}
|
||||
// 3. 移动端抽屉收起(保留宽屏适配)
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).maybePop();
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(36.0, 4.0, 10.0, 4.0),
|
||||
child: Row(
|
||||
children: [
|
||||
// 行号
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(minWidth: 28),
|
||||
child: Text(
|
||||
'${match.lineNumber}:',
|
||||
style: TextStyle(
|
||||
fontFamily: 'JetBrains Mono',
|
||||
fontSize: 11.5,
|
||||
color: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
|
||||
// 代码文本摘要(黄色高亮匹配部分)
|
||||
Expanded(
|
||||
child: _buildHighlightedSnippet(match, theme),
|
||||
),
|
||||
|
||||
// 行单项替换按钮:仅在展开替换输入框时展示
|
||||
if (options.mode == SearchMode.text && options.isReplaceExpanded)
|
||||
IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
style: IconButton.styleFrom(
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
minimumSize: Size.zero,
|
||||
padding: const EdgeInsets.all(3),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 22,
|
||||
minHeight: 22,
|
||||
),
|
||||
iconSize: 15,
|
||||
icon: const Icon(Icons.redo),
|
||||
tooltip: l10n.replaceSingleMatch,
|
||||
onPressed: tabProvider == null
|
||||
? null
|
||||
: () async {
|
||||
final success = await searchProvider.replaceSingleMatch(
|
||||
file: fileResult,
|
||||
match: match,
|
||||
tabProvider: tabProvider,
|
||||
);
|
||||
if (context.mounted && success) {
|
||||
DialogUtils.showSuccessToast(
|
||||
context,
|
||||
l10n.replaceSuccess(1),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建文件内更多匹配项加载按钮条目
|
||||
Widget _buildLoadMoreMatchesTile(
|
||||
ThemeData theme,
|
||||
AppLocalizations l10n,
|
||||
FileSearchResult fileResult,
|
||||
int remainingMatchesCount,
|
||||
SearchProvider searchProvider,
|
||||
) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
searchProvider.loadMoreMatches(
|
||||
fileResult.filePath,
|
||||
SearchPanelWidget.defaultFileMatchesPageSize,
|
||||
SearchPanelWidget.defaultFileMatchesPageSize,
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(36.0, 6.0, 10.0, 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.more_horiz,
|
||||
size: 16,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.searchLoadMoreMatches(remainingMatchesCount),
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 扁平化虚拟条目抽象基类
|
||||
sealed class _SearchRowItem {}
|
||||
|
||||
/// 文件名检索模式条目
|
||||
class _SearchFileNameRowItem extends _SearchRowItem {
|
||||
final FileSearchResult file;
|
||||
_SearchFileNameRowItem(this.file);
|
||||
}
|
||||
|
||||
/// 文本内容检索模式下的文件分组头部条目
|
||||
class _SearchFileHeaderRowItem extends _SearchRowItem {
|
||||
final FileSearchResult file;
|
||||
_SearchFileHeaderRowItem(this.file);
|
||||
}
|
||||
|
||||
/// 文本内容检索模式下的具体代码匹配行条目
|
||||
class _SearchMatchLineRowItem extends _SearchRowItem {
|
||||
final FileSearchResult file;
|
||||
final LineMatch match;
|
||||
_SearchMatchLineRowItem(this.file, this.match);
|
||||
}
|
||||
|
||||
/// 文件内加载更多匹配项条目
|
||||
class _SearchLoadMoreMatchesRowItem extends _SearchRowItem {
|
||||
final FileSearchResult file;
|
||||
final int remainingMatchesCount;
|
||||
_SearchLoadMoreMatchesRowItem(this.file, this.remainingMatchesCount);
|
||||
}
|
||||
|
||||
/// 搜索结果底部加载更多文件条目
|
||||
class _SearchLoadMoreFilesRowItem extends _SearchRowItem {
|
||||
final int remainingFilesCount;
|
||||
_SearchLoadMoreFilesRowItem(this.remainingFilesCount);
|
||||
}
|
||||
Reference in new issue
Block a user