Copy and paste: the desktop's universal copy key works; Ctrl+C at the terminal login keeps the terminal

Omarchy's Super+C sends Ctrl+C by setting the modifier state with no Ctrl key
event while Super is held. Flutter's web engine only presses a modifier on its
own key event, so the app saw a plain "c": the chat selection was not copied
and the terminal typed the letter. A key modifier sync in front of the
framework's key handler now presses the modifiers the browser event's flags
hold (and outside Apple platforms lets go of a held Meta for Ctrl+C/V/X/A/
Insert), installed by the app's binding.

The terminal copies a selection on Ctrl+C without sending ^C, treats the
injected copy key as copy only, and pastes on Shift+Insert. A refused
clipboard write or read now shows a message instead of failing silently.

Server: before the login completes, Ctrl+C and Ctrl+\ erase the typed
password (Ctrl+U) and Ctrl+Z is dropped, so su is not killed and the terminal
no longer ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-29 17:57:28 +00:00
parent 58041e06b7
commit 3d739c3bfc
31 changed files with 2090 additions and 17 deletions
@@ -0,0 +1,93 @@
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/keyboard/key_event_modifiers.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_link_text.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_transcript_selection.dart';
import '../../../../core/keyboard/browser_keys.dart';
import 'chat_transcript_selection_support.dart';
/// The desktop's universal copy key (Omarchy's Super+C sends Ctrl+C while
/// Super is held) copies the chat's selection like Ctrl+C (Cmd+C on a Mac),
/// whether the browser reports Ctrl alone or Ctrl and Meta for it.
void main() {
late List<String> copied;
setUp(() {
ChatTranscriptSelectionArea.debugEnabled = true;
copied = recordTranscriptClipboard();
});
tearDown(() => ChatTranscriptSelectionArea.debugEnabled = null);
Future<void> selectAnswer(WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: ChatTranscriptSelectionArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ChatLinkText('Question 18'),
ChatMarkdownView(text: 'Answer 19 with `code`.'),
],
),
),
),
),
);
await tester.pumpAndSettle();
final answer = tester.getRect(find.textContaining('Answer 19'));
await dragTranscriptSelection(
tester,
answer.centerLeft + const Offset(1, 0),
answer.centerRight - const Offset(1, 0),
);
}
bool apple() =>
defaultTargetPlatform == TargetPlatform.macOS ||
defaultTargetPlatform == TargetPlatform.iOS;
for (final merged in [false, true]) {
testWidgets(
'Super+C (Ctrl${merged ? ' and Meta' : ''} in the flags) copies the '
'selection',
(tester) async {
final keys = BrowserKeys(tester);
await selectAnswer(tester);
await keys.superChord(LogicalKeyboardKey.keyC, mergedMeta: merged);
// On a Mac, Ctrl+C (with or without Cmd) is not the copy key.
expect(copied, apple() ? isEmpty : ['Answer 19 with code.']);
},
variant: TargetPlatformVariant.desktop(),
);
}
testWidgets(
'the keyboard copy keys copy through the browser key path',
(tester) async {
final keys = BrowserKeys(tester);
await selectAnswer(tester);
if (apple()) {
await keys.chord(
LogicalKeyboardKey.metaLeft,
LogicalKeyboardKey.keyC,
flags: const KeyEventModifiers(meta: true),
);
expect(copied, ['Answer 19 with code.']);
return;
}
await keys.chord(LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.keyC);
await keys.chord(
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.insert,
);
expect(copied, ['Answer 19 with code.', 'Answer 19 with code.']);
// A Ctrl the flags pressed is released with its chord.
expect(HardwareKeyboard.instance.isControlPressed, isFalse);
},
variant: TargetPlatformVariant.desktop(),
);
}