1
This commit is contained in:
1 parent
7a3db86a10
commit
3df0cbc7c0
10 files changed
+892
-38
No files matched your search
@@ -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