Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/bao_markdown/lib/src/editor/md_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,18 @@ class MarkdownEditorState extends State<MarkdownEditor>
}
return KeyEventResult.handled;
}
// Ctrl+Y redoes too off Apple's, as Windows has it (and the Edit menu
// says): the defaults have only Ctrl+Shift+Z.
if (key == LogicalKeyboardKey.keyY &&
keyboard.isControlPressed &&
!keyboard.isShiftPressed &&
!keyboard.isMetaPressed &&
!keyboard.isAltPressed &&
defaultTargetPlatform != TargetPlatform.macOS &&
defaultTargetPlatform != TargetPlatform.iOS) {
controller.redo();
return KeyEventResult.handled;
}
// Home and End to the line's ends, Shift selecting to them, as an
// editor has them: macOS's defaults scroll the document instead, and
// select to its ends with Shift. The numpad's 7 and 1 are Home and End
Expand Down
44 changes: 44 additions & 0 deletions test/chat/composer_polish_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import 'package:baocode/chat/composer/composer_polish.dart';
import 'package:baocode/ide/ide_hover.dart';
import 'package:baocode/l10n/l10n.dart';
import 'package:baocode/theme/app_theme.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
Expand Down Expand Up @@ -251,8 +253,50 @@ void main() {
controller.undo();
await tester.pump();
expect(controller.text, before);

controller.redo();
await tester.pump();
expect(controller.text, 'Please fix the bug in ${file.atom}.');
});

testWidgets('Undo and Redo keys take the polish back and put it in '
'again', (tester) async {
composerPolishAsker = (system, asked, {model, exact = false, location}) =>
Future.value('Please fix the bug.');
final controller = await pumpComposer(tester);
await tester.tap(find.byType(MarkdownEditor));
await tester.pump();
controller.replace(0, 0, 'fix teh bug');
await tester.pump();
final before = controller.text;

await tester.tap(polishButton());
await tester.pumpAndSettle();
expect(controller.text, 'Please fix the bug.');

final mac = defaultTargetPlatform == TargetPlatform.macOS;
Future<void> press(LogicalKeyboardKey key, {bool shift = false}) async {
final mod = mac ? LogicalKeyboardKey.meta : LogicalKeyboardKey.control;
await tester.sendKeyDownEvent(mod);
if (shift) await tester.sendKeyDownEvent(LogicalKeyboardKey.shift);
await tester.sendKeyEvent(key);
if (shift) await tester.sendKeyUpEvent(LogicalKeyboardKey.shift);
await tester.sendKeyUpEvent(mod);
await tester.pump();
}

await press(LogicalKeyboardKey.keyZ);
expect(controller.text, before);
await press(LogicalKeyboardKey.keyZ, shift: true);
expect(controller.text, 'Please fix the bug.');
if (mac) return;
// Ctrl+Y as well, as the Edit menu has it.
await press(LogicalKeyboardKey.keyZ);
expect(controller.text, before);
await press(LogicalKeyboardKey.keyY);
expect(controller.text, 'Please fix the bug.');
}, variant: TargetPlatformVariant.desktop());

testWidgets('typed on meanwhile, the reply is not taken', (tester) async {
final reply = Completer<String>();
composerPolishAsker = (system, asked, {model, exact = false, location}) =>
Expand Down