From 3d591282ed0b1e186f845a84674214a3396786ab Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 25 Nov 2026 12:30:25 +0800 Subject: [PATCH] fix(editor): Ctrl+Y redoes off Apple's, as the Edit menu says The markdown editor (the composer's too) had only Ctrl+Shift+Z for redo off macOS; Windows' Ctrl+Y, which the window's Edit menu shows, did nothing there. A polish taken back by the keys is put in again by them. Co-Authored-By: BaoCode --- .../lib/src/editor/md_editor.dart | 12 +++++ test/chat/composer_polish_test.dart | 44 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/packages/bao_markdown/lib/src/editor/md_editor.dart b/packages/bao_markdown/lib/src/editor/md_editor.dart index 7bd0d0282..4c67c89bd 100644 --- a/packages/bao_markdown/lib/src/editor/md_editor.dart +++ b/packages/bao_markdown/lib/src/editor/md_editor.dart @@ -1853,6 +1853,18 @@ class MarkdownEditorState extends State } 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 diff --git a/test/chat/composer_polish_test.dart b/test/chat/composer_polish_test.dart index fe72d2cda..d82e0b8f5 100644 --- a/test/chat/composer_polish_test.dart +++ b/test/chat/composer_polish_test.dart @@ -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() { @@ -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 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(); composerPolishAsker = (system, asked, {model, exact = false, location}) =>