Files
clide/test/builtin/editor/vim_editor_test.dart
T
jpmschweitzerandClaude Opus 4.8 6d0ebab721 chore: adopt Dart 3.9 toolchain — honest floor + tall-style reformat (T-353)
Raise the declared minimums in pubspec.yaml to what our deps already
require: Flutter >=3.35.0 / Dart >=3.9.0 (was 3.19.0 / 3.5.0). alchemist
0.12 needs Flutter 3.32; Dart 3.9 first ships in Flutter 3.35, so 3.35 is
the binding floor. Pin the exact build toolchain in .fvmrc (Flutter
3.44.1).

Moving to the Dart 3.9 language level switches `dart format` to the new
"tall" style and enables two new lints. This commit is the resulting
mechanical churn, isolated from any behaviour change:
  - whole-tree `dart format` reformat (tall style)
  - `dart fix` for unnecessary_underscores + use_null_aware_elements

No runtime behaviour change; `make test` green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-11 12:11:53 +02:00

126 lines
3.9 KiB
Dart

/// T-206: the editor's modal wiring. With a `vim.normal` scope flag set
/// and a sequence binding registered, a bare key drives the buffer (and
/// the editor goes read-only so the key can't also type); under no Vim
/// mode the editor types normally.
library;
import 'package:clide/builtin/editor/src/editor_view.dart';
import 'package:clide/clide.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../helpers/kernel_fixture.dart';
import '../../helpers/widget_harness.dart';
IpcResponse _ok(Map<String, Object?> data) => IpcResponse.ok(id: '', data: data);
void main() {
late KernelFixture f;
setUp(() async => f = await KernelFixture.create());
tearDown(() => f.dispose());
void stubOneBuffer(String content) {
f.ipc.stub(
'editor.list',
(_) async => _ok({
'buffers': [
{'id': 'b_1', 'path': 'lib/a.dart', 'dirty': false},
],
}),
);
f.ipc.stub(
'editor.active',
(_) async => _ok({
'active': {'id': 'b_1'},
}),
);
f.ipc.stub(
'editor.read',
(_) async => _ok({
'id': 'b_1',
'path': 'lib/a.dart',
'content': content,
'selection': {'start': 0, 'end': 0},
'dirty': false,
}),
);
}
Future<void> pumpEditor(WidgetTester tester) async {
await tester.pumpWidget(harness(f, const EditorView()));
await tester.pumpAndSettle();
// Tap the very start so the caret lands at offset 0 (a centred tap
// would put it at end-of-text and make column-sensitive ops no-ops).
await tester.tapAt(tester.getTopLeft(find.byType(EditableText)) + const Offset(1, 1));
await tester.pump();
}
testWidgets('normal-mode x deletes the char under the caret', (tester) async {
String? sentText;
f.ipc.stub('editor.set-content', (a) async {
sentText = a['text'] as String?;
return _ok(const {});
});
f.services.keymap.registerCommandBinding('x', 'editor.vim.deleteChar', when: 'vim.normal');
f.services.keymap.setScopeFlag('vim.normal', true);
stubOneBuffer('hello');
await pumpEditor(tester);
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
await tester.pumpAndSettle();
expect(sentText, 'ello');
});
testWidgets('dd sequence deletes the line', (tester) async {
String? sentText;
f.ipc.stub('editor.set-content', (a) async {
sentText = a['text'] as String?;
return _ok(const {});
});
f.services.keymap.registerCommandBinding('d d', 'editor.vim.deleteLine', when: 'vim.normal');
f.services.keymap.setScopeFlag('vim.normal', true);
stubOneBuffer('one\ntwo');
await pumpEditor(tester);
await tester.sendKeyEvent(LogicalKeyboardKey.keyD);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.keyD);
await tester.pumpAndSettle();
expect(sentText, 'two');
});
testWidgets('the editor is read-only in normal mode, writable otherwise', (tester) async {
f.services.keymap.setScopeFlag('vim.normal', true);
stubOneBuffer('hello');
await pumpEditor(tester);
expect(tester.widget<EditableText>(find.byType(EditableText)).readOnly, isTrue);
f.services.keymap.setScopeFlag('vim.normal', false);
await tester.pumpAndSettle();
expect(tester.widget<EditableText>(find.byType(EditableText)).readOnly, isFalse);
});
testWidgets('an unbound bare key in normal mode is swallowed (no edit)', (tester) async {
String? lastText;
f.ipc.stub('editor.set-content', (a) async {
lastText = a['text'] as String?;
return _ok(const {});
});
f.services.keymap.setScopeFlag('vim.normal', true);
stubOneBuffer('hello');
await pumpEditor(tester);
await tester.sendKeyEvent(LogicalKeyboardKey.keyZ);
await tester.pumpAndSettle();
// The buffer text is never altered by an unbound normal-mode key.
expect(lastText, anyOf(isNull, 'hello'));
});
}