Skip to content

Commit b8def1a

Browse files
committed
Windows: השלמת קודי סריקה להדבקה בלי זיהוי שגוי של V
משלים קוד סריקה חסר של Ctrl/V לפני מסירתו ל־Flutter, בתוך מסלול ה־subclass הקיים לכל view וללא שינוי מצב המקשים. מסיר את זיהוי V הלא ממופה כהדבקה ואת הדבקת הטקסט הידנית. מוסיף בדיקת subclass אמיתי, בקרות V/Alt+V ותרחישי SendInput שבהם כל הרצף נשלח יחד, בלי להחזיק Ctrl עד שהממשק מגיב. התוכן עבר סקירה עצמאית; הרצת Windows ו־Win+V בפועל נדרשות בענף ה־QA לפני העברה ל־PR המוצר.
1 parent 178e66e commit b8def1a

9 files changed

Lines changed: 434 additions & 76 deletions

File tree

‎.github/workflows/flutter_tests.yml‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ jobs:
446446
shell: pwsh
447447
run: native/splash/test/run_splash_timeline_test.ps1
448448

449+
- name: Test native keyboard scan codes
450+
shell: pwsh
451+
timeout-minutes: 3
452+
run: test/windows/run_shift_key_normalizer_test.ps1
453+
449454
# זה הצעד שבגללו ה-job קיים: MSBuild, רישום התוספים הנייטיביים
450455
# וה-build hooks. debug ולא release — הוא מפעיל את אותה שרשרת נייטיבית
451456
# בשבריר מהזמן, ובניית ה-release כבר מכוסה ב-build-and-announce.
@@ -476,7 +481,9 @@ jobs:
476481
uses: actions/upload-artifact@v7.0.2
477482
with:
478483
name: windows-native-report-clipboard
479-
path: build/reporting_qa/native-clipboard.*
484+
path: |
485+
build/reporting_qa/native-clipboard.*
486+
build/reporting_qa/native-keyboard.log
480487
if-no-files-found: warn
481488

482489
# ריבוי תצוגות באפליקציה המלאה. `flutter drive` ולא integration_test: ה-binding

‎integration_test/report_clipboard_windows_test.dart‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,14 @@ void main() {
176176
);
177177
});
178178

