1
This commit is contained in:
1 parent
1ab5d52449
commit
5efc778165
18 files changed
+1011
-43
No files matched your search
@@ -0,0 +1,93 @@
|
||||
# PRoot 环境下 `apt install perl` 失败问题修复计划
|
||||
|
||||
## 一、问题现象与背景
|
||||
|
||||
在 Ubuntu / Debian 容器环境中执行 `apt install perl` 时报错:
|
||||
```text
|
||||
dpkg: error processing archive /var/cache/apt/archives/perl_5.38.2-3.2ubuntu0.4_arm64.deb (--unpack):
|
||||
error setting ownership of '/usr/bin/perlthanks.dpkg-new': No such file or directory
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 二、底层根因分析(深度对标 Termux / proot-distro)
|
||||
|
||||
### 1. 核心诱因:硬链接解包转换
|
||||
- Perl 软件包在解压时,`/usr/bin/perlthanks` 是指向 `/usr/bin/perlbug` 的硬链接(Hard Link)。
|
||||
- Android 应用私有目录下,底层文件系统/SELinux 策略禁止非 root 应用直接创建硬链接(`link(2)` 返回 `EPERM`)。
|
||||
- PRoot 启用了 `--link2symlink`,它将硬链接拦截并转换为:**指向 `.l2s` 目录下替身文件的符号链接(Symlink)**。
|
||||
|
||||
### 2. 缺陷一:`.l2s` 目录路径错位(位于 Rootfs 外部)
|
||||
- **现状**:
|
||||
在 `lib/services/distro_manager.dart` 中:
|
||||
```dart
|
||||
final l2sDir = Directory(p.join(baseDir.path, systemName, '.l2s'));
|
||||
```
|
||||
该路径在宿主为 `<baseDir>/<systemName>/.l2s`,而容器 Rootfs 为 `<baseDir>/<systemName>/rootfs`。`.l2s` 位于 Rootfs **外部**。
|
||||
- **Termux 官方规范**:
|
||||
在 Termux `proot-distro` 的 `l2s.py` 源码中明确声明:
|
||||
> `(proot-distro sets it to <rootfs>/.l2s)`
|
||||
- **导致的问题**:
|
||||
PRoot 在创建替身符号链接时,记录的是绝对路径。当 `.l2s` 位于 rootfs 外时,PRoot 内部的路径逆向规范化(`detranslate_path`)无法将其识别为容器内合法路径;容器内应用跟随链接访问时也无法访问容器外的宿主目录,从而触发 `ENOENT`(No such file or directory)。
|
||||
|
||||
### 3. 缺陷二:`libfix_seccomp.so` 遗漏导出 `chown` 与 `lchown` 符号
|
||||
- **现状**:
|
||||
此前为 Alpine(musl libc)修复 `apk add tzdata` 时,Shim 仅拦截了 `fchownat`,因为 musl 的 `chown/lchown` 内部均调用 `fchownat`。
|
||||
- **Ubuntu/Debian (glibc) 差异**:
|
||||
- `dpkg` 在解包硬链接后会直接调用 `chown(fnamenew, uid, gid)`。
|
||||
- glibc 的 `chown()` 函数实现是**直接执行内联系统调用指令(inline syscall `svc 0`)**,并不走 `fchownat` 的 PLT 动态重定位跳转。
|
||||
- 因此 `dpkg` 调用的 `chown` 彻底绕过了 Shim 的 `fchownat` 拦截,直达 PRoot/内核。PRoot 在跟随 l2s 替身链接时返回 `ENOENT`。
|
||||
|
||||
---
|
||||
|
||||
## 三、修改计划与实施步骤
|
||||
|
||||
### 步骤 1:Dart 端 `.l2s` 路径对标 Termux 并自动迁移
|
||||
**修改文件**:[`lib/services/distro_manager.dart`](file:///d:/Flutter/Projects/code_editor/lib/services/distro_manager.dart)
|
||||
1. 将 `_ensureL2sDir(String systemName)` 升级为 `_ensureL2sDir(String systemName, Directory rootDir)`:
|
||||
- 目录指向 `p.join(rootDir.path, '.l2s')`。
|
||||
- 若此前存在旧路径 `<baseDir>/<systemName>/.l2s` 且内含文件,自动平滑移动至新位置。
|
||||
2. 环境变量配置:
|
||||
- PRoot 宿主环境传递:`'PROOT_L2S_DIR': l2sDir.path`。
|
||||
- 容器内 guest 环境变量同步注入:`'PROOT_L2S_DIR=/.l2s'`。
|
||||
|
||||
### 步骤 2:Debian / Ubuntu 环境部署 `dpkg` 优化配置
|
||||
**修改文件**:[`lib/services/distro_installer.dart`](file:///d:/Flutter/Projects/code_editor/lib/services/distro_installer.dart)
|
||||
1. 新增 `ensureDpkgConfiguration(Directory rootfsDir)` 方法:
|
||||
- 检查 `etc/dpkg` 是否存在(判断是否为 Debian/Ubuntu 环境)。
|
||||
- 确保 `/etc/dpkg/dpkg.cfg.d/` 目录存在。
|
||||
- 写入 `/etc/dpkg/dpkg.cfg.d/01_proot`,内容包含:
|
||||
```text
|
||||
force-unsafe-io
|
||||
```
|
||||
- 避免容器内因 fsync / flash I/O 阻塞或权限校验引发的解包异常(Docker / proot-distro 官方推荐实践)。
|
||||
2. 在 `postInstallConfigure` 与容器启动检查中自动调用。
|
||||
|
||||
### 步骤 3:Shim (`libfix_seccomp.c`) 补充 `chown` 与 `lchown` 导出
|
||||
**修改文件**:[`android/app/src/main/cpp/libfix_seccomp.c`](file:///d:/Flutter/Projects/code_editor/android/app/src/main/cpp/libfix_seccomp.c)
|
||||
1. 增加标准 `chown` 和 `lchown` 导出符号:
|
||||
```c
|
||||
__attribute__((visibility("default")))
|
||||
int chown(const char *path, int owner, int group) {
|
||||
return fchownat(AT_FDCWD, path, owner, group, 0);
|
||||
}
|
||||
|
||||
__attribute__((visibility("default")))
|
||||
int lchown(const char *path, int owner, int group) {
|
||||
return fchownat(AT_FDCWD, path, owner, group, AT_SYMLINK_NOFOLLOW);
|
||||
}
|
||||
```
|
||||
2. 如此一来,无论是 glibc 还是 musl 的应用程序直接调用 `chown` 或 `lchown`,均会走入已有的 `fchownat` 机制:在遭遇 `ENOENT` 时自动以 `AT_SYMLINK_NOFOLLOW` 重试设置替身属性,保证硬链接解压 100% 成功。
|
||||
|
||||
---
|
||||
|
||||
## 四、验证与验收方案
|
||||
|
||||
1. **单元测试回归**:
|
||||
- 运行全量单元测试:`flutter test`(确保现有 282 项测试无任何回退)。
|
||||
- 增加关于 `.l2s` 位于 `rootDir/.l2s` 以及 `dpkg.cfg.d/01_proot` 的自动化测试用例。
|
||||
2. **静态分析**:
|
||||
- 运行 `flutter analyze` 确保无任何语法和类型告警。
|
||||
3. **真实场景(Ubuntu 容器)验证**:
|
||||
- 在容器中执行 `apt update && apt install perl -y`。
|
||||
- 验证 `/usr/bin/perlthanks` 与 `/usr/bin/perlbug` 成功安装且解包 ownership 正确设置,退出码为 0。
|
||||
@@ -84,6 +84,8 @@
|
||||
"terminalFont": "Terminal Font",
|
||||
"selectTerminalFont": "Select Terminal Font",
|
||||
"terminalFontPreview": "$ git status -s # terminal font preview",
|
||||
"terminalFontSize": "Terminal Font Size",
|
||||
"terminalFontSizeDialogTitle": "Terminal Font Size",
|
||||
"fontName": "{font, select, system_default{System Default} sans_serif{Sans-Serif} serif{Serif (Songti)} monospace{System Monospace} consolas{Consolas} courier_new{Courier New} menlo{Menlo / Monaco} jetbrains_mono{JetBrains Mono} fira_code{Fira Code} other{{font}}}",
|
||||
"@fontName": {
|
||||
"placeholders": {
|
||||
|
||||
@@ -602,6 +602,18 @@ abstract class AppLocalizations {
|
||||
/// **'\$ git status -s # 终端字体预览'**
|
||||
String get terminalFontPreview;
|
||||
|
||||
/// No description provided for @terminalFontSize.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'终端字号'**
|
||||
String get terminalFontSize;
|
||||
|
||||
/// No description provided for @terminalFontSizeDialogTitle.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'终端字号'**
|
||||
String get terminalFontSizeDialogTitle;
|
||||
|
||||
/// No description provided for @fontName.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
|
||||
@@ -280,6 +280,12 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get terminalFontPreview => '\$ git status -s # terminal font preview';
|
||||
|
||||
@override
|
||||
String get terminalFontSize => 'Terminal Font Size';
|
||||
|
||||
@override
|
||||
String get terminalFontSizeDialogTitle => 'Terminal Font Size';
|
||||
|
||||
@override
|
||||
String fontName(String font) {
|
||||
String _temp0 = intl.Intl.selectLogic(font, {
|
||||
|
||||
@@ -276,6 +276,12 @@ class AppLocalizationsZh extends AppLocalizations {
|
||||
@override
|
||||
String get terminalFontPreview => '\$ git status -s # 终端字体预览';
|
||||
|
||||
@override
|
||||
String get terminalFontSize => '终端字号';
|
||||
|
||||
@override
|
||||
String get terminalFontSizeDialogTitle => '终端字号';
|
||||
|
||||
@override
|
||||
String fontName(String font) {
|
||||
String _temp0 = intl.Intl.selectLogic(font, {
|
||||
|
||||
@@ -84,6 +84,8 @@
|
||||
"terminalFont": "终端字体",
|
||||
"selectTerminalFont": "选择终端字体",
|
||||
"terminalFontPreview": "$ git status -s # 终端字体预览",
|
||||
"terminalFontSize": "终端字号",
|
||||
"terminalFontSizeDialogTitle": "终端字号",
|
||||
"fontName": "{font, select, system_default{系统默认} sans_serif{无衬线体} serif{衬线体(宋体)} monospace{系统等宽} consolas{Consolas} courier_new{Courier New} menlo{Menlo / Monaco} jetbrains_mono{JetBrains Mono} fira_code{Fira Code} other{{font}}}",
|
||||
"@fontName": {
|
||||
"placeholders": {
|
||||
|
||||
@@ -26,6 +26,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
|
||||
//终端
|
||||
static const String _keyTerminalFont = 'terminal_font_family'; //终端字体
|
||||
static const String _keyTerminalFontSize = 'terminal_font_size'; //终端字号
|
||||
static const String _keyTerminalBackgroundColor = 'terminal_background_color'; //终端背景颜色
|
||||
static const String _keyEnableTerminalVirtualKeyboard = 'enable_terminal_virtual_keyboard'; //终端小键盘启用
|
||||
static const String _keyTerminalKeyboardConfig = 'terminal_virtual_keyboard_config'; //终端小键盘配置JSON
|
||||
@@ -46,6 +47,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
String _editorFontId = 'jetbrains_mono';
|
||||
String _terminalFontId = 'jetbrains_mono';
|
||||
Color _terminalBackgroundColor = const Color(0xFF1E1E1E);
|
||||
double _terminalFontSize = 13.0;
|
||||
double _fontSize = 14.0;
|
||||
int _indentSize = 4;
|
||||
bool _wordWrap = false;
|
||||
@@ -77,6 +79,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
String get terminalFontId => _terminalFontId;
|
||||
AppFontItem get terminalFont => AppFonts.getTerminalFont(_terminalFontId);
|
||||
Color get terminalBackgroundColor => _terminalBackgroundColor;
|
||||
double get terminalFontSize => _terminalFontSize;
|
||||
|
||||
double get fontSize => _fontSize;
|
||||
int get indentSize => _indentSize;
|
||||
@@ -277,6 +280,11 @@ class SettingsProvider extends ChangeNotifier {
|
||||
_terminalBackgroundColor = Color(savedTerminalBackground);
|
||||
}
|
||||
|
||||
final savedTerminalFontSize = prefs.getDouble(_keyTerminalFontSize);
|
||||
if (savedTerminalFontSize != null) {
|
||||
_terminalFontSize = savedTerminalFontSize.clamp(8.0, 32.0);
|
||||
}
|
||||
|
||||
//设置项目配置
|
||||
final savedShowHiddenFiles = prefs.getBool(_keyShowHiddenFiles);
|
||||
if (savedShowHiddenFiles != null) {
|
||||
@@ -451,6 +459,18 @@ class SettingsProvider extends ChangeNotifier {
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// 设置终端字体大小
|
||||
Future<void> setTerminalFontSize(double size) async {
|
||||
final clamped = size.clamp(8.0, 32.0);
|
||||
if (_terminalFontSize == clamped) return;
|
||||
_terminalFontSize = clamped;
|
||||
notifyListeners();
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setDouble(_keyTerminalFontSize, clamped);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// 设置是否显示隐藏文件
|
||||
Future<void> setShowHiddenFiles(bool show) async {
|
||||
if (_showHiddenFiles == show) return;
|
||||
|
||||
@@ -69,6 +69,7 @@ class SettingsView extends StatelessWidget {
|
||||
_buildTerminalVirtualKeyboardTile(context, provider, l10n),
|
||||
_buildTerminalVirtualKeyboardConfigTile(context, provider, l10n),
|
||||
_buildTerminalFontTile(context, provider),
|
||||
_buildTerminalFontSizeTile(context, provider, l10n),
|
||||
|
||||
const Divider(height: 32, indent: 16, endIndent: 16),
|
||||
|
||||
@@ -278,6 +279,121 @@ class SettingsView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// 终端:终端字号条目
|
||||
Widget _buildTerminalFontSizeTile(
|
||||
BuildContext context,
|
||||
SettingsProvider provider,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return ListTile(
|
||||
leading: Icon(Icons.format_size, color: theme.colorScheme.primary),
|
||||
title: Text(l10n.terminalFontSize),
|
||||
subtitle: Text('${provider.terminalFontSize.toInt()} pt'),
|
||||
trailing: SizedBox(
|
||||
width: 150,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.remove, size: 18),
|
||||
visualDensity: VisualDensity.compact,
|
||||
tooltip: l10n.decreaseFontSize,
|
||||
onPressed: provider.terminalFontSize > 8.0
|
||||
? () => provider.setTerminalFontSize(provider.terminalFontSize - 1)
|
||||
: null,
|
||||
),
|
||||
Text(
|
||||
'${provider.terminalFontSize.toInt()}',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add, size: 18),
|
||||
visualDensity: VisualDensity.compact,
|
||||
tooltip: l10n.increaseFontSize,
|
||||
onPressed: provider.terminalFontSize < 32.0
|
||||
? () => provider.setTerminalFontSize(provider.terminalFontSize + 1)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
_showTerminalFontSizeDialog(context, provider, l10n);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showTerminalFontSizeDialog(
|
||||
BuildContext context,
|
||||
SettingsProvider provider,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
double tempSize = provider.terminalFontSize;
|
||||
final terminalFont = provider.terminalFont;
|
||||
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setDialogState) {
|
||||
return AlertDialog(
|
||||
title: Text(l10n.terminalFontSizeDialogTitle),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'${tempSize.toInt()} pt',
|
||||
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Slider(
|
||||
value: tempSize.clamp(8.0, 32.0),
|
||||
min: 8.0,
|
||||
max: 32.0,
|
||||
divisions: 24,
|
||||
label: '${tempSize.toInt()}',
|
||||
onChanged: (val) {
|
||||
setDialogState(() {
|
||||
tempSize = val;
|
||||
});
|
||||
provider.setTerminalFontSize(val);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: provider.terminalBackgroundColor,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
l10n.terminalFontPreview,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: tempSize,
|
||||
fontFamily: terminalFont.fontFamily ?? 'monospace',
|
||||
fontFamilyFallback: terminalFont.fallback,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||
child: Text(l10n.done),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 外观:主题颜色条目(点击弹出调色板)
|
||||
Widget _buildThemeColorTile(
|
||||
BuildContext context,
|
||||
|
||||
@@ -215,6 +215,103 @@ class _TerminalSessionBodyState extends State<_TerminalSessionBody> {
|
||||
TerminalInputHandler? _delegateInputHandler;
|
||||
void Function(String)? _delegateOnOutput;
|
||||
|
||||
// 双指捏合缩放终端字号状态
|
||||
final Map<int, Offset> _pointerPositions = {};
|
||||
double? _initialPinchDistance;
|
||||
double? _initialPinchFontSize;
|
||||
double? _activeZoomFontSize;
|
||||
bool _isPinching = false;
|
||||
Offset? _initialLocalFocal;
|
||||
double _initialScrollV = 0.0;
|
||||
|
||||
void _handlePointerDown(PointerDownEvent event, double currentFontSize) {
|
||||
_pointerPositions[event.pointer] = event.position;
|
||||
if (_pointerPositions.length == 2) {
|
||||
final points = _pointerPositions.values.toList();
|
||||
_initialPinchDistance = (points[0] - points[1]).distance;
|
||||
_initialPinchFontSize = _activeZoomFontSize ?? currentFontSize;
|
||||
|
||||
final globalFocal = (points[0] + points[1]) / 2;
|
||||
final renderBox = context.findRenderObject() as RenderBox?;
|
||||
_initialLocalFocal = renderBox != null ? renderBox.globalToLocal(globalFocal) : globalFocal;
|
||||
_initialScrollV = _terminalScrollController.hasClients ? _terminalScrollController.offset : 0.0;
|
||||
|
||||
// 双指缩放开始时,清除可能残留的选区,避免手柄或菜单错位
|
||||
_terminalController.clearSelection();
|
||||
|
||||
setState(() {
|
||||
_isPinching = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePointerMove(PointerMoveEvent event) {
|
||||
if (!_pointerPositions.containsKey(event.pointer)) return;
|
||||
_pointerPositions[event.pointer] = event.position;
|
||||
|
||||
if (_pointerPositions.length >= 2 &&
|
||||
_initialPinchDistance != null &&
|
||||
_initialPinchDistance! > 10.0 &&
|
||||
_initialPinchFontSize != null &&
|
||||
_initialLocalFocal != null) {
|
||||
final points = _pointerPositions.values.toList();
|
||||
final currentDistance = (points[0] - points[1]).distance;
|
||||
final scale = currentDistance / _initialPinchDistance!;
|
||||
final rawFontSize = (_initialPinchFontSize! * scale).clamp(8.0, 32.0);
|
||||
final newFontSize = (rawFontSize * 10).round() / 10.0;
|
||||
final fontScale = newFontSize / _initialPinchFontSize!;
|
||||
|
||||
final currentGlobalFocal = (points[0] + points[1]) / 2;
|
||||
final renderBox = context.findRenderObject() as RenderBox?;
|
||||
final currentLocalFocal = renderBox != null
|
||||
? renderBox.globalToLocal(currentGlobalFocal)
|
||||
: currentGlobalFocal;
|
||||
|
||||
if (_terminalScrollController.hasClients && _terminalScrollController.position.maxScrollExtent > 0) {
|
||||
final targetScrollV = (_initialScrollV + _initialLocalFocal!.dy) * fontScale - currentLocalFocal.dy;
|
||||
_terminalScrollController.jumpTo(targetScrollV.clamp(0.0, _terminalScrollController.position.maxScrollExtent));
|
||||
}
|
||||
|
||||
if (_activeZoomFontSize != newFontSize) {
|
||||
setState(() {
|
||||
_activeZoomFontSize = newFontSize;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePointerUp(PointerUpEvent event) {
|
||||
_pointerPositions.remove(event.pointer);
|
||||
if (_pointerPositions.length < 2 && _isPinching) {
|
||||
_finishPinchZoom();
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePointerCancel(PointerCancelEvent event) {
|
||||
_pointerPositions.remove(event.pointer);
|
||||
if (_pointerPositions.length < 2 && _isPinching) {
|
||||
_finishPinchZoom();
|
||||
}
|
||||
}
|
||||
|
||||
void _finishPinchZoom() {
|
||||
final finalSize = _activeZoomFontSize;
|
||||
if (finalSize != null) {
|
||||
try {
|
||||
final settings = context.read<SettingsProvider?>();
|
||||
settings?.setTerminalFontSize(finalSize.roundToDouble());
|
||||
} catch (_) {}
|
||||
}
|
||||
setState(() {
|
||||
_isPinching = false;
|
||||
_initialPinchDistance = null;
|
||||
_initialPinchFontSize = null;
|
||||
_activeZoomFontSize = null;
|
||||
_initialLocalFocal = null;
|
||||
_initialScrollV = 0.0;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -255,9 +352,11 @@ class _TerminalSessionBodyState extends State<_TerminalSessionBody> {
|
||||
final session = widget.session;
|
||||
final settings = context.watch<SettingsProvider?>();
|
||||
final terminalFont = settings?.terminalFont ?? AppFonts.terminalMonospace;
|
||||
final currentBaseFontSize = settings?.terminalFontSize ?? 13.0;
|
||||
final displayFontSize = _activeZoomFontSize ?? currentBaseFontSize;
|
||||
|
||||
final terminalStyle = xterm.TerminalStyle(
|
||||
fontSize: 13.0,
|
||||
fontSize: displayFontSize,
|
||||
fontFamily: terminalFont.fontFamily ?? 'monospace',
|
||||
fontFamilyFallback: terminalFont.fallback,
|
||||
);
|
||||
@@ -276,6 +375,12 @@ class _TerminalSessionBodyState extends State<_TerminalSessionBody> {
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Listener(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onPointerDown: (e) => _handlePointerDown(e, currentBaseFontSize),
|
||||
onPointerMove: _handlePointerMove,
|
||||
onPointerUp: _handlePointerUp,
|
||||
onPointerCancel: _handlePointerCancel,
|
||||
child: TerminalSelectionOverlay(
|
||||
terminal: session.terminal,
|
||||
controller: _terminalController,
|
||||
@@ -292,7 +397,8 @@ class _TerminalSessionBodyState extends State<_TerminalSessionBody> {
|
||||
theme: terminalThemeWithBackground(backgroundColor),
|
||||
textStyle: terminalStyle,
|
||||
cursorType: xterm.TerminalCursorType.block,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 8.0),
|
||||
padding: const EdgeInsets.fromLTRB(10.0, 8.0, 10.0, 20.0),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -52,39 +52,50 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
int? _currentIndentSize;
|
||||
bool _isShowingConflictDialog = false;
|
||||
|
||||
// 双指捏合缩放字号及中心锚定状态
|
||||
// 双指捏合实时缩放字号及中心锚定状态
|
||||
final GlobalKey _editorContainerKey = GlobalKey();
|
||||
final Map<int, Offset> _pointerPositions = {};
|
||||
int? _pinchPointer1;
|
||||
int? _pinchPointer2;
|
||||
double? _initialPinchDistance;
|
||||
double? _initialPinchFontSize;
|
||||
double? _activeZoomFontSize;
|
||||
bool _isPinching = false;
|
||||
CodeLineSelection? _pinchSelection;
|
||||
Offset? _initialLocalFocal;
|
||||
Offset? _currentLocalFocal;
|
||||
double _initialScrollV = 0.0;
|
||||
double _initialScrollH = 0.0;
|
||||
|
||||
void _handlePointerDown(PointerDownEvent event, double currentFontSize) {
|
||||
_pointerPositions[event.pointer] = event.position;
|
||||
if (_pointerPositions.length == 2) {
|
||||
final points = _pointerPositions.values.toList();
|
||||
_initialPinchDistance = (points[0] - points[1]).distance;
|
||||
_initialPinchFontSize = _activeZoomFontSize ?? currentFontSize;
|
||||
if (_pointerPositions.length >= 2 && !_isPinching) {
|
||||
final keys = _pointerPositions.keys.toList();
|
||||
_pinchPointer1 = keys[0];
|
||||
_pinchPointer2 = keys[1];
|
||||
|
||||
// 停止当前的惯性滚动,保证锚定基准平稳
|
||||
final p1 = _pointerPositions[_pinchPointer1]!;
|
||||
final p2 = _pointerPositions[_pinchPointer2]!;
|
||||
|
||||
_initialPinchDistance = (p1 - p2).distance;
|
||||
_initialPinchFontSize = _activeZoomFontSize ?? currentFontSize;
|
||||
_activeZoomFontSize = _initialPinchFontSize;
|
||||
|
||||
// 锁定底层滚动控制器并停止惯性滚动,彻底阻断单指拖拽识别器与内部 viewport 修正干扰
|
||||
final vScroller = _scrollController?.verticalScroller;
|
||||
if (vScroller is CodeEditorScrollController) {
|
||||
vScroller.stopScrolling();
|
||||
vScroller.isPinchLocked = true;
|
||||
}
|
||||
final hScroller = _scrollController?.horizontalScroller;
|
||||
if (hScroller is CodeEditorScrollController) {
|
||||
hScroller.stopScrolling();
|
||||
hScroller.isPinchLocked = true;
|
||||
}
|
||||
|
||||
final globalFocal = (points[0] + points[1]) / 2;
|
||||
final globalFocal = (p1 + p2) / 2;
|
||||
final renderBox = _editorContainerKey.currentContext?.findRenderObject() as RenderBox?;
|
||||
final localFocal = renderBox != null ? renderBox.globalToLocal(globalFocal) : globalFocal;
|
||||
_initialLocalFocal = localFocal;
|
||||
_currentLocalFocal = localFocal;
|
||||
|
||||
_initialScrollV = (_scrollController?.verticalScroller.hasClients == true)
|
||||
? _scrollController!.verticalScroller.offset
|
||||
@@ -110,32 +121,53 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
if (!_pointerPositions.containsKey(event.pointer)) return;
|
||||
_pointerPositions[event.pointer] = event.position;
|
||||
|
||||
if (_pointerPositions.length >= 2 &&
|
||||
if (_isPinching &&
|
||||
_pinchPointer1 != null &&
|
||||
_pinchPointer2 != null &&
|
||||
_pointerPositions.containsKey(_pinchPointer1) &&
|
||||
_pointerPositions.containsKey(_pinchPointer2) &&
|
||||
_initialPinchDistance != null &&
|
||||
_initialPinchDistance! > 10.0 &&
|
||||
_initialPinchFontSize != null &&
|
||||
_initialLocalFocal != null) {
|
||||
final points = _pointerPositions.values.toList();
|
||||
final currentDistance = (points[0] - points[1]).distance;
|
||||
final scale = currentDistance / _initialPinchDistance!;
|
||||
final rawFontSize = (_initialPinchFontSize! * scale).clamp(10.0, 30.0);
|
||||
final newFontSize = (rawFontSize * 10).round() / 10.0;
|
||||
final fontScale = newFontSize / _initialPinchFontSize!;
|
||||
final p1 = _pointerPositions[_pinchPointer1]!;
|
||||
final p2 = _pointerPositions[_pinchPointer2]!;
|
||||
|
||||
final currentGlobalFocal = (points[0] + points[1]) / 2;
|
||||
final currentDistance = (p1 - p2).distance;
|
||||
final rawScale = currentDistance / _initialPinchDistance!;
|
||||
|
||||
// 边界弹性阻尼(10.0 ~ 30.0)
|
||||
final minScale = 10.0 / _initialPinchFontSize!;
|
||||
final maxScale = 30.0 / _initialPinchFontSize!;
|
||||
final clampedScale = rawScale.clamp(minScale * 0.9, maxScale * 1.1);
|
||||
|
||||
final currentGlobalFocal = (p1 + p2) / 2;
|
||||
final renderBox = _editorContainerKey.currentContext?.findRenderObject() as RenderBox?;
|
||||
final currentLocalFocal = renderBox != null
|
||||
? renderBox.globalToLocal(currentGlobalFocal)
|
||||
: currentGlobalFocal;
|
||||
_currentLocalFocal = currentLocalFocal;
|
||||
|
||||
final targetScrollV = (_initialScrollV + _initialLocalFocal!.dy) * fontScale - currentLocalFocal.dy;
|
||||
final targetScrollH = (_initialScrollH + _initialLocalFocal!.dx) * fontScale - currentLocalFocal.dx;
|
||||
// 连续高精度浮点字号(避免 0.1 离散跳变造成的阶梯式顿挫)
|
||||
final continuousFontSize = ((_initialPinchFontSize! * clampedScale) * 100).round() / 100.0;
|
||||
final newFontSize = continuousFontSize.clamp(10.0, 30.0);
|
||||
final fontRatio = newFontSize / _initialPinchFontSize!;
|
||||
|
||||
// 焦心连续锚定公式:保持手指焦心下的代码行与手指相对位置绝对静止
|
||||
final targetScrollV = (_initialScrollV + _initialLocalFocal!.dy) * fontRatio - currentLocalFocal.dy;
|
||||
final targetScrollH = (_initialScrollH + _initialLocalFocal!.dx) * fontRatio - currentLocalFocal.dx;
|
||||
|
||||
if (_scrollController?.verticalScroller.hasClients == true) {
|
||||
_scrollController!.verticalScroller.jumpTo(max(0.0, targetScrollV));
|
||||
final pos = _scrollController!.verticalScroller.position;
|
||||
final maxV = max(0.0, pos.maxScrollExtent);
|
||||
final clampedV = targetScrollV.clamp(0.0, maxV);
|
||||
_scrollController!.verticalScroller.jumpTo(clampedV);
|
||||
}
|
||||
if (_scrollController?.horizontalScroller.hasClients == true) {
|
||||
_scrollController!.horizontalScroller.jumpTo(max(0.0, targetScrollH));
|
||||
final pos = _scrollController!.horizontalScroller.position;
|
||||
final maxH = max(0.0, pos.maxScrollExtent);
|
||||
final clampedH = targetScrollH.clamp(0.0, maxH);
|
||||
_scrollController!.horizontalScroller.jumpTo(clampedH);
|
||||
}
|
||||
|
||||
if (_activeZoomFontSize != newFontSize) {
|
||||
@@ -148,16 +180,33 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
|
||||
void _handlePointerUp(PointerUpEvent event) {
|
||||
_pointerPositions.remove(event.pointer);
|
||||
if (_pointerPositions.length < 2 && _isPinching) {
|
||||
if (_isPinching && (event.pointer == _pinchPointer1 || event.pointer == _pinchPointer2 || _pointerPositions.length < 2)) {
|
||||
_finishPinchZoom();
|
||||
}
|
||||
if (_pointerPositions.isEmpty) {
|
||||
_unlockPinch();
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePointerCancel(PointerCancelEvent event) {
|
||||
_pointerPositions.remove(event.pointer);
|
||||
if (_pointerPositions.length < 2 && _isPinching) {
|
||||
if (_isPinching && (event.pointer == _pinchPointer1 || event.pointer == _pinchPointer2 || _pointerPositions.length < 2)) {
|
||||
_finishPinchZoom();
|
||||
}
|
||||
if (_pointerPositions.isEmpty) {
|
||||
_unlockPinch();
|
||||
}
|
||||
}
|
||||
|
||||
void _unlockPinch() {
|
||||
final vScroller = _scrollController?.verticalScroller;
|
||||
if (vScroller is CodeEditorScrollController) {
|
||||
vScroller.isPinchLocked = false;
|
||||
}
|
||||
final hScroller = _scrollController?.horizontalScroller;
|
||||
if (hScroller is CodeEditorScrollController) {
|
||||
hScroller.isPinchLocked = false;
|
||||
}
|
||||
}
|
||||
|
||||
void _finishPinchZoom() {
|
||||
@@ -165,19 +214,48 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
final savedSelection = _pinchSelection;
|
||||
_pinchSelection = null;
|
||||
|
||||
if (finalSize != null) {
|
||||
final initialFontSize = _initialPinchFontSize;
|
||||
final initialLocalFocal = _initialLocalFocal;
|
||||
final currentLocalFocal = _currentLocalFocal ?? initialLocalFocal;
|
||||
final initialScrollV = _initialScrollV;
|
||||
final initialScrollH = _initialScrollH;
|
||||
|
||||
if (finalSize != null && initialFontSize != null && initialLocalFocal != null && currentLocalFocal != null) {
|
||||
// 手势释放后定格为整数(如 16.0),持久化到用户设置
|
||||
final double targetFontSize = finalSize.clamp(10.0, 30.0).roundToDouble();
|
||||
final double fontRatio = targetFontSize / initialFontSize;
|
||||
|
||||
final targetScrollV = (initialScrollV + initialLocalFocal.dy) * fontRatio - currentLocalFocal.dy;
|
||||
final targetScrollH = (initialScrollH + initialLocalFocal.dx) * fontRatio - currentLocalFocal.dx;
|
||||
|
||||
try {
|
||||
final settings = _getSettingsProvider(context);
|
||||
settings.setFontSize(finalSize.roundToDouble());
|
||||
settings.setFontSize(targetFontSize);
|
||||
} catch (_) {}
|
||||
|
||||
if (_scrollController?.verticalScroller.hasClients == true) {
|
||||
final pos = _scrollController!.verticalScroller.position;
|
||||
final maxV = max(0.0, pos.maxScrollExtent);
|
||||
final clampedV = targetScrollV.clamp(0.0, maxV);
|
||||
_scrollController!.verticalScroller.jumpTo(clampedV);
|
||||
}
|
||||
if (_scrollController?.horizontalScroller.hasClients == true) {
|
||||
final pos = _scrollController!.horizontalScroller.position;
|
||||
final maxH = max(0.0, pos.maxScrollExtent);
|
||||
final clampedH = targetScrollH.clamp(0.0, maxH);
|
||||
_scrollController!.horizontalScroller.jumpTo(clampedH);
|
||||
}
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isPinching = false;
|
||||
_pinchPointer1 = null;
|
||||
_pinchPointer2 = null;
|
||||
_initialPinchDistance = null;
|
||||
_initialPinchFontSize = null;
|
||||
_activeZoomFontSize = null;
|
||||
_initialLocalFocal = null;
|
||||
_currentLocalFocal = null;
|
||||
_initialScrollV = 0.0;
|
||||
_initialScrollH = 0.0;
|
||||
});
|
||||
@@ -529,7 +607,9 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
onPointerCancel: _handlePointerCancel,
|
||||
child: Stack(
|
||||
children: [
|
||||
CodeEditor(
|
||||
IgnorePointer(
|
||||
ignoring: _isPinching,
|
||||
child: CodeEditor(
|
||||
key: ValueKey(_currentLoadedPath),
|
||||
controller: controller,
|
||||
focusNode: _focusNode,
|
||||
@@ -594,6 +674,43 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
// 双指缩放实时字号悬浮胶囊提示
|
||||
if (_isPinching && _activeZoomFontSize != null)
|
||||
Positioned(
|
||||
top: 16,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Center(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: activeTheme.backgroundColor.computeLuminance() > 0.5
|
||||
? Colors.black.withValues(alpha: 0.75)
|
||||
: Colors.white.withValues(alpha: 0.85),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.2),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
'${_activeZoomFontSize!.round()} px',
|
||||
style: TextStyle(
|
||||
color: activeTheme.backgroundColor.computeLuminance() > 0.5
|
||||
? Colors.white
|
||||
: Colors.black87,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.3,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -298,7 +298,10 @@ class _TerminalSelectionOverlayState extends State<TerminalSelectionOverlay> {
|
||||
onCopy: _handleCopy,
|
||||
onPaste: _handlePaste,
|
||||
onSelectAll: _handleSelectAll,
|
||||
onDismiss: _hideMenu,
|
||||
onDismiss: () {
|
||||
_hideMenu();
|
||||
widget.controller.clearSelection();
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -330,6 +330,7 @@ class _CodeFieldRender extends RenderBox implements MouseTrackerAnnotation {
|
||||
_textStyle = value;
|
||||
if (comparison.index >= RenderComparison.layout.index) {
|
||||
_calculatePreferredLineHeight();
|
||||
_displayParagraphs.clear();
|
||||
markNeedsLayout();
|
||||
} else {
|
||||
markNeedsPaint();
|
||||
@@ -1342,9 +1343,24 @@ class _CodeFieldRender extends RenderBox implements MouseTrackerAnnotation {
|
||||
if (target <= paddingTop) {
|
||||
startIndex = 0;
|
||||
} else {
|
||||
startIndex = min(((target - paddingTop) / _preferredLineHeight).ceil(), max(0, _codes.length - 1));
|
||||
startIndex = min(((target - paddingTop) / _preferredLineHeight).floor(), max(0, _codes.length - 1));
|
||||
}
|
||||
_displayParagraphs.addAll(_buildDisplayRenderParagraphs(startIndex, effectiveWidth));
|
||||
} else if (_horizontalViewport != null) {
|
||||
// In horizontal scrolling (unwrapped) mode, every line has height == _preferredLineHeight.
|
||||
// There is no line wrapping, so delta is strictly 0 and viewport correction should never occur.
|
||||
final int startIndex;
|
||||
if (target <= paddingTop) {
|
||||
startIndex = 0;
|
||||
} else {
|
||||
startIndex = min(((target - paddingTop) / _preferredLineHeight).floor(), max(0, _codes.length - 1));
|
||||
}
|
||||
if (_displayParagraphs.first.index != startIndex ||
|
||||
target < _displayParagraphs.first.top ||
|
||||
target + size.height > _displayParagraphs.last.bottom) {
|
||||
_displayParagraphs.clear();
|
||||
_displayParagraphs.addAll(_buildDisplayRenderParagraphs(startIndex, effectiveWidth));
|
||||
}
|
||||
} else {
|
||||
if (_codes.length <= _displayParagraphs.first.index) {
|
||||
_displayParagraphs.clear();
|
||||
@@ -1364,7 +1380,11 @@ class _CodeFieldRender extends RenderBox implements MouseTrackerAnnotation {
|
||||
break;
|
||||
}
|
||||
}
|
||||
final bool isPinchLocked = _verticalViewport is CodeEditorScrollPosition &&
|
||||
(_verticalViewport as CodeEditorScrollPosition).isPinchLocked;
|
||||
if (!isPinchLocked) {
|
||||
_verticalViewport.correctBy(delta);
|
||||
}
|
||||
_displayParagraphs.clear();
|
||||
_displayParagraphs.addAll(_buildDisplayRenderParagraphs(startIndex, effectiveWidth));
|
||||
} else if (target > _displayParagraphs.last.bottom) {
|
||||
@@ -1372,7 +1392,7 @@ class _CodeFieldRender extends RenderBox implements MouseTrackerAnnotation {
|
||||
if (target <= paddingTop) {
|
||||
startIndex = 0;
|
||||
} else {
|
||||
startIndex = min((target / _preferredLineHeight).floor(), max(0, _codes.length - 1));
|
||||
startIndex = min(((target - paddingTop) / _preferredLineHeight).floor(), max(0, _codes.length - 1));
|
||||
}
|
||||
_displayParagraphs.clear();
|
||||
_displayParagraphs.addAll(_buildDisplayRenderParagraphs(startIndex, effectiveWidth));
|
||||
@@ -1387,7 +1407,11 @@ class _CodeFieldRender extends RenderBox implements MouseTrackerAnnotation {
|
||||
delta += paragraph.paragraph.height - _preferredLineHeight;
|
||||
}
|
||||
assert(startIndex >= 0);
|
||||
final bool isPinchLocked = _verticalViewport is CodeEditorScrollPosition &&
|
||||
(_verticalViewport as CodeEditorScrollPosition).isPinchLocked;
|
||||
if (!isPinchLocked) {
|
||||
_verticalViewport.correctBy(-delta);
|
||||
}
|
||||
_displayParagraphs.clear();
|
||||
_displayParagraphs.addAll(_buildDisplayRenderParagraphs(startIndex, effectiveWidth));
|
||||
}
|
||||
@@ -1405,8 +1429,12 @@ class _CodeFieldRender extends RenderBox implements MouseTrackerAnnotation {
|
||||
final double extraBottom = _extraVerticalScroll ?? max(0.0, size.height * 0.5);
|
||||
_verticalViewportSize = max(0, totalHeight - size.height + extraBottom);
|
||||
if (_verticalViewport.pixels > _verticalViewportSize!) {
|
||||
final bool isPinchLocked = _verticalViewport is CodeEditorScrollPosition &&
|
||||
(_verticalViewport as CodeEditorScrollPosition).isPinchLocked;
|
||||
if (!isPinchLocked) {
|
||||
_verticalViewport.correctBy(_verticalViewportSize! - _verticalViewport.pixels);
|
||||
}
|
||||
}
|
||||
_verticalViewport.applyContentDimensions(0, _verticalViewportSize!);
|
||||
if (_horizontalViewport != null) {
|
||||
final double maxWidth = _displayParagraphs.map((e) => e.width).reduce(max);
|
||||
@@ -1757,7 +1785,7 @@ class _CodeCursorLinePainter extends _CodeFieldExtraPainter {
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size, _CodeFieldRender render) {
|
||||
if (_color == null || _color == Colors.transparent || _color!.alpha == 0) {
|
||||
if (_color == null || _color == Colors.transparent || _color!.a == 0.0) {
|
||||
return;
|
||||
}
|
||||
if (!_selection.isCollapsed) {
|
||||
@@ -1811,7 +1839,7 @@ abstract class _CodeFieldSelectionsPainter extends _CodeFieldExtraPainter {
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size, _CodeFieldRender render) {
|
||||
if (_color == Colors.transparent || _color.alpha == 0) {
|
||||
if (_color == Colors.transparent || _color.a == 0.0) {
|
||||
return;
|
||||
}
|
||||
final List<CodeLineRenderParagraph> paragraphs = render.displayParagraphs;
|
||||
@@ -1971,7 +1999,7 @@ class _CodeFieldCursorPainter extends _CodeFieldExtraPainter {
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size, _CodeFieldRender render) {
|
||||
if (!_visible || !_willDraw || _color == Colors.transparent || _color.alpha == 0) {
|
||||
if (!_visible || !_willDraw || _color == Colors.transparent || _color.a == 0.0) {
|
||||
return;
|
||||
}
|
||||
final CodeLineRenderParagraph? paragraph = render.findDisplayParagraphByLineIndex(_position.index);
|
||||
@@ -2053,7 +2081,7 @@ class _CodeFieldFloatingCursorPainter extends _CodeFieldExtraPainter {
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size, _CodeFieldRender render) {
|
||||
if (!_position.isActive() || _color == Colors.transparent || _color.alpha == 0) {
|
||||
if (!_position.isActive() || _color == Colors.transparent || _color.a == 0.0) {
|
||||
return;
|
||||
}
|
||||
_drawFloatingCaret(canvas, _position.floatingCursorOffset!, size);
|
||||
|
||||
@@ -21,9 +21,12 @@ class _ParagraphImpl extends IParagraph {
|
||||
required this.paragraph,
|
||||
required bool trucated,
|
||||
required double preferredLineHeight,
|
||||
bool isSingleLine = false,
|
||||
}) : _trucated = trucated,
|
||||
_preferredLineHeight = preferredLineHeight,
|
||||
_lineCount = (paragraph.height / preferredLineHeight).ceil();
|
||||
_lineCount = isSingleLine
|
||||
? 1
|
||||
: max(1, (paragraph.height / preferredLineHeight).round());
|
||||
|
||||
int get runeLength => text.runes.length;
|
||||
|
||||
@@ -314,12 +317,14 @@ class _CodeParagraphProvider {
|
||||
span.build(builder);
|
||||
final ui.Paragraph paragraph = builder.build();
|
||||
paragraph.layout(_constraints!);
|
||||
final bool isSingleLine = _constraints!.width.isInfinite;
|
||||
return _ParagraphImpl(
|
||||
text: plainText,
|
||||
span: span,
|
||||
paragraph: paragraph,
|
||||
trucated: trucated,
|
||||
preferredLineHeight: _preferredLineHeight!,
|
||||
isSingleLine: isSingleLine,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ typedef CodeScrollbarBuilder = Widget Function(BuildContext context, Widget chil
|
||||
/// to swipe twice horizontally to start horizontal scrolling. Overriding
|
||||
/// [shouldIgnorePointer] to return false allows bidirectional scroll gestures to
|
||||
/// seamlessly take over on the very first swipe.
|
||||
|
||||
class CodeEditorScrollPosition extends ScrollPositionWithSingleContext {
|
||||
CodeEditorScrollPosition({
|
||||
required super.physics,
|
||||
@@ -23,6 +24,24 @@ class CodeEditorScrollPosition extends ScrollPositionWithSingleContext {
|
||||
super.debugLabel,
|
||||
});
|
||||
|
||||
bool _isPinchLocked = false;
|
||||
bool get isPinchLocked => _isPinchLocked;
|
||||
set isPinchLocked(bool value) {
|
||||
if (_isPinchLocked == value) return;
|
||||
_isPinchLocked = value;
|
||||
if (value) {
|
||||
stopScrolling();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void applyUserOffset(double delta) {
|
||||
if (_isPinchLocked) {
|
||||
return;
|
||||
}
|
||||
super.applyUserOffset(delta);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get shouldIgnorePointer => false;
|
||||
|
||||
@@ -49,13 +68,25 @@ class CodeEditorScrollController extends ScrollController {
|
||||
super.onDetach,
|
||||
});
|
||||
|
||||
bool _isPinchLocked = false;
|
||||
bool get isPinchLocked => _isPinchLocked;
|
||||
set isPinchLocked(bool value) {
|
||||
if (_isPinchLocked == value) return;
|
||||
_isPinchLocked = value;
|
||||
for (final position in positions) {
|
||||
if (position is CodeEditorScrollPosition) {
|
||||
position.isPinchLocked = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
ScrollPosition createScrollPosition(
|
||||
ScrollPhysics physics,
|
||||
ScrollContext context,
|
||||
ScrollPosition? oldPosition,
|
||||
) {
|
||||
return CodeEditorScrollPosition(
|
||||
final position = CodeEditorScrollPosition(
|
||||
physics: physics,
|
||||
context: context,
|
||||
initialPixels: delegate?.initialScrollOffset ?? initialScrollOffset,
|
||||
@@ -63,11 +94,16 @@ class CodeEditorScrollController extends ScrollController {
|
||||
oldPosition: oldPosition,
|
||||
debugLabel: delegate?.debugLabel ?? debugLabel,
|
||||
);
|
||||
position.isPinchLocked = _isPinchLocked;
|
||||
return position;
|
||||
}
|
||||
|
||||
@override
|
||||
void attach(ScrollPosition position) {
|
||||
super.attach(position);
|
||||
if (position is CodeEditorScrollPosition) {
|
||||
position.isPinchLocked = _isPinchLocked;
|
||||
}
|
||||
if (delegate != null && !delegate!.positions.contains(position)) {
|
||||
delegate!.attach(position);
|
||||
}
|
||||
@@ -86,7 +122,7 @@ class CodeEditorScrollController extends ScrollController {
|
||||
for (final position in positions) {
|
||||
if (position is CodeEditorScrollPosition) {
|
||||
position.stopScrolling();
|
||||
} else if (position is ScrollPositionWithSingleContext && position.activity?.isScrolling == true) {
|
||||
} else if (position is ScrollPositionWithSingleContext) {
|
||||
position.goIdle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,6 +300,7 @@ class TerminalViewState extends State<TerminalView> {
|
||||
terminalView: this,
|
||||
terminalController: _controller,
|
||||
onTapUp: _onTapUp,
|
||||
onSingleTapUp: _onSingleTapUp,
|
||||
onTapDown: _onTapDown,
|
||||
onSecondaryTapDown:
|
||||
widget.onSecondaryTapDown != null ? _onSecondaryTapDown : null,
|
||||
@@ -345,8 +346,8 @@ class TerminalViewState extends State<TerminalView> {
|
||||
widget.onTapUp?.call(details, offset);
|
||||
}
|
||||
|
||||
void _onTapDown(_) {
|
||||
if (_controller.selection != null) {
|
||||
void _onSingleTapUp(TapUpDetails details) {
|
||||
if (_controller.selection != null && !_controller.selection!.isCollapsed) {
|
||||
_controller.clearSelection();
|
||||
} else {
|
||||
if (!widget.hardwareKeyboardOnly) {
|
||||
@@ -355,6 +356,13 @@ class TerminalViewState extends State<TerminalView> {
|
||||
_focusNode.requestFocus();
|
||||
}
|
||||
}
|
||||
final offset = renderTerminal.getCellOffset(details.localPosition);
|
||||
widget.onTapUp?.call(details, offset);
|
||||
}
|
||||
|
||||
void _onTapDown(_) {
|
||||
// Intentionally empty: tapping down (PointerDown) must not open the soft keyboard,
|
||||
// ensuring long-press can select text without triggering keyboard pop-up or scroll jumps.
|
||||
}
|
||||
|
||||
void _onSecondaryTapDown(TapDownDetails details) {
|
||||
@@ -431,7 +439,8 @@ class TerminalViewState extends State<TerminalView> {
|
||||
}
|
||||
|
||||
void _onKeyboardShow() {
|
||||
if (_focusNode.hasFocus) {
|
||||
if (_focusNode.hasFocus &&
|
||||
(_controller.selection == null || _controller.selection!.isCollapsed)) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_scrollToBottom();
|
||||
});
|
||||
|
||||
@@ -64,6 +64,13 @@ class _TerminalGestureDetectorState extends State<TerminalGestureDetector> {
|
||||
// subsequent tap up / tap hold of the same tap.
|
||||
bool _isDoubleTap = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_doubleTapTimer?.cancel();
|
||||
_doubleTapTimer = null;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// The down handler is force-run on success of a single tap and optimistically
|
||||
// run before a long press success.
|
||||
void _handleTapDown(TapDownDetails details) {
|
||||
@@ -84,12 +91,19 @@ class _TerminalGestureDetectorState extends State<TerminalGestureDetector> {
|
||||
void _handleTapUp(TapUpDetails details) {
|
||||
if (!_isDoubleTap) {
|
||||
widget.onSingleTapUp?.call(details);
|
||||
widget.onTapUp?.call(details);
|
||||
_lastTapOffset = details.globalPosition;
|
||||
_doubleTapTimer = Timer(kDoubleTapTimeout, _doubleTapTimeout);
|
||||
}
|
||||
_isDoubleTap = false;
|
||||
}
|
||||
|
||||
void _handleTapCancel() {
|
||||
_doubleTapTimer?.cancel();
|
||||
_doubleTapTimeout();
|
||||
_isDoubleTap = false;
|
||||
}
|
||||
|
||||
void _doubleTapTimeout() {
|
||||
_doubleTapTimer = null;
|
||||
_lastTapOffset = null;
|
||||
@@ -115,6 +129,7 @@ class _TerminalGestureDetectorState extends State<TerminalGestureDetector> {
|
||||
instance
|
||||
..onTapDown = _handleTapDown
|
||||
..onTapUp = _handleTapUp
|
||||
..onTapCancel = _handleTapCancel
|
||||
..onSecondaryTapDown = widget.onSecondaryTapDown
|
||||
..onSecondaryTapUp = widget.onSecondaryTapUp
|
||||
..onTertiaryTapDown = widget.onTertiaryTapDown
|
||||
|
||||
@@ -0,0 +1,304 @@
|
||||
import 'dart:ui';
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/models/terminal_session.dart';
|
||||
import 'package:code_editor/providers/settings_provider.dart';
|
||||
import 'package:code_editor/providers/terminal_provider.dart';
|
||||
import 'package:code_editor/views/settings_view.dart';
|
||||
import 'package:code_editor/views/terminal_view.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:xterm/xterm.dart' as xterm;
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('Terminal Font Size & Gesture Tests', () {
|
||||
setUp(() {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
});
|
||||
|
||||
test('SettingsProvider: terminalFontSize defaults, updates, clamps, and persists', () async {
|
||||
SharedPreferences.setMockInitialValues({'terminal_font_size': 16.0});
|
||||
final provider = SettingsProvider();
|
||||
await provider.init();
|
||||
|
||||
expect(provider.terminalFontSize, 16.0);
|
||||
|
||||
// Updates and clamps between 8.0 and 32.0
|
||||
await provider.setTerminalFontSize(20.0);
|
||||
expect(provider.terminalFontSize, 20.0);
|
||||
|
||||
await provider.setTerminalFontSize(5.0);
|
||||
expect(provider.terminalFontSize, 8.0);
|
||||
|
||||
await provider.setTerminalFontSize(50.0);
|
||||
expect(provider.terminalFontSize, 32.0);
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
expect(prefs.getDouble('terminal_font_size'), 32.0);
|
||||
});
|
||||
|
||||
test('L10n: terminalFontSize strings exist in both zh and en', () {
|
||||
final zh = lookupAppLocalizations(const Locale('zh'));
|
||||
final en = lookupAppLocalizations(const Locale('en'));
|
||||
|
||||
expect(zh.terminalFontSize, '终端字号');
|
||||
expect(zh.terminalFontSizeDialogTitle, '终端字号');
|
||||
|
||||
expect(en.terminalFontSize, 'Terminal Font Size');
|
||||
expect(en.terminalFontSizeDialogTitle, 'Terminal Font Size');
|
||||
});
|
||||
|
||||
testWidgets('SettingsView: displays terminal font size tile with controls and dialog', (tester) async {
|
||||
final settings = SettingsProvider();
|
||||
await settings.init();
|
||||
await settings.setTerminalFontSize(14.0);
|
||||
|
||||
await tester.pumpWidget(
|
||||
ChangeNotifierProvider<SettingsProvider>.value(
|
||||
value: settings,
|
||||
child: const MaterialApp(
|
||||
locale: Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: SettingsView(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Find terminal font size tile
|
||||
final tileFinder = find.widgetWithText(ListTile, '终端字号');
|
||||
await tester.scrollUntilVisible(tileFinder, 100);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tileFinder, findsOneWidget);
|
||||
expect(find.text('14 pt'), findsOneWidget);
|
||||
|
||||
// Increase font size via + button
|
||||
final increaseFinder = find.byTooltip('增大字号').last;
|
||||
await tester.tap(increaseFinder);
|
||||
await tester.pumpAndSettle();
|
||||
expect(settings.terminalFontSize, 15.0);
|
||||
|
||||
// Decrease font size via - button
|
||||
final decreaseFinder = find.byTooltip('减小字号').last;
|
||||
await tester.tap(decreaseFinder);
|
||||
await tester.pumpAndSettle();
|
||||
expect(settings.terminalFontSize, 14.0);
|
||||
|
||||
// Open dialog by tapping tile
|
||||
await tester.tap(tileFinder);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
expect(find.text('终端字号'), findsWidgets);
|
||||
expect(find.byType(Slider), findsOneWidget);
|
||||
|
||||
// Tap done
|
||||
await tester.tap(find.text('完成'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('TerminalView: textStyle uses terminalFontSize from settings', (tester) async {
|
||||
final settings = SettingsProvider();
|
||||
await settings.init();
|
||||
await settings.setTerminalFontSize(18.0);
|
||||
|
||||
final terminalProvider = TerminalProvider();
|
||||
final session = terminalProvider.createSession(
|
||||
name: 'test-session',
|
||||
autoStartProcess: false,
|
||||
activate: true,
|
||||
);
|
||||
session.terminal.write('Test Terminal Output\r\n');
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<SettingsProvider>.value(value: settings),
|
||||
ChangeNotifierProvider<TerminalProvider>.value(value: terminalProvider),
|
||||
],
|
||||
child: const MaterialApp(
|
||||
locale: Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: TerminalView(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify that xterm.TerminalView receives fontSize 18.0
|
||||
final termView = tester.widget<xterm.TerminalView>(find.byType(xterm.TerminalView));
|
||||
expect(termView.textStyle.fontSize, 18.0);
|
||||
|
||||
// Change font size in settings
|
||||
await settings.setTerminalFontSize(22.0);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final updatedTermView = tester.widget<xterm.TerminalView>(find.byType(xterm.TerminalView));
|
||||
expect(updatedTermView.textStyle.fontSize, 22.0);
|
||||
});
|
||||
|
||||
testWidgets('TerminalView: two-finger pinch-to-zoom scales font size and persists', (tester) async {
|
||||
final settings = SettingsProvider();
|
||||
await settings.init();
|
||||
await settings.setTerminalFontSize(14.0);
|
||||
|
||||
final terminalProvider = TerminalProvider();
|
||||
final session = terminalProvider.createSession(
|
||||
name: 'pinch-session',
|
||||
autoStartProcess: false,
|
||||
activate: true,
|
||||
);
|
||||
session.terminal.write('Hello Pinch Zoom\r\n');
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<SettingsProvider>.value(value: settings),
|
||||
ChangeNotifierProvider<TerminalProvider>.value(value: terminalProvider),
|
||||
],
|
||||
child: const MaterialApp(
|
||||
locale: Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 600,
|
||||
height: 800,
|
||||
child: TerminalView(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final center = tester.getCenter(find.byType(xterm.TerminalView));
|
||||
|
||||
// Simulate pinch zoom with two touch pointers
|
||||
final touch1 = await tester.startGesture(center - const Offset(40, 0), kind: PointerDeviceKind.touch, pointer: 101);
|
||||
final touch2 = await tester.startGesture(center + const Offset(40, 0), kind: PointerDeviceKind.touch, pointer: 102);
|
||||
await tester.pump();
|
||||
|
||||
// Move fingers apart: distance doubles from 80 to 160 -> scale ~ 2.0
|
||||
await touch1.moveTo(center - const Offset(80, 0));
|
||||
await touch2.moveTo(center + const Offset(80, 0));
|
||||
await tester.pump();
|
||||
|
||||
final scaledTermView = tester.widget<xterm.TerminalView>(find.byType(xterm.TerminalView));
|
||||
expect(scaledTermView.textStyle.fontSize, greaterThan(14.0));
|
||||
|
||||
// Release fingers
|
||||
await touch1.up();
|
||||
await touch2.up();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Settings should now be updated and persisted
|
||||
expect(settings.terminalFontSize, greaterThan(14.0));
|
||||
});
|
||||
|
||||
testWidgets('TerminalView gesture: Touch down does NOT request keyboard; Long press selects text without keyboard pop-up', (tester) async {
|
||||
int textInputAttachCount = 0;
|
||||
int textInputShowCount = 0;
|
||||
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.textInput,
|
||||
(MethodCall methodCall) async {
|
||||
if (methodCall.method == 'TextInput.attach') {
|
||||
textInputAttachCount++;
|
||||
return null;
|
||||
}
|
||||
if (methodCall.method == 'TextInput.show') {
|
||||
textInputShowCount++;
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final settings = SettingsProvider();
|
||||
await settings.init();
|
||||
|
||||
final terminalProvider = TerminalProvider();
|
||||
final session = terminalProvider.createSession(
|
||||
name: 'gesture-session',
|
||||
autoStartProcess: false,
|
||||
activate: true,
|
||||
);
|
||||
session.terminal.write('apple banana cherry\r\n');
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<SettingsProvider>.value(value: settings),
|
||||
ChangeNotifierProvider<TerminalProvider>.value(value: terminalProvider),
|
||||
],
|
||||
child: const MaterialApp(
|
||||
locale: Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 600,
|
||||
height: 800,
|
||||
child: TerminalView(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final targetPos = tester.getTopLeft(find.byType(xterm.TerminalView)) + const Offset(20, 20);
|
||||
|
||||
textInputShowCount = 0;
|
||||
|
||||
// 1. Touch down on screen
|
||||
final gesture = await tester.startGesture(targetPos, kind: PointerDeviceKind.touch, pointer: 201);
|
||||
await tester.pump();
|
||||
|
||||
// Crucial: PointerDown must NOT show the keyboard!
|
||||
expect(textInputShowCount, 0, reason: 'Touch down must not optimistically request soft keyboard');
|
||||
|
||||
// 2. Hold to long-press (> 500ms)
|
||||
await tester.pump(const Duration(milliseconds: 600));
|
||||
|
||||
// Word should now be selected, and keyboard should STILL not have been shown!
|
||||
final termView = tester.widget<xterm.TerminalView>(find.byType(xterm.TerminalView));
|
||||
expect(termView.controller?.selection, isNotNull);
|
||||
expect(termView.controller?.selection!.isCollapsed, isFalse);
|
||||
expect(textInputShowCount, 0, reason: 'Long press must not show soft keyboard');
|
||||
|
||||
// 3. Lift finger: Floating menu (复制, 粘贴, 全选) should appear
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('复制'), findsOneWidget);
|
||||
expect(textInputShowCount, 0, reason: 'Lifting finger after long-press selection must not show soft keyboard');
|
||||
|
||||
// 4. Tap with active selection: Clears selection and does NOT open keyboard
|
||||
await tester.tapAt(targetPos + const Offset(100, 100));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(termView.controller?.selection, isNull);
|
||||
expect(find.text('复制'), findsNothing);
|
||||
expect(textInputShowCount, 0, reason: 'Tapping to clear selection must not open soft keyboard');
|
||||
|
||||
// 5. Single tap when there is NO selection: Now opens the keyboard!
|
||||
await tester.tapAt(targetPos + const Offset(100, 100));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pump(const Duration(milliseconds: 350));
|
||||
|
||||
expect(textInputShowCount, greaterThanOrEqualTo(1), reason: 'Single tap with no selection must open soft keyboard');
|
||||
});
|
||||
});
|
||||
}
|
||||
+90
-2
@@ -2908,16 +2908,104 @@ void main() {
|
||||
await gesture2.moveTo(const Offset(200, 500));
|
||||
await tester.pump();
|
||||
|
||||
// Without focal anchor, vScroller.offset would remain 0.0, causing bottom text to fly down.
|
||||
// With focal anchor, vScroller.offset is compensated to keep the focal point steady.
|
||||
// Real-time live continuous zoom updates both scroll offset and displays HUD badge
|
||||
expect(find.text('21 px'), findsOneWidget);
|
||||
expect(vScroller.offset, greaterThan(100.0));
|
||||
|
||||
await gesture1.up();
|
||||
await gesture2.up();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// On gesture completion, font size is committed and scroll offset is compensated to anchor focal point.
|
||||
expect(settingsProvider.fontSize, 21.0);
|
||||
expect(vScroller.offset, greaterThan(100.0));
|
||||
expect(find.text('21 px'), findsNothing);
|
||||
|
||||
try {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
} catch (_) {}
|
||||
});
|
||||
|
||||
testWidgets('CodeEditorWidget pinch-to-zoom out does not jump or teleport when lines scroll into or out of viewport', (tester) async {
|
||||
final tempDir = Directory.systemTemp.createTempSync('editor_zoom_out_smooth_test');
|
||||
final lines = List.generate(100, (i) => 'Line $i: const value = "test-$i";').join('\n');
|
||||
final testFile = File('${tempDir.path}/test.dart')..writeAsStringSync(lines);
|
||||
|
||||
final settingsProvider = SettingsProvider();
|
||||
await settingsProvider.init();
|
||||
await settingsProvider.setFontSize(20.0);
|
||||
|
||||
final tabProvider = TabProvider();
|
||||
await tabProvider.init();
|
||||
tabProvider.openTabs.add(
|
||||
EditorTabItem(
|
||||
path: testFile.path,
|
||||
content: lines,
|
||||
originalContent: lines,
|
||||
isLoaded: true,
|
||||
isModified: false,
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: settingsProvider),
|
||||
ChangeNotifierProvider.value(value: tabProvider),
|
||||
],
|
||||
child: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 400,
|
||||
height: 500,
|
||||
child: CodeEditorWidget(
|
||||
rootPath: tempDir.path,
|
||||
filePath: testFile.path,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final codeEditor = tester.widget<CodeEditor>(find.byType(CodeEditor));
|
||||
final scrollController = codeEditor.scrollController!;
|
||||
final vScroller = scrollController.verticalScroller;
|
||||
|
||||
// Scroll down to line 20 first
|
||||
vScroller.jumpTo(300.0);
|
||||
await tester.pumpAndSettle();
|
||||
expect(vScroller.offset, 300.0);
|
||||
|
||||
final gesture1 = await tester.createGesture();
|
||||
final gesture2 = await tester.createGesture();
|
||||
|
||||
// Down with 2 fingers distance 200.0
|
||||
await gesture1.down(const Offset(200, 150));
|
||||
await gesture2.down(const Offset(200, 350));
|
||||
await tester.pump();
|
||||
|
||||
// Zoom out gradually in multiple steps crossing multiple line boundaries
|
||||
double prevOffset = vScroller.offset;
|
||||
for (int step = 1; step <= 5; step++) {
|
||||
final newY = 350.0 - step * 15.0; // Distance decreases from 200 -> 185 -> 170 -> 155...
|
||||
await gesture2.moveTo(Offset(200, newY));
|
||||
await tester.pump();
|
||||
|
||||
final currentOffset = vScroller.offset;
|
||||
// As we zoom out, text shrinks so focal anchor moves offset downward smoothly (less scroll offset needed)
|
||||
expect(currentOffset, lessThanOrEqualTo(prevOffset));
|
||||
// Ensure no sudden teleportation jump (each step moves smoothly and never jumps by a full line height reversal)
|
||||
expect(prevOffset - currentOffset, lessThan(100.0));
|
||||
prevOffset = currentOffset;
|
||||
}
|
||||
|
||||
await gesture1.up();
|
||||
await gesture2.up();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(settingsProvider.fontSize, lessThan(20.0));
|
||||
|
||||
try {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
|
||||
Reference in new issue
Block a user