1
This commit is contained in:
1 parent
7a3db86a10
commit
3df0cbc7c0
10 files changed
+892
-38
No files matched your search
@@ -301,16 +301,24 @@ class ProjectProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> paste(FileItem targetDir) async {
|
||||
if(!targetDir.isDirectory) return;
|
||||
if (!targetDir.isDirectory) return;
|
||||
await pasteToDirectory(targetDir.path);
|
||||
}
|
||||
|
||||
if(_cutItem != null) {
|
||||
Future<void> pasteToRoot() async {
|
||||
if (rootPath == null || !canPaste) return;
|
||||
await pasteToDirectory(rootPath!);
|
||||
}
|
||||
|
||||
Future<void> pasteToDirectory(String dirPath) async {
|
||||
if (_cutItem != null) {
|
||||
final source = _cutItem!;
|
||||
await FileService.instance.moveEntity(source.path, targetDir.path);
|
||||
await FileService.instance.moveEntity(source.path, dirPath);
|
||||
_cutItem = null;
|
||||
await refreshTree();
|
||||
}else if (_copiedItem != null) {
|
||||
} else if (_copiedItem != null) {
|
||||
final source = _copiedItem!;
|
||||
await FileService.instance.copyEntity(source.path, targetDir.path);
|
||||
await FileService.instance.copyEntity(source.path, dirPath);
|
||||
await refreshTree();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,10 +157,14 @@ class GitService {
|
||||
}
|
||||
}
|
||||
|
||||
/// 自动确保 Git 基础配置就绪(safe.directory 豁免 + 默认提交者占位符)
|
||||
/// 自动确保 Git 基础配置就绪(safe.directory 豁免 + 默认提交者占位符 + 避免 link2symlink 逃逸)
|
||||
Future<void> ensureGitUserConfigured() async {
|
||||
try {
|
||||
await _runProcess('git', ['config', '--global', '--add', 'safe.directory', '*']);
|
||||
// 核心修复:强制 Git 使用 rename 而非 link() 创建对象,
|
||||
// 根除 PRoot --link2symlink 将对象伪装软链接放入容器内部 rootfs/.l2s,
|
||||
// 保证容器重建时项目目录内的 Git loose objects 绝不会丢失!
|
||||
await _runProcess('git', ['config', '--global', 'core.createObject', 'rename']);
|
||||
final nameCheck = await _runProcess('git', ['config', '--global', 'user.name']);
|
||||
if (nameCheck.stdout.toString().trim().isEmpty) {
|
||||
await _runProcess('git', ['config', '--global', 'user.name', 'CodeEditor User']);
|
||||
@@ -495,16 +499,39 @@ class GitService {
|
||||
}
|
||||
}
|
||||
|
||||
/// 删除本地分支 (`git branch -d` / `-D`)
|
||||
/// 删除本地分支 (`git branch -d` / `-D`),支持强力清理坏损无对象分支
|
||||
Future<GitCommandResult> deleteBranch(
|
||||
String repoPath,
|
||||
String branchName, {
|
||||
bool force = false,
|
||||
}) async {
|
||||
return runGitCommand(
|
||||
final res = await runGitCommand(
|
||||
['branch', force ? '-D' : '-d', branchName],
|
||||
workingDir: repoPath,
|
||||
);
|
||||
if (res.success) return res;
|
||||
|
||||
// 针对树对象损坏或缺失的分支(如 fatal: reference is not a tree),
|
||||
// 允许通过物理删除 .git/refs/heads/<branchName> 解除阻断
|
||||
if (force ||
|
||||
res.stderr.contains('reference is not a tree') ||
|
||||
res.stderr.contains('not a valid object name') ||
|
||||
res.stderr.contains('unable to resolve reference')) {
|
||||
try {
|
||||
final refFile = File(p.join(repoPath, '.git', 'refs', 'heads', branchName));
|
||||
if (refFile.existsSync()) {
|
||||
refFile.deleteSync();
|
||||
return const GitCommandResult(
|
||||
success: true,
|
||||
exitCode: 0,
|
||||
stdout: 'Deleted damaged branch reference',
|
||||
stderr: '',
|
||||
);
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/// 获取本地标签列表 (`git tag -l`)
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../l10n/app_localizations.dart';
|
||||
@@ -106,7 +107,28 @@ class InternalEngineService extends ChangeNotifier {
|
||||
// 2. 清理终端中属于 ubuntu 的活跃会话
|
||||
terminalProvider?.removeSessionsForDistro(DistroRepository.defaultSystemName);
|
||||
|
||||
// 3. 彻底删除 ubuntu 容器目录
|
||||
// 3. 保护 .l2s 目录,避免外部工程中已建立的 PRoot 硬链接替身文件随容器重装被误删
|
||||
Directory? preservedL2s;
|
||||
try {
|
||||
final currentRootfs = await DistroManager().getSystemRootDir(DistroRepository.defaultSystemName);
|
||||
final oldL2s = Directory(p.join(currentRootfs.path, '.l2s'));
|
||||
if (oldL2s.existsSync()) {
|
||||
final tempDir = await getTemporaryDirectory();
|
||||
final backupDir = Directory(p.join(tempDir.path, 'preserved_l2s_${DateTime.now().millisecondsSinceEpoch}'));
|
||||
backupDir.createSync(recursive: true);
|
||||
final entries = oldL2s.listSync();
|
||||
for (final entry in entries) {
|
||||
if (entry is File) {
|
||||
entry.copySync(p.join(backupDir.path, p.basename(entry.path)));
|
||||
}
|
||||
}
|
||||
preservedL2s = backupDir;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('备份 .l2s 异常 (非阻塞): $e');
|
||||
}
|
||||
|
||||
// 彻底删除 ubuntu 容器目录
|
||||
if (customEngineDir != null) {
|
||||
if (customEngineDir!.existsSync()) {
|
||||
customEngineDir!.deleteSync(recursive: true);
|
||||
@@ -135,6 +157,29 @@ class InternalEngineService extends ChangeNotifier {
|
||||
},
|
||||
);
|
||||
|
||||
// 5. 还原被保护的 .l2s 替身目录到新解压的容器中
|
||||
if (success && preservedL2s != null && preservedL2s.existsSync()) {
|
||||
try {
|
||||
final newRootfs = await DistroManager().getSystemRootDir(DistroRepository.defaultSystemName);
|
||||
final newL2s = Directory(p.join(newRootfs.path, '.l2s'));
|
||||
if (!newL2s.existsSync()) {
|
||||
newL2s.createSync(recursive: true);
|
||||
}
|
||||
for (final entity in preservedL2s.listSync()) {
|
||||
if (entity is File) {
|
||||
final target = p.join(newL2s.path, p.basename(entity.path));
|
||||
if (!File(target).existsSync()) {
|
||||
entity.copySync(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
preservedL2s.deleteSync(recursive: true);
|
||||
debugPrint('成功恢复 .l2s 替身目录到新容器');
|
||||
} catch (e) {
|
||||
debugPrint('恢复 .l2s 目录异常: $e');
|
||||
}
|
||||
}
|
||||
|
||||
_isChecking = false;
|
||||
notifyListeners();
|
||||
return success;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math' as math;
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// 差异行类型
|
||||
enum DiffLineType {
|
||||
@@ -63,8 +64,140 @@ class SplitDiffResult {
|
||||
});
|
||||
}
|
||||
|
||||
/// 编辑区行号栏 Git 差异提示类型(对标 VS Code)
|
||||
enum GitGutterDiffType {
|
||||
/// 修改行(黄色/Amber)
|
||||
modified,
|
||||
|
||||
/// 新增行(绿色/Green)
|
||||
added,
|
||||
|
||||
/// 删除标记(红色/Red)
|
||||
deleted,
|
||||
}
|
||||
|
||||
/// Git Diff 算法与行对齐计算工具类
|
||||
class GitDiffHelper {
|
||||
/// 计算编辑区每一行的 Git 差异标记映射(0-based 行号 -> 差异类型)
|
||||
static Map<int, GitGutterDiffType> computeLineDiff(
|
||||
String baseContent,
|
||||
String currentContent,
|
||||
) {
|
||||
if (baseContent == currentContent) return const {};
|
||||
|
||||
final originalLines = splitLines(baseContent);
|
||||
final currentLines = splitLines(currentContent);
|
||||
if (originalLines.isEmpty && currentLines.isEmpty) return const {};
|
||||
|
||||
if (originalLines.isEmpty) {
|
||||
final map = <int, GitGutterDiffType>{};
|
||||
for (int i = 0; i < currentLines.length; i++) {
|
||||
map[i] = GitGutterDiffType.added;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
if (currentLines.isEmpty) {
|
||||
return {0: GitGutterDiffType.deleted};
|
||||
}
|
||||
|
||||
// 1. 公共前后缀双向 O(1) 快速收缩剪枝 (与 Myers Diff 对齐,规避大文件整屏计算与误判)
|
||||
int prefixCount = 0;
|
||||
while (prefixCount < originalLines.length &&
|
||||
prefixCount < currentLines.length &&
|
||||
originalLines[prefixCount] == currentLines[prefixCount]) {
|
||||
prefixCount++;
|
||||
}
|
||||
|
||||
int suffixCount = 0;
|
||||
while (suffixCount < (originalLines.length - prefixCount) &&
|
||||
suffixCount < (currentLines.length - prefixCount) &&
|
||||
originalLines[originalLines.length - 1 - suffixCount] ==
|
||||
currentLines[currentLines.length - 1 - suffixCount]) {
|
||||
suffixCount++;
|
||||
}
|
||||
|
||||
// 若前后缀完全覆盖,内容完全一致
|
||||
if (prefixCount == originalLines.length && prefixCount == currentLines.length) {
|
||||
return const {};
|
||||
}
|
||||
|
||||
final middleOrig = originalLines.sublist(
|
||||
prefixCount,
|
||||
originalLines.length - suffixCount,
|
||||
);
|
||||
final middleCurr = currentLines.sublist(
|
||||
prefixCount,
|
||||
currentLines.length - suffixCount,
|
||||
);
|
||||
|
||||
final diffOps = _computeDiffOperations(middleOrig, middleCurr);
|
||||
final markers = <int, GitGutterDiffType>{};
|
||||
|
||||
int currentLineIndex = prefixCount;
|
||||
int opIndex = 0;
|
||||
|
||||
while (opIndex < diffOps.length) {
|
||||
final op = diffOps[opIndex];
|
||||
if (op.type == _DiffOpType.equal) {
|
||||
currentLineIndex++;
|
||||
opIndex++;
|
||||
} else {
|
||||
int deleteCount = 0;
|
||||
int insertCount = 0;
|
||||
while (opIndex < diffOps.length && diffOps[opIndex].type != _DiffOpType.equal) {
|
||||
if (diffOps[opIndex].type == _DiffOpType.delete) {
|
||||
deleteCount++;
|
||||
} else if (diffOps[opIndex].type == _DiffOpType.insert) {
|
||||
insertCount++;
|
||||
}
|
||||
opIndex++;
|
||||
}
|
||||
|
||||
if (deleteCount > 0 && insertCount > 0) {
|
||||
final modifiedLinesCount = math.min(deleteCount, insertCount);
|
||||
for (int i = 0; i < modifiedLinesCount; i++) {
|
||||
markers[currentLineIndex + i] = GitGutterDiffType.modified;
|
||||
}
|
||||
for (int i = modifiedLinesCount; i < insertCount; i++) {
|
||||
markers[currentLineIndex + i] = GitGutterDiffType.added;
|
||||
}
|
||||
currentLineIndex += insertCount;
|
||||
} else if (insertCount > 0) {
|
||||
for (int i = 0; i < insertCount; i++) {
|
||||
markers[currentLineIndex + i] = GitGutterDiffType.added;
|
||||
}
|
||||
currentLineIndex += insertCount;
|
||||
} else if (deleteCount > 0) {
|
||||
final targetLine = currentLineIndex < currentLines.length
|
||||
? currentLineIndex
|
||||
: math.max(0, currentLines.length - 1);
|
||||
markers.putIfAbsent(targetLine, () => GitGutterDiffType.deleted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return markers;
|
||||
}
|
||||
|
||||
/// 异步计算编辑区 Git 差异(在大文件或复杂改动时将计算丢入后台 Isolate,保障主线程 60fps)
|
||||
static Future<Map<int, GitGutterDiffType>> computeLineDiffAsync(
|
||||
String baseContent,
|
||||
String currentContent,
|
||||
) async {
|
||||
if (baseContent == currentContent) return const {};
|
||||
if (baseContent.length < 32768 && currentContent.length < 32768) {
|
||||
return computeLineDiff(baseContent, currentContent);
|
||||
}
|
||||
return compute<_DiffInputPayload, Map<int, GitGutterDiffType>>(
|
||||
_computeLineDiffEntry,
|
||||
_DiffInputPayload(baseContent, currentContent),
|
||||
);
|
||||
}
|
||||
|
||||
/// 公开的按行分割函数
|
||||
static List<String> splitLines(String text) => _splitLines(text);
|
||||
|
||||
/// 计算双屏并排对齐结果
|
||||
static SplitDiffResult computeSplitDiff(String originalText, String modifiedText) {
|
||||
final originalLines = _splitLines(originalText);
|
||||
@@ -222,12 +355,49 @@ class GitDiffHelper {
|
||||
final originalLines = _splitLines(originalText);
|
||||
final modifiedLines = _splitLines(modifiedText);
|
||||
|
||||
final diffOps = _computeDiffOperations(originalLines, modifiedLines);
|
||||
// 公共前缀快速收缩剪枝
|
||||
int prefixCount = 0;
|
||||
while (prefixCount < originalLines.length &&
|
||||
prefixCount < modifiedLines.length &&
|
||||
originalLines[prefixCount] == modifiedLines[prefixCount]) {
|
||||
prefixCount++;
|
||||
}
|
||||
|
||||
// 公共后缀快速收缩剪枝
|
||||
int suffixCount = 0;
|
||||
while (suffixCount < (originalLines.length - prefixCount) &&
|
||||
suffixCount < (modifiedLines.length - prefixCount) &&
|
||||
originalLines[originalLines.length - 1 - suffixCount] ==
|
||||
modifiedLines[modifiedLines.length - 1 - suffixCount]) {
|
||||
suffixCount++;
|
||||
}
|
||||
|
||||
final result = <UnifiedDiffLine>[];
|
||||
|
||||
int origLineNo = 1;
|
||||
int modLineNo = 1;
|
||||
|
||||
// 1. 前缀相同部分
|
||||
for (int i = 0; i < prefixCount; i++) {
|
||||
result.add(UnifiedDiffLine(
|
||||
type: DiffLineType.unchanged,
|
||||
text: originalLines[i],
|
||||
oldLineNumber: origLineNo++,
|
||||
newLineNumber: modLineNo++,
|
||||
));
|
||||
}
|
||||
|
||||
// 2. 中间差异部分
|
||||
final middleOrig = originalLines.sublist(
|
||||
prefixCount,
|
||||
originalLines.length - suffixCount,
|
||||
);
|
||||
final middleMod = modifiedLines.sublist(
|
||||
prefixCount,
|
||||
modifiedLines.length - suffixCount,
|
||||
);
|
||||
|
||||
final diffOps = _computeDiffOperations(middleOrig, middleMod);
|
||||
for (final op in diffOps) {
|
||||
switch (op.type) {
|
||||
case _DiffOpType.equal:
|
||||
@@ -257,6 +427,17 @@ class GitDiffHelper {
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 后缀相同部分
|
||||
final origSuffixStart = originalLines.length - suffixCount;
|
||||
for (int i = 0; i < suffixCount; i++) {
|
||||
result.add(UnifiedDiffLine(
|
||||
type: DiffLineType.unchanged,
|
||||
text: originalLines[origSuffixStart + i],
|
||||
oldLineNumber: origLineNo++,
|
||||
newLineNumber: modLineNo++,
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -329,3 +510,14 @@ class _DiffOp {
|
||||
|
||||
_DiffOp(this.type, this.text);
|
||||
}
|
||||
|
||||
class _DiffInputPayload {
|
||||
final String baseContent;
|
||||
final String currentContent;
|
||||
|
||||
const _DiffInputPayload(this.baseContent, this.currentContent);
|
||||
}
|
||||
|
||||
Map<int, GitGutterDiffType> _computeLineDiffEntry(_DiffInputPayload payload) {
|
||||
return GitDiffHelper.computeLineDiff(payload.baseContent, payload.currentContent);
|
||||
}
|
||||
@@ -157,7 +157,14 @@ class SyntaxHighlightHelper {
|
||||
}
|
||||
final definition = builtinAllLanguages[langId];
|
||||
if (definition != null) {
|
||||
final mode = CodeHighlightThemeMode(mode: definition);
|
||||
// 对标 VS Code 性能保护策略:
|
||||
// 1. 文件文本超过 2MB 时,安全降级为纯文本,防止巨型语法树引发主线程垃圾回收暂停;
|
||||
// 2. 单行超过 4096 字符(如压缩混淆 JSON/JS)时,安全截断单行复杂正则回溯与跨 Isolate 数组序列化。
|
||||
final mode = CodeHighlightThemeMode(
|
||||
mode: definition,
|
||||
maxSize: 2 * 1024 * 1024,
|
||||
maxLineLength: 4096,
|
||||
);
|
||||
_modeCache[langId] = mode;
|
||||
return mode;
|
||||
}
|
||||
@@ -197,6 +204,10 @@ class SyntaxHighlightHelper {
|
||||
if (code.isEmpty) {
|
||||
return TextSpan(text: '', style: baseStyle);
|
||||
}
|
||||
// 性能防御:单行超出 2048 字符(如压缩 JSON/数据行)在 Diff 视图中降级为纯文本,防止每帧重绘卡顿
|
||||
if (code.length > 2048) {
|
||||
return TextSpan(text: code, style: baseStyle);
|
||||
}
|
||||
final langId = getLanguageId(filePath);
|
||||
if (langId == null) {
|
||||
return TextSpan(text: code, style: baseStyle);
|
||||
|
||||
@@ -139,6 +139,29 @@ class _CodeEditorDrawerState extends State<CodeEditorDrawer> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handlePasteToRoot(
|
||||
BuildContext context,
|
||||
ProjectProvider provider,
|
||||
) async {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
try {
|
||||
await provider.pasteToRoot();
|
||||
if (context.mounted) {
|
||||
DialogUtils.showSuccessToast(
|
||||
context,
|
||||
l10n?.operationSuccess ?? '操作成功',
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
DialogUtils.showErrorToast(
|
||||
context,
|
||||
l10n?.operationFailed(e.toString()) ?? '操作失败: $e',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildActivityBarItem({
|
||||
required BuildContext context,
|
||||
required int index,
|
||||
@@ -287,6 +310,7 @@ class _CodeEditorDrawerState extends State<CodeEditorDrawer> {
|
||||
String? rootPath,
|
||||
bool hasProject,
|
||||
) {
|
||||
final projectProvider = _getProjectProvider(context, listen: true);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
@@ -471,6 +495,25 @@ class _CodeEditorDrawerState extends State<CodeEditorDrawer> {
|
||||
onPressed: () =>
|
||||
_handleImportFiles(context, rootPath!),
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
style: IconButton.styleFrom(
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
minimumSize: Size.zero,
|
||||
padding: const EdgeInsets.all(3),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 24,
|
||||
minHeight: 24,
|
||||
),
|
||||
iconSize: 18,
|
||||
icon: const Icon(Icons.paste_outlined),
|
||||
tooltip: l10n.paste,
|
||||
onPressed: projectProvider.canPaste
|
||||
? () => _handlePasteToRoot(context, projectProvider)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/models/app_font.dart';
|
||||
import 'package:code_editor/models/editor_tab_item.dart';
|
||||
import 'package:code_editor/models/editor_theme.dart';
|
||||
import 'package:code_editor/models/virtual_keyboard_config.dart';
|
||||
import 'package:code_editor/models/git_model.dart';
|
||||
import 'package:code_editor/models/search_model.dart';
|
||||
import 'package:code_editor/providers/git_provider.dart';
|
||||
import 'package:code_editor/providers/search_provider.dart';
|
||||
import 'package:code_editor/providers/settings_provider.dart';
|
||||
import 'package:code_editor/providers/tab_provider.dart';
|
||||
@@ -16,7 +19,9 @@ import 'package:code_editor/services/lsp/lsp_manager.dart';
|
||||
import 'package:code_editor/services/lsp/lsp_protocol.dart';
|
||||
import 'package:code_editor/utils/case_utils.dart';
|
||||
import 'package:code_editor/utils/dialog_utils.dart';
|
||||
import 'package:code_editor/utils/git_diff_helper.dart';
|
||||
import 'package:code_editor/utils/syntax_highlight_helper.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:code_editor/widgets/code_autocomplete_view.dart';
|
||||
import 'package:code_editor/widgets/code_editor_menu.dart';
|
||||
import 'package:code_editor/widgets/editor/editor_diagnostic_controller.dart';
|
||||
@@ -24,6 +29,7 @@ import 'package:code_editor/widgets/editor/editor_lsp_coordinator.dart';
|
||||
import 'package:code_editor/widgets/editor/editor_overlay_scope.dart';
|
||||
import 'package:code_editor/widgets/virtual_keyboard_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -60,6 +66,159 @@ class _DiagnosticGutterDotPainter extends BoxPainter {
|
||||
}
|
||||
}
|
||||
|
||||
/// 编辑区行号栏与代码折叠箭头之间的 Git 差异条指示器(对标 VS Code)
|
||||
class GitDiffGutterIndicator extends LeafRenderObjectWidget {
|
||||
final double width;
|
||||
final CodeIndicatorValueNotifier notifier;
|
||||
final ValueListenable<Map<int, GitGutterDiffType>> diffMarkers;
|
||||
|
||||
const GitDiffGutterIndicator({
|
||||
super.key,
|
||||
required this.width,
|
||||
required this.notifier,
|
||||
required this.diffMarkers,
|
||||
});
|
||||
|
||||
@override
|
||||
RenderObject createRenderObject(BuildContext context) => GitDiffGutterIndicatorRenderObject(
|
||||
width: width,
|
||||
notifier: notifier,
|
||||
diffMarkers: diffMarkers,
|
||||
);
|
||||
|
||||
@override
|
||||
void updateRenderObject(BuildContext context, covariant GitDiffGutterIndicatorRenderObject renderObject) {
|
||||
renderObject
|
||||
..width = width
|
||||
..notifier = notifier
|
||||
..diffMarkers = diffMarkers;
|
||||
super.updateRenderObject(context, renderObject);
|
||||
}
|
||||
}
|
||||
|
||||
class GitDiffGutterIndicatorRenderObject extends RenderBox {
|
||||
double _width;
|
||||
CodeIndicatorValueNotifier _notifier;
|
||||
ValueListenable<Map<int, GitGutterDiffType>> _diffMarkers;
|
||||
|
||||
GitDiffGutterIndicatorRenderObject({
|
||||
required double width,
|
||||
required CodeIndicatorValueNotifier notifier,
|
||||
required ValueListenable<Map<int, GitGutterDiffType>> diffMarkers,
|
||||
}) : _width = width,
|
||||
_notifier = notifier,
|
||||
_diffMarkers = diffMarkers;
|
||||
|
||||
set width(double val) {
|
||||
if (_width == val) return;
|
||||
_width = val;
|
||||
markNeedsLayout();
|
||||
}
|
||||
|
||||
set notifier(CodeIndicatorValueNotifier val) {
|
||||
if (_notifier == val) return;
|
||||
if (attached) _notifier.removeListener(markNeedsPaint);
|
||||
_notifier = val;
|
||||
if (attached) _notifier.addListener(markNeedsPaint);
|
||||
markNeedsPaint();
|
||||
}
|
||||
|
||||
set diffMarkers(ValueListenable<Map<int, GitGutterDiffType>> val) {
|
||||
if (_diffMarkers == val) return;
|
||||
if (attached) _diffMarkers.removeListener(markNeedsPaint);
|
||||
_diffMarkers = val;
|
||||
if (attached) _diffMarkers.addListener(markNeedsPaint);
|
||||
markNeedsPaint();
|
||||
}
|
||||
|
||||
@override
|
||||
void attach(covariant PipelineOwner owner) {
|
||||
_notifier.addListener(markNeedsPaint);
|
||||
_diffMarkers.addListener(markNeedsPaint);
|
||||
super.attach(owner);
|
||||
}
|
||||
|
||||
@override
|
||||
void detach() {
|
||||
_notifier.removeListener(markNeedsPaint);
|
||||
_diffMarkers.removeListener(markNeedsPaint);
|
||||
super.detach();
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicWidth(double height) => _width;
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicWidth(double height) => _width;
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicHeight(double width) => 0.0;
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double width) => 0.0;
|
||||
|
||||
@override
|
||||
Size computeDryLayout(BoxConstraints constraints) {
|
||||
return constraints.constrain(Size(_width, constraints.maxHeight));
|
||||
}
|
||||
|
||||
@override
|
||||
void performLayout() {
|
||||
size = constraints.constrain(Size(_width, constraints.maxHeight));
|
||||
}
|
||||
|
||||
@override
|
||||
void paint(PaintingContext context, Offset offset) {
|
||||
final Canvas canvas = context.canvas;
|
||||
final CodeIndicatorValue? value = _notifier.value;
|
||||
if (value == null || value.paragraphs.isEmpty) return;
|
||||
|
||||
final markers = _diffMarkers.value;
|
||||
if (markers.isEmpty) return;
|
||||
|
||||
final paint = Paint()..style = PaintingStyle.fill;
|
||||
|
||||
canvas.save();
|
||||
canvas.clipRect(Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height));
|
||||
|
||||
for (final CodeLineRenderParagraph paragraph in value.paragraphs) {
|
||||
final markerType = markers[paragraph.index];
|
||||
if (markerType == null) continue;
|
||||
|
||||
final top = offset.dy + paragraph.offset.dy;
|
||||
final height = paragraph.preferredLineHeight;
|
||||
|
||||
switch (markerType) {
|
||||
case GitGutterDiffType.modified:
|
||||
paint.color = const Color(0xFFE2B340); // 黄色/琥珀色
|
||||
canvas.drawRect(
|
||||
Rect.fromLTWH(offset.dx + 1.0, top, 3.0, height),
|
||||
paint,
|
||||
);
|
||||
break;
|
||||
case GitGutterDiffType.added:
|
||||
paint.color = const Color(0xFF2EA043); // 绿色
|
||||
canvas.drawRect(
|
||||
Rect.fromLTWH(offset.dx + 1.0, top, 3.0, height),
|
||||
paint,
|
||||
);
|
||||
break;
|
||||
case GitGutterDiffType.deleted:
|
||||
paint.color = const Color(0xFFF85149); // 红色删除三角形
|
||||
final path = Path()
|
||||
..moveTo(offset.dx + 1.0, top)
|
||||
..lineTo(offset.dx + 4.5, top + 3.0)
|
||||
..lineTo(offset.dx + 1.0, top + 6.0)
|
||||
..close();
|
||||
canvas.drawPath(path, paint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
|
||||
class CodeEditorWidget extends StatefulWidget {
|
||||
final String? rootPath;
|
||||
final String? filePath;
|
||||
@@ -98,6 +257,12 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
bool _isShowingConflictDialog = false;
|
||||
int _currentCursorLine = -1;
|
||||
|
||||
// Git 行差异状态管理(对标 VS Code 实时黄绿高亮)
|
||||
String? _gitBaseContent;
|
||||
final ValueNotifier<Map<int, GitGutterDiffType>> _gitLineMarkers = ValueNotifier(const {});
|
||||
Timer? _gitDiffDebounceTimer;
|
||||
String? _lastGitStateKey;
|
||||
|
||||
// 双指捏合实时缩放字号及中心锚定状态
|
||||
final GlobalKey _editorContainerKey = GlobalKey();
|
||||
final Map<int, Offset> _pointerPositions = {};
|
||||
@@ -654,6 +819,66 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
_handleFindNext();
|
||||
}
|
||||
|
||||
Future<void> _updateGitBaseContent() async {
|
||||
final path = _currentLoadedPath;
|
||||
if (path == null) {
|
||||
_gitBaseContent = null;
|
||||
if (_gitLineMarkers.value.isNotEmpty) _gitLineMarkers.value = const {};
|
||||
return;
|
||||
}
|
||||
GitProvider? gitProvider;
|
||||
try {
|
||||
gitProvider = context.read<GitProvider?>();
|
||||
} catch (_) {}
|
||||
final repoPath = gitProvider?.currentRepoPath;
|
||||
if (repoPath == null || !p.isWithin(repoPath, path)) {
|
||||
_gitBaseContent = null;
|
||||
if (_gitLineMarkers.value.isNotEmpty) _gitLineMarkers.value = const {};
|
||||
return;
|
||||
}
|
||||
final relPath = p.relative(path, from: repoPath).replaceAll(r'\', '/');
|
||||
try {
|
||||
final content = await gitProvider!.gitService.getFileContentAtRef(repoPath, ':0', relPath)
|
||||
?? await gitProvider.gitService.getFileContentAtRef(repoPath, 'HEAD', relPath);
|
||||
if (!mounted || _currentLoadedPath != path) return;
|
||||
_gitBaseContent = content?.replaceAll('\r\n', '\n');
|
||||
_recomputeGitDiff();
|
||||
} catch (_) {
|
||||
_gitBaseContent = null;
|
||||
_recomputeGitDiff();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _recomputeGitDiff() async {
|
||||
if (!mounted || _controller == null) return;
|
||||
if (_gitBaseContent == null) {
|
||||
GitProvider? gitProvider;
|
||||
try {
|
||||
gitProvider = context.read<GitProvider?>();
|
||||
} catch (_) {}
|
||||
final path = _currentLoadedPath;
|
||||
if (path != null && gitProvider != null) {
|
||||
final status = gitProvider.getFileStatus(path);
|
||||
if (status?.statusType == GitFileStatusType.untracked) {
|
||||
final linesCount = _controller!.codeLines.length;
|
||||
final markers = <int, GitGutterDiffType>{};
|
||||
for (int i = 0; i < linesCount; i++) {
|
||||
markers[i] = GitGutterDiffType.added;
|
||||
}
|
||||
if (mounted) _gitLineMarkers.value = markers;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (_gitLineMarkers.value.isNotEmpty) _gitLineMarkers.value = const {};
|
||||
return;
|
||||
}
|
||||
final currentText = _controller!.text.replaceAll('\r\n', '\n');
|
||||
final markers = await GitDiffHelper.computeLineDiffAsync(_gitBaseContent!, currentText);
|
||||
if (mounted) {
|
||||
_gitLineMarkers.value = markers;
|
||||
}
|
||||
}
|
||||
|
||||
void _onDiagnosticsChanged() {
|
||||
if (!mounted || _controller == null) return;
|
||||
_controller?.forceRepaint();
|
||||
@@ -718,6 +943,8 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
_scrollController?.dispose();
|
||||
_findController?.dispose();
|
||||
_findController = null;
|
||||
_gitDiffDebounceTimer?.cancel();
|
||||
_gitLineMarkers.dispose();
|
||||
_controller?.removeListener(_onTextChanged);
|
||||
_controller?.dispose();
|
||||
_focusNode.dispose();
|
||||
@@ -778,6 +1005,11 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
} else {
|
||||
notifyProvider();
|
||||
}
|
||||
|
||||
_gitDiffDebounceTimer?.cancel();
|
||||
_gitDiffDebounceTimer = Timer(const Duration(milliseconds: 150), () {
|
||||
if (mounted) _recomputeGitDiff();
|
||||
});
|
||||
}
|
||||
|
||||
/// 依据 LSP 实时诊断结果,为当前行的代码文本施加波浪下划线(保留已有代码高亮色彩)
|
||||
@@ -914,6 +1146,20 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
final gitProvider = context.watch<GitProvider?>();
|
||||
final currentStatus = (_currentLoadedPath != null && gitProvider != null)
|
||||
? gitProvider.getFileStatus(_currentLoadedPath!)
|
||||
: null;
|
||||
final gitStateKey = '${gitProvider?.currentRepoPath}_${gitProvider?.currentBranch}_${currentStatus?.statusType}_${currentStatus?.isStaged}_${currentStatus?.originalPath}_${gitProvider?.totalChangedCount}';
|
||||
if (_lastGitStateKey != gitStateKey) {
|
||||
_lastGitStateKey = gitStateKey;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) _updateGitBaseContent();
|
||||
});
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final hasNoProject = widget.rootPath == null || widget.rootPath!.trim().isEmpty;
|
||||
final hasNoFile = widget.filePath == null || widget.filePath!.trim().isEmpty;
|
||||
@@ -1097,6 +1343,11 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
GitDiffGutterIndicator(
|
||||
width: 5.0,
|
||||
notifier: notifier,
|
||||
diffMarkers: _gitLineMarkers,
|
||||
),
|
||||
DefaultCodeChunkIndicator(
|
||||
width: 20,
|
||||
controller: chunkController,
|
||||
@@ -1186,6 +1437,8 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
|
||||
if (hasNoFile) {
|
||||
_currentLoadedPath = null;
|
||||
_gitBaseContent = null;
|
||||
if (_gitLineMarkers.value.isNotEmpty) _gitLineMarkers.value = const {};
|
||||
_controller?.removeListener(_onTextChanged);
|
||||
_controller?.dispose();
|
||||
_controller = null;
|
||||
@@ -1291,6 +1544,7 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
if (mounted) {
|
||||
_handleNavigationTarget(provider);
|
||||
_syncSearchHighlight(searchProvider);
|
||||
_updateGitBaseContent();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1316,13 +1570,22 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
return;
|
||||
}
|
||||
|
||||
// 大文本异步分行:对于超过 64KB 的文本在后台 Isolate 完成解析,彻底杜绝主 UI 线程掉帧
|
||||
final CodeLines codeLines = diskContent.length > 65536
|
||||
? await diskContent.codeLinesAsync
|
||||
: diskContent.codeLines;
|
||||
|
||||
if (!mounted || requestVersion != _currentLoadVersion) {
|
||||
return;
|
||||
}
|
||||
|
||||
final oldController = _controller;
|
||||
oldController?.removeListener(_onTextChanged);
|
||||
|
||||
final newController = CodeLineEditingController.fromText(
|
||||
diskContent,
|
||||
CodeLineOptions(indentSize: activeIndentSize),
|
||||
_buildDiagnosticSpans,
|
||||
final newController = CodeLineEditingController(
|
||||
codeLines: codeLines,
|
||||
options: CodeLineOptions(indentSize: activeIndentSize),
|
||||
spanBuilder: _buildDiagnosticSpans,
|
||||
);
|
||||
|
||||
_controller = newController;
|
||||
@@ -1343,12 +1606,15 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
_currentIndentSize = activeIndentSize;
|
||||
_errorMessage = null;
|
||||
|
||||
_lspCoordinator.onFileOpened(
|
||||
fullFilePath,
|
||||
diskContent,
|
||||
newController.codeLines,
|
||||
workspaceRoot: widget.rootPath,
|
||||
);
|
||||
Future.microtask(() {
|
||||
if (!mounted || _currentLoadedPath != fullFilePath) return;
|
||||
_lspCoordinator.onFileOpened(
|
||||
fullFilePath,
|
||||
diskContent,
|
||||
newController.codeLines,
|
||||
workspaceRoot: widget.rootPath,
|
||||
);
|
||||
});
|
||||
|
||||
if (tab != null) {
|
||||
tab.content = diskContent;
|
||||
@@ -1378,6 +1644,7 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
if (mounted) {
|
||||
_handleNavigationTarget(provider);
|
||||
_syncSearchHighlight(searchProvider);
|
||||
_updateGitBaseContent();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'dart:math' as math;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -253,15 +254,21 @@ class _GitDiffPageState extends State<GitDiffPage> {
|
||||
final baseContent = await widget.gitProvider.gitService.getFileBaseContent(repoPath, _currentFile);
|
||||
final modifiedContent = await widget.gitProvider.gitService.getFileModifiedContent(repoPath, _currentFile);
|
||||
|
||||
final split = GitDiffHelper.computeSplitDiff(baseContent ?? '', modifiedContent);
|
||||
final unified = GitDiffHelper.toUnifiedDiff(baseContent ?? '', modifiedContent);
|
||||
// 大文件采用后台 Isolate 计算双屏与单屏差异,彻底杜绝主 UI 线程卡顿
|
||||
final isLarge = (baseContent != null && baseContent.length > 32768) || modifiedContent.length > 32768;
|
||||
final diffData = isLarge
|
||||
? await compute<_DiffDataInput, _DiffDataOutput>(
|
||||
_computeDiffPageData,
|
||||
_DiffDataInput(baseContent ?? '', modifiedContent),
|
||||
)
|
||||
: _computeDiffPageData(_DiffDataInput(baseContent ?? '', modifiedContent));
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_splitResult = split;
|
||||
_unifiedLines = unified;
|
||||
_splitResult = diffData.split;
|
||||
_unifiedLines = diffData.unified;
|
||||
_isLoading = false;
|
||||
_currentChangeIndex = split.changeRowIndices.isNotEmpty ? 0 : -1;
|
||||
_currentChangeIndex = diffData.split.changeRowIndices.isNotEmpty ? 0 : -1;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -368,7 +375,9 @@ class _GitDiffPageState extends State<GitDiffPage> {
|
||||
final curH = _leftHController.hasClients ? _leftHController.offset : 0.0;
|
||||
|
||||
_splitFocalLineContinuous = (curV + localFocal.dy) / math.max(1.0, rowH);
|
||||
_splitFocalCharContinuous = (curH + localFocal.dx) / math.max(1.0, charW);
|
||||
// 水平锚定:若当前未横向滚动(偏移 <= 4px),缩放时严格锁定在 0,
|
||||
// 避免全局屏幕触摸坐标算入 targetScrollH 导致代码首部字符(如 -I、#、关键字等)被意外向右推入视口外
|
||||
_splitFocalCharContinuous = curH <= 4.0 ? 0.0 : curH / math.max(1.0, charW);
|
||||
|
||||
_splitLastPanPos = null;
|
||||
setState(() {
|
||||
@@ -417,7 +426,9 @@ class _GitDiffPageState extends State<GitDiffPage> {
|
||||
_splitCurrentLocalFocal = currentLocalFocal;
|
||||
|
||||
final targetScrollV = _splitFocalLineContinuous * newRowH - currentLocalFocal.dy;
|
||||
final targetScrollH = _splitFocalCharContinuous * newCharW - currentLocalFocal.dx;
|
||||
final targetScrollH = _splitFocalCharContinuous <= 0.0
|
||||
? 0.0
|
||||
: _splitFocalCharContinuous * newCharW;
|
||||
|
||||
_jumpSplitScroll(targetScrollV, targetScrollH);
|
||||
|
||||
@@ -451,7 +462,9 @@ class _GitDiffPageState extends State<GitDiffPage> {
|
||||
final currentLocalFocal = _splitCurrentLocalFocal ?? _splitInitialLocalFocal;
|
||||
if (currentLocalFocal != null) {
|
||||
final targetScrollV = _splitFocalLineContinuous * finalH - currentLocalFocal.dy;
|
||||
final targetScrollH = _splitFocalCharContinuous * finalW - currentLocalFocal.dx;
|
||||
final targetScrollH = _splitFocalCharContinuous <= 0.0
|
||||
? 0.0
|
||||
: _splitFocalCharContinuous * finalW;
|
||||
_jumpSplitScroll(targetScrollV, targetScrollH);
|
||||
}
|
||||
}
|
||||
@@ -622,7 +635,9 @@ class _GitDiffPageState extends State<GitDiffPage> {
|
||||
final curH = _unifiedHController.hasClients ? _unifiedHController.offset : 0.0;
|
||||
|
||||
_unifiedFocalLineContinuous = (curV + localFocal.dy) / math.max(1.0, rowH);
|
||||
_unifiedFocalCharContinuous = (curH + localFocal.dx) / math.max(1.0, charW);
|
||||
// 水平锚定:若当前未横向滚动(偏移 <= 4px),缩放时严格锁定在 0,
|
||||
// 避免全局屏幕触摸坐标算入 targetScrollH 导致代码首部字符被推入视口外
|
||||
_unifiedFocalCharContinuous = curH <= 4.0 ? 0.0 : curH / math.max(1.0, charW);
|
||||
|
||||
_unifiedLastPanPos = null;
|
||||
setState(() {
|
||||
@@ -671,7 +686,9 @@ class _GitDiffPageState extends State<GitDiffPage> {
|
||||
_unifiedCurrentLocalFocal = currentLocalFocal;
|
||||
|
||||
final targetScrollV = _unifiedFocalLineContinuous * newRowH - currentLocalFocal.dy;
|
||||
final targetScrollH = _unifiedFocalCharContinuous * newCharW - currentLocalFocal.dx;
|
||||
final targetScrollH = _unifiedFocalCharContinuous <= 0.0
|
||||
? 0.0
|
||||
: _unifiedFocalCharContinuous * newCharW;
|
||||
|
||||
_syncingUnified = true;
|
||||
if (_unifiedVController.hasClients) {
|
||||
@@ -729,7 +746,9 @@ class _GitDiffPageState extends State<GitDiffPage> {
|
||||
final currentLocalFocal = _unifiedCurrentLocalFocal ?? _unifiedInitialLocalFocal;
|
||||
if (currentLocalFocal != null) {
|
||||
final targetScrollV = _unifiedFocalLineContinuous * finalH - currentLocalFocal.dy;
|
||||
final targetScrollH = _unifiedFocalCharContinuous * finalW - currentLocalFocal.dx;
|
||||
final targetScrollH = _unifiedFocalCharContinuous <= 0.0
|
||||
? 0.0
|
||||
: _unifiedFocalCharContinuous * finalW;
|
||||
_syncingUnified = true;
|
||||
if (_unifiedVController.hasClients) {
|
||||
final maxV = _unifiedVController.position.maxScrollExtent;
|
||||
@@ -1426,7 +1445,8 @@ class _GitDiffPageState extends State<GitDiffPage> {
|
||||
final totalLines = lines.length;
|
||||
final digits = totalLines > 0 ? '$totalLines'.length : 1;
|
||||
final charW = fontSize * 0.60;
|
||||
final gutterWidth = math.max(44.0, digits * charW + 24.0);
|
||||
final signW = (charW + 4.0).clamp(14.0, 36.0);
|
||||
final gutterWidth = math.max(44.0, digits * charW + signW + 12.0);
|
||||
|
||||
// 视口极限狭窄自适应判定(彻底根治 RenderFlex 水平溢出)
|
||||
final bool hasCodeArea = viewportWidth > (gutterWidth + 1.0);
|
||||
@@ -1532,12 +1552,14 @@ class _GitDiffPageState extends State<GitDiffPage> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
// 加号/减号符号严格显示在行号区内!
|
||||
// 加号/减号符号严格显示在行号区内,随字号动态伸缩且防溢出裁切
|
||||
SizedBox(
|
||||
width: 12,
|
||||
width: signW,
|
||||
child: Center(
|
||||
child: Text(
|
||||
isDeleted ? '-' : (isAdded ? '+' : ''),
|
||||
overflow: TextOverflow.visible,
|
||||
softWrap: false,
|
||||
style: TextStyle(
|
||||
fontSize: (fontSize - 1).clamp(SettingsProvider.minFontSize - 1.0, SettingsProvider.maxFontSize + 8.0),
|
||||
fontWeight: FontWeight.bold,
|
||||
@@ -1655,7 +1677,8 @@ class _GitDiffPageState extends State<GitDiffPage> {
|
||||
|
||||
final totalLines = lines.length;
|
||||
final digits = totalLines > 0 ? '$totalLines'.length : 1;
|
||||
final gutterWidth = math.max(44.0, digits * displayCharWidth + 24.0);
|
||||
final signW = (displayCharWidth + 4.0).clamp(14.0, 36.0);
|
||||
final gutterWidth = math.max(44.0, digits * displayCharWidth + signW + 12.0);
|
||||
|
||||
int maxChars = 0;
|
||||
for (final l in lines) {
|
||||
@@ -1760,12 +1783,14 @@ class _GitDiffPageState extends State<GitDiffPage> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
// 符号指示器(+ / -)同样在行号区内!
|
||||
// 符号指示器(+ / -)同样在行号区内,随字号动态伸缩且防溢出裁切
|
||||
SizedBox(
|
||||
width: 12,
|
||||
width: signW,
|
||||
child: Center(
|
||||
child: Text(
|
||||
isDeleted ? '-' : (isAdded ? '+' : ''),
|
||||
overflow: TextOverflow.visible,
|
||||
softWrap: false,
|
||||
style: TextStyle(
|
||||
fontSize: (displayFontSize - 1).clamp(SettingsProvider.minFontSize - 1.0, SettingsProvider.maxFontSize + 8.0),
|
||||
fontWeight: FontWeight.bold,
|
||||
@@ -1863,3 +1888,21 @@ class _GitDiffPageState extends State<GitDiffPage> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DiffDataInput {
|
||||
final String baseContent;
|
||||
final String modifiedContent;
|
||||
const _DiffDataInput(this.baseContent, this.modifiedContent);
|
||||
}
|
||||
|
||||
class _DiffDataOutput {
|
||||
final SplitDiffResult split;
|
||||
final List<UnifiedDiffLine> unified;
|
||||
const _DiffDataOutput(this.split, this.unified);
|
||||
}
|
||||
|
||||
_DiffDataOutput _computeDiffPageData(_DiffDataInput input) {
|
||||
final split = GitDiffHelper.computeSplitDiff(input.baseContent, input.modifiedContent);
|
||||
final unified = GitDiffHelper.toUnifiedDiff(input.baseContent, input.modifiedContent);
|
||||
return _DiffDataOutput(split, unified);
|
||||
}
|
||||
Reference in new issue
Block a user