This commit is contained in:
LZX committed 2026-09-19 23:00:50 +08:00
1 parent 875840147d
commit a8b7bdf606
13 files changed
+2038 -16

No files matched your search

+48
View File
@@ -1365,6 +1365,54 @@
},
"gitConflictApplyOurs": "Use this",
"gitConflictApplyBoth": "Keep both",
"gitConflictResolveTitle": "Resolve Conflict",
"gitConflictBlockIndex": "Conflict {index} of {total}",
"@gitConflictBlockIndex": {
"placeholders": {
"index": {
"type": "int"
},
"total": {
"type": "int"
}
}
},
"gitConflictSectionBaseline": "Baseline (common ancestor)",
"gitConflictSectionOurs": "Current side",
"gitConflictSectionTheirs": "Incoming side",
"gitConflictTakeBoth": "Keep both",
"gitConflictEditManually": "Edit manually",
"gitConflictAllOurs": "Use current side for all",
"gitConflictAllTheirs": "Use incoming side for all",
"gitConflictSaveAndMark": "Save and mark resolved",
"gitConflictAcceptCurrent": "Accept Current Change",
"gitConflictAcceptIncoming": "Accept Incoming Change",
"gitConflictAcceptBoth": "Accept Both Changes",
"gitConflictCompare": "Compare Changes",
"gitConflictPrev": "Previous conflict",
"gitConflictNext": "Next conflict",
"gitConflictSaveAndMarkDone": "Resolved and written back",
"gitConflictNoBlocks": "No conflict markers left in this file",
"gitConflictLoadFailed": "Failed to load conflict contents",
"gitConflictUnresolvedRemain": "{count} block(s) still unresolved",
"@gitConflictUnresolvedRemain": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"gitConflictMarkWithMarkers": "{count} conflict marker(s) still remain in the file",
"@gitConflictMarkWithMarkers": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"gitConflictMarkWithMarkersHint": "Marking as resolved would commit them as normal content.",
"gitConflictMarkAnyway": "Mark anyway",
"gitConflictGoResolve": "Resolve first",
"gitRemoteBranches": "Remote Branches",
"gitLocalBranches": "Local Branches",
+144
View File
@@ -4018,6 +4018,150 @@ abstract class AppLocalizations {
/// **'两段都要'**
String get gitConflictApplyBoth;
/// No description provided for @gitConflictResolveTitle.
///
/// In zh, this message translates to:
/// **'解决冲突'**
String get gitConflictResolveTitle;
/// No description provided for @gitConflictBlockIndex.
///
/// In zh, this message translates to:
/// **'冲突 {index} / {total}'**
String gitConflictBlockIndex(int index, int total);
/// No description provided for @gitConflictSectionBaseline.
///
/// In zh, this message translates to:
/// **'基线(共同祖先)'**
String get gitConflictSectionBaseline;
/// No description provided for @gitConflictSectionOurs.
///
/// In zh, this message translates to:
/// **'当前侧'**
String get gitConflictSectionOurs;
/// No description provided for @gitConflictSectionTheirs.
///
/// In zh, this message translates to:
/// **'传入侧'**
String get gitConflictSectionTheirs;
/// No description provided for @gitConflictTakeBoth.
///
/// In zh, this message translates to:
/// **'两段都要'**
String get gitConflictTakeBoth;
/// No description provided for @gitConflictEditManually.
///
/// In zh, this message translates to:
/// **'手动编辑'**
String get gitConflictEditManually;
/// No description provided for @gitConflictAllOurs.
///
/// In zh, this message translates to:
/// **'全部采用当前侧'**
String get gitConflictAllOurs;
/// No description provided for @gitConflictAllTheirs.
///
/// In zh, this message translates to:
/// **'全部采用传入侧'**
String get gitConflictAllTheirs;
/// No description provided for @gitConflictSaveAndMark.
///
/// In zh, this message translates to:
/// **'保存并标记为已解决'**
String get gitConflictSaveAndMark;
/// No description provided for @gitConflictAcceptCurrent.
///
/// In zh, this message translates to:
/// **'采用当前侧'**
String get gitConflictAcceptCurrent;
/// No description provided for @gitConflictAcceptIncoming.
///
/// In zh, this message translates to:
/// **'采用传入侧'**
String get gitConflictAcceptIncoming;
/// No description provided for @gitConflictAcceptBoth.
///
/// In zh, this message translates to:
/// **'两段都保留'**
String get gitConflictAcceptBoth;
/// No description provided for @gitConflictCompare.
///
/// In zh, this message translates to:
/// **'对比查看'**
String get gitConflictCompare;
/// No description provided for @gitConflictPrev.
///
/// In zh, this message translates to:
/// **'上一处冲突'**
String get gitConflictPrev;
/// No description provided for @gitConflictNext.
///
/// In zh, this message translates to:
/// **'下一处冲突'**
String get gitConflictNext;
/// No description provided for @gitConflictSaveAndMarkDone.
///
/// In zh, this message translates to:
/// **'已解决并写回文件'**
String get gitConflictSaveAndMarkDone;
/// No description provided for @gitConflictNoBlocks.
///
/// In zh, this message translates to:
/// **'该文件已无冲突标记'**
String get gitConflictNoBlocks;
/// No description provided for @gitConflictLoadFailed.
///
/// In zh, this message translates to:
/// **'读取冲突内容失败'**
String get gitConflictLoadFailed;
/// No description provided for @gitConflictUnresolvedRemain.
///
/// In zh, this message translates to:
/// **'还剩 {count} 处未处理'**
String gitConflictUnresolvedRemain(int count);
/// No description provided for @gitConflictMarkWithMarkers.
///
/// In zh, this message translates to:
/// **'文件里仍残留 {count} 处冲突标记'**
String gitConflictMarkWithMarkers(int count);
/// No description provided for @gitConflictMarkWithMarkersHint.
///
/// In zh, this message translates to:
/// **'标记为已解决会把它们当作正常内容提交进仓库。建议先处理干净。'**
String get gitConflictMarkWithMarkersHint;
/// No description provided for @gitConflictMarkAnyway.
///
/// In zh, this message translates to:
/// **'仍然标记'**
String get gitConflictMarkAnyway;
/// No description provided for @gitConflictGoResolve.
///
/// In zh, this message translates to:
/// **'去处理'**
String get gitConflictGoResolve;
/// No description provided for @gitRemoteBranches.
///
/// In zh, this message translates to:
+79
View File
@@ -2394,6 +2394,85 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get gitConflictApplyBoth => 'Keep both';
@override
String get gitConflictResolveTitle => 'Resolve Conflict';
@override
String gitConflictBlockIndex(int index, int total) {
return 'Conflict $index of $total';
}
@override
String get gitConflictSectionBaseline => 'Baseline (common ancestor)';
@override
String get gitConflictSectionOurs => 'Current side';
@override
String get gitConflictSectionTheirs => 'Incoming side';
@override
String get gitConflictTakeBoth => 'Keep both';
@override
String get gitConflictEditManually => 'Edit manually';
@override
String get gitConflictAllOurs => 'Use current side for all';
@override
String get gitConflictAllTheirs => 'Use incoming side for all';
@override
String get gitConflictSaveAndMark => 'Save and mark resolved';
@override
String get gitConflictAcceptCurrent => 'Accept Current Change';
@override
String get gitConflictAcceptIncoming => 'Accept Incoming Change';
@override
String get gitConflictAcceptBoth => 'Accept Both Changes';
@override
String get gitConflictCompare => 'Compare Changes';
@override
String get gitConflictPrev => 'Previous conflict';
@override
String get gitConflictNext => 'Next conflict';
@override
String get gitConflictSaveAndMarkDone => 'Resolved and written back';
@override
String get gitConflictNoBlocks => 'No conflict markers left in this file';
@override
String get gitConflictLoadFailed => 'Failed to load conflict contents';
@override
String gitConflictUnresolvedRemain(int count) {
return '$count block(s) still unresolved';
}
@override
String gitConflictMarkWithMarkers(int count) {
return '$count conflict marker(s) still remain in the file';
}
@override
String get gitConflictMarkWithMarkersHint =>
'Marking as resolved would commit them as normal content.';
@override
String get gitConflictMarkAnyway => 'Mark anyway';
@override
String get gitConflictGoResolve => 'Resolve first';
@override
String get gitRemoteBranches => 'Remote Branches';
+78
View File
@@ -2321,6 +2321,84 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get gitConflictApplyBoth => '两段都要';
@override
String get gitConflictResolveTitle => '解决冲突';
@override
String gitConflictBlockIndex(int index, int total) {
return '冲突 $index / $total';
}
@override
String get gitConflictSectionBaseline => '基线(共同祖先)';
@override
String get gitConflictSectionOurs => '当前侧';
@override
String get gitConflictSectionTheirs => '传入侧';
@override
String get gitConflictTakeBoth => '两段都要';
@override
String get gitConflictEditManually => '手动编辑';
@override
String get gitConflictAllOurs => '全部采用当前侧';
@override
String get gitConflictAllTheirs => '全部采用传入侧';
@override
String get gitConflictSaveAndMark => '保存并标记为已解决';
@override
String get gitConflictAcceptCurrent => '采用当前侧';
@override
String get gitConflictAcceptIncoming => '采用传入侧';
@override
String get gitConflictAcceptBoth => '两段都保留';
@override
String get gitConflictCompare => '对比查看';
@override
String get gitConflictPrev => '上一处冲突';
@override
String get gitConflictNext => '下一处冲突';
@override
String get gitConflictSaveAndMarkDone => '已解决并写回文件';
@override
String get gitConflictNoBlocks => '该文件已无冲突标记';
@override
String get gitConflictLoadFailed => '读取冲突内容失败';
@override
String gitConflictUnresolvedRemain(int count) {
return '还剩 $count 处未处理';
}
@override
String gitConflictMarkWithMarkers(int count) {
return '文件里仍残留 $count 处冲突标记';
}
@override
String get gitConflictMarkWithMarkersHint => '标记为已解决会把它们当作正常内容提交进仓库。建议先处理干净。';
@override
String get gitConflictMarkAnyway => '仍然标记';
@override
String get gitConflictGoResolve => '去处理';
@override
String get gitRemoteBranches => '远端分支';
+48
View File
@@ -1365,6 +1365,54 @@
},
"gitConflictApplyOurs": "采用此段",
"gitConflictApplyBoth": "两段都要",
"gitConflictResolveTitle": "解决冲突",
"gitConflictBlockIndex": "冲突 {index} / {total}",
"@gitConflictBlockIndex": {
"placeholders": {
"index": {
"type": "int"
},
"total": {
"type": "int"
}
}
},
"gitConflictSectionBaseline": "基线(共同祖先)",
"gitConflictSectionOurs": "当前侧",
"gitConflictSectionTheirs": "传入侧",
"gitConflictTakeBoth": "两段都要",
"gitConflictEditManually": "手动编辑",
"gitConflictAllOurs": "全部采用当前侧",
"gitConflictAllTheirs": "全部采用传入侧",
"gitConflictSaveAndMark": "保存并标记为已解决",
"gitConflictAcceptCurrent": "采用当前侧",
"gitConflictAcceptIncoming": "采用传入侧",
"gitConflictAcceptBoth": "两段都保留",
"gitConflictCompare": "对比查看",
"gitConflictPrev": "上一处冲突",
"gitConflictNext": "下一处冲突",
"gitConflictSaveAndMarkDone": "已解决并写回文件",
"gitConflictNoBlocks": "该文件已无冲突标记",
"gitConflictLoadFailed": "读取冲突内容失败",
"gitConflictUnresolvedRemain": "还剩 {count} 处未处理",
"@gitConflictUnresolvedRemain": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"gitConflictMarkWithMarkers": "文件里仍残留 {count} 处冲突标记",
"@gitConflictMarkWithMarkers": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"gitConflictMarkWithMarkersHint": "标记为已解决会把它们当作正常内容提交进仓库。建议先处理干净。",
"gitConflictMarkAnyway": "仍然标记",
"gitConflictGoResolve": "去处理",
"gitRemoteBranches": "远端分支",
"gitLocalBranches": "本地分支",
+37
View File
@@ -206,4 +206,41 @@ class GitConflictParser {
static String _labelOf(String line, String marker) {
return line.length > marker.length ? line.substring(marker.length).trim() : '';
}
/// 把第 [blockIndex] 个冲突块替换为 [replacement],返回新内容
///
/// 这是"逐块解决"的核心算法,独立成纯函数以便测试:
/// - 只替换**该块的行范围**,前后内容原样保留(多块文件各块互不影响)
/// - 传入旧的 [blocks] 与 [content] 必须来自同一次解析,否则行号会错位
/// - [replacement] 为空表示"该块删掉"
///
/// 调用方应在替换后**重新解析**再处理下一块:块的行号会随替换而整体移动,
/// 维护偏移量容易出错,重解析代价可以忽略。
static String? replaceBlock({
required String content,
required List<GitConflictBlock> blocks,
required int blockIndex,
required String replacement,
}) {
if (blockIndex < 0 || blockIndex >= blocks.length) return null;
final lines = content.split('\n');
final block = blocks[blockIndex];
if (block.startLine < 0 || block.endLine >= lines.length) return null;
final before = lines.sublist(0, block.startLine);
final after = lines.sublist(block.endLine + 1);
final replacementLines =
replacement.isEmpty ? <String>[] : replacement.split('\n').toList();
// split 在内容以换行结尾时会多出一个空串,去掉以免多插空行
if (replacementLines.isNotEmpty && replacementLines.last.isEmpty) {
replacementLines.removeLast();
}
return <String>[...before, ...replacementLines, ...after].join('\n');
}
/// 统计内容中未解决的冲突块数量(不做完整解析,用于快速校验)
static int countMarkers(String content) => parse(content).blocks.length;
}
+15 -4
View File
@@ -197,10 +197,21 @@ class _FileItemWidgetState extends State<FileItemWidget> {
),
selected: isSelected,
selectedTileColor: theme.colorScheme.primaryContainer.withValues(alpha: 0.5),
leading: Icon(
_getFileIcon(item),
size: 20,
color: iconColor,
// 与文件夹项前导区对齐:文件夹有「折叠箭头 + 间距 + 图标」,
// 文件只有图标。若直接给图标,同一层级下文件图标会比文件夹图标
// 左移一个箭头的宽度(16+4),视觉上文件缩进反而更浅。
// 这里补一个等宽占位(区别于 VS Code:文件项不显示箭头),
// 使同一层级的图标与文件名严格对齐。
leading: Row(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(width: 16 + 4),
Icon(
_getFileIcon(item),
size: 20,
color: iconColor,
),
],
),
title: Text(
item.name,
+158
View File
@@ -0,0 +1,158 @@
/// 冲突页的行模型与内容组装(纯逻辑,便于单测)
///
/// 与 `git_conflict_parser.dart` 的分工:
/// - 解析器负责"标记块在文件中的位置"
/// - 这里负责"把解析结果摊平成一条条带语义的行",供 UI 直接渲染
///
/// 独立成文件的原因:VS Code 风格的内联冲突视图**完全由行渲染**组成
/// (标记行变标题带、内容行带整段底色),把"哪些行属于哪一段"算清楚
/// 是正确性的核心,而它必须可测 —— 上一版页面的内容错乱正是栽在
/// 行号映射上。
library;
import '../../utils/git_conflict_parser.dart';
/// 一行在冲突视图中的角色
enum ConflictLineRole {
/// 普通上下文行(不属于任何冲突块)
context,
/// 冲突块开头标记行(渲染为标题带 + 内联操作)
oursHeader,
/// 当前侧内容行
oursContent,
/// 基线段标题(diff3 风格;不显示操作)
baseHeader,
/// 基线段内容行
baseContent,
/// 分隔线(`=======`),渲染为极窄分隔
separator,
/// 传入侧标题带
theirsHeader,
/// 传入侧内容行
theirsContent,
}
/// 一行渲染数据
class ConflictLine {
/// 文件中的绝对行号(1-based,供行号栏显示)
final int lineNumber;
/// 该行的原始文本
final String text;
final ConflictLineRole role;
/// 若该行是一处分段的标题,这里给出它所属的冲突块序号(0-based)
final int? blockIndex;
const ConflictLine({
required this.lineNumber,
required this.text,
required this.role,
this.blockIndex,
});
bool get isHeader =>
role == ConflictLineRole.oursHeader ||
role == ConflictLineRole.baseHeader ||
role == ConflictLineRole.theirsHeader;
bool get isContent =>
role == ConflictLineRole.oursContent ||
role == ConflictLineRole.baseContent ||
role == ConflictLineRole.theirsContent;
}
/// 把冲突文件内容摊平成可渲染的行序列
class ConflictLineBuilder {
ConflictLineBuilder._();
/// 解析 [content] 并生成行序列
///
/// [parseResult] 必须与 [content] 来自同一次解析,否则行号会错位。
static List<ConflictLine> build(
String content,
GitConflictParseResult parseResult,
) {
final lines = content.split('\n');
final result = <ConflictLine>[];
// 行号 → 该行承担的段角色
final roles = List<ConflictLineRole?>.filled(lines.length, null);
final blockOfLine = List<int?>.filled(lines.length, null);
for (var b = 0; b < parseResult.blocks.length; b++) {
final block = parseResult.blocks[b];
void mark(int from, int toExclusive, ConflictLineRole role) {
for (var i = from; i < toExclusive; i++) {
if (i >= 0 && i < roles.length) {
roles[i] = role;
blockOfLine[i] = b;
}
}
}
// 起始标记行
mark(block.startLine, block.startLine + 1, ConflictLineRole.oursHeader);
// 当前侧内容
mark(
block.ours.startLine,
block.ours.endLine,
ConflictLineRole.oursContent,
);
if (block.base != null) {
// diff3:基线段(其上一行是 ||||||| 标记)
mark(
block.base!.startLine - 1,
block.base!.startLine,
ConflictLineRole.baseHeader,
);
mark(
block.base!.startLine,
block.base!.endLine,
ConflictLineRole.baseContent,
);
}
// 分隔线位于基线段结束处(有基线时)或 ours 结束处
final separatorLine = block.base != null
? block.base!.endLine
: block.ours.endLine;
mark(separatorLine, separatorLine + 1, ConflictLineRole.separator);
// 传入侧内容
mark(
block.theirs.startLine,
block.theirs.endLine,
ConflictLineRole.theirsContent,
);
// 结束标记行
mark(block.endLine, block.endLine + 1, ConflictLineRole.theirsHeader);
}
for (var i = 0; i < lines.length; i++) {
result.add(
ConflictLine(
lineNumber: i + 1,
text: lines[i],
role: roles[i] ?? ConflictLineRole.context,
blockIndex: blockOfLine[i],
),
);
}
return result;
}
/// 统计各块是否已解决(视图中没有标记块时即为完全解决)
static bool isFullyResolved(GitConflictParseResult parseResult) =>
parseResult.blocks.isEmpty;
}
+37 -7
View File
@@ -7,6 +7,7 @@ import '../../providers/git_provider.dart';
import '../../providers/tab_provider.dart';
import '../../utils/dialog_utils.dart';
import '../../utils/git_error_mapper.dart';
import 'git_conflict_resolve_page.dart';
/// 冲突解决面板(底部弹出)
///
@@ -380,11 +381,19 @@ class _ConflictFileTile extends StatelessWidget {
tooltip: l10n.gitConflictTitle,
onSelected: (action) => _handle(context, l10n, provider, action),
itemBuilder: (_) => [
if (file.canEditManually)
if (file.canEditManually) ...[
PopupMenuItem(
value: 'resolve',
child: _menuRow(
Icons.merge_type,
l10n.gitConflictResolveTitle,
),
),
PopupMenuItem(
value: 'open',
child: _menuRow(Icons.open_in_new_rounded, l10n.gitConflictOpenFile),
),
],
PopupMenuItem(
value: 'ours',
child: _menuRow(
@@ -415,8 +424,9 @@ class _ConflictFileTile extends StatelessWidget {
),
],
),
// 点击文件条目直接进入三方解决页(这是主要路径)
onTap: file.canEditManually
? () => _handle(context, l10n, provider, 'open')
? () => _openResolvePage(context, provider)
: null,
);
}
@@ -458,6 +468,9 @@ class _ConflictFileTile extends StatelessWidget {
String action,
) async {
switch (action) {
case 'resolve':
await _openResolvePage(context, provider);
break;
case 'open':
await _openInEditor(context, provider);
break;
@@ -500,6 +513,21 @@ class _ConflictFileTile extends StatelessWidget {
}
}
/// 打开三方冲突解决页(逐块选择,由程序替换而非人工删标记)
Future<void> _openResolvePage(BuildContext context, GitProvider provider) async {
await provider.refreshConflictState();
if (!context.mounted) return;
// 先收起面板与抽屉,再压入解决页 —— 否则返回时层级会错乱
Navigator.of(context).maybePop();
await Navigator.of(context).push(
GitConflictResolvePage.route(file: file, gitProvider: provider),
);
// 返回后刷新:用户可能已在解决页里标记完成
await provider.refreshConflictState();
}
/// 在编辑器中打开冲突文件
///
/// **必须先强制从磁盘重载**:Git 冲突时直接改写了工作区文件并写入标记,
@@ -509,11 +537,13 @@ class _ConflictFileTile extends StatelessWidget {
await provider.refreshConflictState();
await tabProvider.reloadTabFromDisk(file.absolutePath);
await tabProvider.openFile(file.absolutePath);
if (context.mounted) {
// 关闭面板并退出抽屉,把焦点交给编辑器
Navigator.of(context).maybePop();
Navigator.of(context).maybePop();
}
if (!context.mounted) return;
// 先收起 bottom sheet 面板,再显式关闭抽屉。
// 这里不能用连续两次 maybePop():抽屉是 Scaffold 管理的路由,
// 用 closeDrawer() 才是项目内一致且可靠的做法(见 file_item_widget)。
Navigator.of(context).maybePop();
Scaffold.maybeOf(context)?.closeDrawer();
}
Future<void> _takeSide(
File diff suppressed because it is too large. Load diff
+6 -5
View File
@@ -98,11 +98,6 @@ class _GitSyncBarState extends State<GitSyncBar> {
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
// 冲突优先于一切:此时同步动作都无法继续,必须先把冲突摆到最前面
if (gitProvider.hasPendingOperation) ...[
_buildConflictBanner(context, theme, l10n, gitProvider),
const SizedBox(height: 6),
],
// 与上方「分支」行完全一致的结构:左侧占满的选择条 + 右侧 32×32 图标按钮。
// 这样三行(分支 / 远程 / 进度)视觉对齐,宽度也天然不会溢出。
Row(
@@ -120,6 +115,12 @@ class _GitSyncBarState extends State<GitSyncBar> {
_buildSyncButton(context, theme, l10n, gitProvider),
],
),
// 冲突横幅放在远程行**下方**:它是一段需要处理的状态说明,
// 放在远程行之上会把「分支 → 远程」这两行的对应关系打断。
if (gitProvider.hasPendingOperation) ...[
const SizedBox(height: 6),
_buildConflictBanner(context, theme, l10n, gitProvider),
],
// 推送目标与上游不一致时的提示:单独占一行。
// 绝不能塞进上面的选择条 —— 那是第三个抢宽度的元素,会把远程名挤到溢出。
if (differs) ...[