Skip to content

Commit 3db9962

Browse files
yom-chadashotzaria-bot[bot]
authored andcommitted
גרירת כרטיסיות: גידור מקור שנסגר ויעד שהוחלף בזמן המתנה
1 parent cef12e9 commit 3db9962

1 file changed

Lines changed: 58 additions & 28 deletions

File tree

‎lib/core/windowing/cross_window_tab_drag.dart‎

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class CrossWindowTabDrag {
5858
/// מזהה עולה לכל גרירה, לגידור תשובות אסינכרוניות של גרירה שהסתיימה.
5959
int _dragGeneration = 0;
6060

61-
/// כותרת הכרטיסיה הנגררת כרגע, לשליחה לחלון היעד.
61+
/// כותרת הכרטיסיה הנגררת, עד עצירת התצוגה הנייטיבית.
6262
String? _draggedTitle;
6363

6464
/// הכרטיסיה הנגררת ובלוק הכרטיסיות של חלון המקור, למסירה מ-[_poll].
@@ -237,14 +237,12 @@ class CrossWindowTabDrag {
237237
/// ⚠️ חובה בסגירת החלון. הטיימר שואל את ה-runner כל 60ms, ולולאה שנשארה
238238
/// אחרי שהחלון נסגר ממשיכה לעדכן חיווי של גרירה שאיננה.
239239
void dispose() {
240+
_dragGeneration++;
240241
_timer?.cancel();
241242
_timer = null;
242-
// ⚠️ בלי זה הרוח הנייטיבית נשארת חיה ומצוירת אחרי שהרצועה ירדה מהעץ.
243-
// המסירה למערכת מנקה בעצמה, ולכן רק גרירה שלא נמסרה מטופלת כאן.
244-
if (_draggedTitle != null && !_handedOff) _hidePreview();
243+
if (_draggedTitle != null) _hideSystemPreview();
245244
// ⚠️ המחלקה חיה יותר מגרירה בודדת (היא שדה של הרצועה). החזקה של
246245
// כרטיסיה שאולי כבר `dispose`-ה היא הפניה תלויה.
247-
_draggedTitle = null;
248246
_draggedTab = null;
249247
_sourceBloc = null;
250248
_cancelFlutterDrag = null;
@@ -372,7 +370,7 @@ class CrossWindowTabDrag {
372370
_handedOff = true;
373371
_timer?.cancel();
374372
_timer = null;
375-
_hidePreview();
373+
_hideSystemPreview();
376374
return;
377375
}
378376

@@ -383,16 +381,15 @@ class CrossWindowTabDrag {
383381
final last = _lastDragOverSlot;
384382
if (last != null) _notifyDragLeave(last);
385383
_lastDragOverSlot = null;
386-
_draggedTitle = null;
387384

388385
_cancelFlutterDrag?.call();
389386
final outcome = await _dragOutToSystem();
390387
if (generation != _dragGeneration) return;
391388

392-
if (outcome == null) return _hidePreview();
389+
if (outcome == null || bloc.isClosed) return _hideSystemPreview();
393390
final peerSlot = outcome.snapped ? null : outcome.slot;
394391
// שחרור לפני תחילת הלולאה יכול להעביר רק לחלון היעד שכבר קיים.
395-
if (!outcome.ran && peerSlot == null) return _hidePreview();
392+
if (!outcome.ran && peerSlot == null) return _hideSystemPreview();
396393
debugPrint(
397394
'גרירה הסתיימה: snapped=${outcome.snapped} '
398395
'rect=${outcome.left},${outcome.top} '
@@ -406,7 +403,7 @@ class CrossWindowTabDrag {
406403
if (!outcome.snapped) {
407404
// שחרור חזרה מעל חלון המקור — ביטול. אחרת כל גרירה שיצאה וחזרה
408405
// הייתה פותחת חלון.
409-
if (outcome.isSelf) return _hidePreview();
406+
if (outcome.isSelf) return _hideSystemPreview();
410407

411408
// ⚠️ שורת המשימות אינה מחווה של "פתח חלון כאן". היא נגישה גם בחלון
412409
// ממוקסם, ולכן שחרור עליה הוא כמעט תמיד החטאה.
@@ -416,22 +413,29 @@ class CrossWindowTabDrag {
416413
outcome.atTaskbarEdge ||
417414
_outsideWorkArea(outcome.slot, outcome.inWorkArea)) {
418415
debugPrint('גרירה שוחררה מעל שורת המשימות — מבוטלת');
419-
return _hidePreview();
416+
return _hideSystemPreview();
420417
}
421418
}
422419

423420
// בשחרור מוקדם טיימר המעקב הנייטיבי פעיל עד הסתרת התצוגה.
424-
if (!outcome.ran) _hidePreview();
421+
if (!outcome.ran) _hideSystemPreview();
425422
final confirmed = await confirmTransfer(tab);
426423
if (generation != _dragGeneration) return;
427-
if (!confirmed) {
428-
if (outcome.ran) _hidePreview();
424+
if (!confirmed || bloc.isClosed) {
425+
if (outcome.ran) _hideSystemPreview();
429426
return;
430427
}
431428

432429
if (peerSlot != null) {
433-
if (outcome.ran) _hidePreview();
434-
await _transferToPeer(peerSlot, tab, bloc, outcome.x, outcome.y);
430+
if (outcome.ran) _hideSystemPreview();
431+
await _transferToPeer(
432+
peerSlot,
433+
tab,
434+
bloc,
435+
outcome.x,
436+
outcome.y,
437+
hwnd: outcome.hwnd,
438+
);
435439
return;
436440
}
437441

@@ -449,16 +453,20 @@ class CrossWindowTabDrag {
449453
)
450454
: null,
451455
);
456+
if (generation == _dragGeneration) _hideSystemPreview();
452457
if (moved) {
453-
_hideAfterViewOpened();
454-
bloc.add(RemoveTab(tab));
458+
if (!bloc.isClosed) bloc.add(RemoveTab(tab));
455459
return;
456460
}
457461

458-
_hidePreview();
459462
await WindowOpener.current.reportOpenWindowFailure();
460463
}
461464

465+
void _hideSystemPreview() {
466+
_draggedTitle = null;
467+
_hidePreview();
468+
}
469+
462470
/// מעביר את הכרטיסיה לחלון [slot], למקום המדויק שתחת הסמן.
463471
///
464472
/// ⚠️ מיקום ההכנסה נשאל **כאן**, ברגע השחרור, ולא בפעימות הגרירה: מהרגע
@@ -470,19 +478,34 @@ class CrossWindowTabDrag {
470478
OpenedTab tab,
471479
TabsBloc bloc,
472480
int x,
473-
int y,
474-
) async {
475-
final index =
476-
_remoteDropIndex ??
477-
await _inProcess.notifyDragOver(slot, x, y, tab.title);
481+
int y, {
482+
required int? hwnd,
483+
}) async {
484+
final generation = _dragGeneration;
485+
// משבצת של חלון Dart מתפנה בסגירה ויכולה כבר לשמש חלון אחר.
486+
bool samePeer() =>
487+
hwnd == null ||
488+
slot == InProcessTabDrops.mainSlot ||
489+
_inProcess.resolve(hwnd: hwnd) == slot;
490+
491+
final index = samePeer()
492+
? _remoteDropIndex ??
493+
await _inProcess.notifyDragOver(slot, x, y, tab.title)
494+
: null;
478495
_remoteDropIndex = null;
479-
final moved = await _inProcess.sendTabToWindow(slot, tab, index: index);
496+
if (generation != _dragGeneration || bloc.isClosed) {
497+
if (samePeer()) _notifyDragLeave(slot);
498+
return;
499+
}
500+
final moved = samePeer()
501+
? await _inProcess.sendTabToWindow(slot, tab, index: index)
502+
: false;
480503
if (moved == true) {
481-
bloc.add(RemoveTab(tab));
504+
if (!bloc.isClosed) bloc.add(RemoveTab(tab));
482505
return;
483506
}
484507
// החיווי ביעד הודלק על ידי `notifyDragOver` — יש לכבות אותו.
485-
_notifyDragLeave(slot);
508+
if (samePeer()) _notifyDragLeave(slot);
486509
UiSnack.showError(
487510
moved == false
488511
? WindowMessages.transferFailed
@@ -536,7 +559,14 @@ class CrossWindowTabDrag {
536559
// הכרטיסיה נכנסת לחלון קיים — אין מה להחליף את הרוח, והיא מוסתרת
537560
// מיד כדי שלא תרחף מעל היעד.
538561
_hidePreview();
539-
await _transferToPeer(target.slot!, tab, tabsBloc, target.x, target.y);
562+
await _transferToPeer(
563+
target.slot!,
564+
tab,
565+
tabsBloc,
566+
target.x,
567+
target.y,
568+
hwnd: target.hwnd,
569+
);
540570
return;
541571
}
542572

0 commit comments

Comments
 (0)