Files
clide/test/builtin/keybindings_ui/preset_commands_test.dart
T
jpmschweitzerandClaude Opus 4.8 727fe8fdd4 feat(settings): Keymap category — preset select (T-451)
The keybindings-ui extension contributes a Keymap SettingsCategory: a preset
select (Default / Vim / VS Code / JetBrains) reading the active preset from
kKeymapPresetSetting. Picking one routes through a new schema affordance —
SettingsField.applyCommandPrefix — running `keymap.preset.<value>`, which calls
KeymapService.setPreset to persist and reload the layered keymap live. The
prefix path keeps the engine generic: settings a subsystem applies via a
command (rather than a bare key write) declare the prefix; the scope tag and
current-value read still use the key.

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

63 lines
2.4 KiB
Dart

/// T-65: the keybindings UI contributes palette commands that switch the
/// active keymap preset.
library;
import 'package:clide/builtin/keybindings_ui/keybindings_ui.dart';
import 'package:clide/extension/extension.dart';
import 'package:clide/kernel/kernel.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../helpers/kernel_fixture.dart';
void main() {
late KernelFixture f;
setUp(() async {
f = await KernelFixture.create();
f.services.extensions.register(KeybindingsUiExtension());
await f.services.extensions.activate('builtin.keybindings-ui');
});
tearDown(() => f.dispose());
test('identifies itself', () {
final ext = KeybindingsUiExtension();
expect(ext.id, 'builtin.keybindings-ui');
expect(ext.title, 'Keybindings UI');
expect(ext.version, '0.1.0');
});
test('deactivate drops the keymap reference', () async {
await f.services.extensions.deactivate('builtin.keybindings-ui');
// Re-activating is clean (no retained state).
await f.services.extensions.activate('builtin.keybindings-ui');
expect(f.services.commands.get('keymap.preset.vim'), isNotNull);
});
test('contributes a switch command per shipped preset', () {
expect(f.services.commands.get('keymap.preset.vim'), isNotNull);
expect(f.services.commands.get('keymap.preset.default'), isNotNull);
});
test('running the vim command switches the active preset', () async {
await f.services.commands.execute('keymap.preset.vim');
expect(f.services.settings.get<String>(kKeymapPresetSetting), 'vim');
});
test('switching back to default works', () async {
await f.services.commands.execute('keymap.preset.vim');
await f.services.commands.execute('keymap.preset.default');
expect(f.services.settings.get<String>(kKeymapPresetSetting), 'default');
});
test('contributes a Keymap settings category routed through the preset commands (T-451)', () {
final category = KeybindingsUiExtension().contributions
.whereType<SettingsCategoryContribution>()
.firstWhere((c) => c.id == 'keymap')
.category;
expect(category.title, 'Keymap');
final field = category.sections.expand((s) => s.fields).firstWhere((f) => f.key == kKeymapPresetSetting);
expect(field.kind, SettingsFieldKind.select);
expect(field.applyCommandPrefix, 'keymap.preset.');
expect(field.options.map((o) => o.value), containsAll(['default', 'vim', 'vscode', 'jetbrains']));
});
}