179-
for (final shiftInsert in [false, true]) {
180-
final shortcut = shiftInsert ? 'Shift+Insert' : 'Ctrl+V';
179+
for (final mode in ['ctrlV', 'shiftInsert', 'batchedZeroScanCtrlV']) {
180+
final shiftInsert = mode == 'shiftInsert';
181+
final batched = mode == 'batchedZeroScanCtrlV';
182+
final shortcut = batched
183+
? 'Ctrl+V in one zero-scan batch'
184+
: shiftInsert
185+
? 'Shift+Insert'
186+
: 'Ctrl+V';
181187
for (final textFocus in [false, true]) {
182188
// Separate forms keep the text-only asynchronous clipboard read from
183189
// overlapping a subsequent clipboard write for the PNG case.
@@ -290,13 +296,19 @@ void main() {
290296
item.add(Formats.plainText(text));
291297
}
292298
await clipboard.write([item]);
293-
await sendNativePaste(
294-
tester,
295-
shiftInsert: shiftInsert,
296-
applied: () => imagePayload
297-
? (bloc.state as AppReportEditing).images.length == 1
298-
: editor.controller.text == expectedTitle,
299-
);
299+
bool applied() => imagePayload
300+
? (bloc.state as AppReportEditing).images.length == 1
301+
: editor.controller.text == expectedTitle;
302+
List<Map<String, Object?>>? trace;
303+
if (batched) {
304+
trace = await sendNativeBatchedPaste(tester, applied: applied);
305+
} else {
306+
await sendNativePaste(
307+
tester,
308+
shiftInsert: shiftInsert,
309+
applied: applied,
310+
);
311+
}
300312
expect(editor.controller.text, expectedTitle);
301313
expect((bloc.state as AppReportEditing).title, expectedTitle);
302314
final images = (bloc.state as AppReportEditing).images;
@@ -324,6 +336,12 @@ void main() {
324336
'textFieldFocus': textFocus,
325337
'foregroundProcessId': pid,
326338
'nativeNonSynthesizedKeyDownObserved': true,
339+
if (batched) ...{
340+
'sendInputCallsForChord': 1,
341+
'submittedScanCodes': [0, 0, 0, 0],
342+
'heldModifierUntilApplied': false,
343+
'flutterKeyTrace': trace,
344+
},
327345
'titlePreservedExactly': true,
328346
'mixedTextAndImagePreservesTextPrecedence':
329347
textFocus && !imagePayload ? true : null,

‎integration_test/support/report_native_keyboard.dart‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:ffi';
22
import 'dart:io';
33

44
import 'package:ffi/ffi.dart';
5+
import 'package:flutter/foundation.dart';
56
import 'package:flutter/services.dart';
67
import 'package:flutter_test/flutter_test.dart';
78
import 'package:win32/win32.dart' as win;
@@ -145,3 +146,86 @@ Future<void> sendNativePaste(
145146
}
146147
}
147148
}
149+
150+
/// Submits down/down/up/up together, without holding Ctrl until Dart responds.
151+
/// Zero wScan is submitted to Windows; the engine's received scan code may differ.
152+
Future<List<Map<String, Object?>>> sendNativeBatchedPaste(
153+
WidgetTester tester, {
154+
required bool Function() applied,
155+
}) async {
156+
await focusNativeReportWindow(tester);
157+
expect(win.GetAsyncKeyState(win.VK_CONTROL) & 0x8000, 0);
158+
expect(win.GetAsyncKeyState(win.VK_V) & 0x8000, 0);
159+
final trace = <Map<String, Object?>>[];
160+
var observed = false;
161+
bool observe(KeyEvent event) {
162+
if (event.logicalKey == LogicalKeyboardKey.controlLeft ||
163+
event.logicalKey == LogicalKeyboardKey.controlRight ||
164+
event.logicalKey == LogicalKeyboardKey.keyV) {
165+
trace.add({
166+
'type': event.runtimeType.toString(),
167+
'logical': event.logicalKey.keyId,
168+
'physical': event.physicalKey.usbHidUsage,
169+
'synthesized': event.synthesized,
170+
'controlPressed': HardwareKeyboard.instance.isControlPressed,
171+
'win32LeftControlPressedAtCallback':
172+
(win.GetKeyState(win.VK_LCONTROL) & 0x8000) != 0,
173+
});
174+
if (event is KeyDownEvent &&
175+
event.logicalKey == LogicalKeyboardKey.keyV &&
176+
!event.synthesized) {
177+
observed = true;
178+
}
179+
}
180+
return false;
181+
}
182+
183+
bool released() =>
184+
!HardwareKeyboard.instance.isControlPressed &&
185+
!HardwareKeyboard.instance.logicalKeysPressed.contains(
186+
LogicalKeyboardKey.keyV,
187+
) &&
188+
(win.GetAsyncKeyState(win.VK_CONTROL) & 0x8000) == 0 &&
189+
(win.GetAsyncKeyState(win.VK_V) & 0x8000) == 0;
190+
191+
HardwareKeyboard.instance.addHandler(observe);
192+
try {
193+
final submitted = using((arena) {
194+
final inputs = arena<win.INPUT>(4);
195+
final keys = [win.VK_CONTROL, win.VK_V, win.VK_V, win.VK_CONTROL];
196+
for (var index = 0; index < keys.length; index++) {
197+
inputs[index].type = win.INPUT_KEYBOARD;
198+
inputs[index].ki.wVk = keys[index];
199+
inputs[index].ki.wScan = 0;
200+
inputs[index].ki.dwFlags = win.KEYBD_EVENT_FLAGS(
201+
index >= 2 ? win.KEYEVENTF_KEYUP : 0,
202+
);
203+
}
204+
return win.SendInput(4, inputs, sizeOf<win.INPUT>()).value;
205+
});
206+
expect(submitted, 4, reason: 'Windows must accept the complete key batch.');
207+
await pumpNativeUntil(
208+
tester,
209+
() => observed && applied() && released(),
210+
reason:
211+
'The complete native chord must paste once and release all keys; '
212+
'trace: $trace',
213+
);
214+
expect(_windowProcess(win.GetForegroundWindow()), pid);
215+
return List<Map<String, Object?>>.unmodifiable(trace);
216+
} finally {
217+
debugPrint('Batched native Ctrl+V trace: $trace');
218+
try {
219+
if (!released()) {
220+
expect(_sendKeys([win.VK_V, win.VK_CONTROL], release: true), 2);
221+
await pumpNativeUntil(
222+
tester,
223+
released,
224+
reason: 'Batched paste must not leave Ctrl or V pressed.',
225+
);
226+
}
227+
} finally {
228+
HardwareKeyboard.instance.removeHandler(observe);
229+
}
230+
}
231+
}

‎lib/app_report/view/widgets/app_report_images_section.dart‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,9 @@ class _AppReportImagesSectionState extends State<AppReportImagesSection>
6060
/// כדי שהדבקת טקסט לשדה תמשיך לעבוד.
6161
bool _onKey(KeyEvent event) {
6262
if (event is! KeyDownEvent || !widget.enabled) return false;
63-
final historyPaste =
64-
!kIsWeb &&
65-
defaultTargetPlatform == TargetPlatform.windows &&
66-
event.logicalKey == LogicalKeyboardKey.keyV &&
67-
event.physicalKey.usbHidUsage == 0x1600000000 &&
68-
!event.synthesized;
69-
if (!_isPasteShortcut(event) && !historyPaste) return false;
63+
if (!_isPasteShortcut(event)) return false;
7064
if (!(ModalRoute.of(context)?.isCurrent ?? false)) return false;
7165
if (!AppWindowKeys.isActiveWindow(context)) return false;
72-
// Win+V משחרר Ctrl לפני V בעל קוד פיזי לא ממופה (flutter/flutter#143997).
73-
// רק במסלול הזה משלימים הדבקת טקסט; Ctrl+V רגיל נשאר בידי EditableText.
74-
if (historyPaste && !HardwareKeyboard.instance.isControlPressed) {
75-
final editor = _focusedEditor;
76-
if (editor != null) {
77-
unawaited(editor.pasteText(SelectionChangedCause.keyboard));
78-
}
79-
}
8066
unawaited(_paste());
8167
return false;
8268
}

0 commit comments

Comments
 (0)