File size: 1,542 Bytes
bfecf3d
 
 
 
 
 
 
 
 
 
 
 
 
 
4d19902
 
 
 
 
 
 
 
 
bfecf3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function submitUndoSplit(undoBtn) {
    if (!undoBtn || undoBtn.disabled) return;

    var segIdx = parseInt(undoBtn.dataset.segment, 10);
    if (isNaN(segIdx)) return;

    if (typeof activeManualSplitCard !== 'undefined' && activeManualSplitCard) {
        exitManualSplit(activeManualSplitCard);
    }

    undoBtn.disabled = true;
    undoBtn.dataset.originalLabel = undoBtn.textContent || 'Undo split';
    undoBtn.textContent = 'Undoing...';

    // Re-anchor on the merged segment after the undo re-render (keep it
    // stationary). The merged segment keeps the group's first child's start-time,
    // so anchor on that first card (the undo button lives in the group header,
    // not inside a card). Falls back to the top-most card if not found.
    if (window.qaSaveScrollAnchor) {
        var grp = undoBtn.closest('.split-group');
        window.qaSaveScrollAnchor(grp ? grp.querySelector('.segment-card') : null);
    }

    var payloadStr = JSON.stringify({idx: segIdx});
    setGradioValue('undo-split-payload', payloadStr);
    setTimeout(function() {
        var btn = document.getElementById('undo-split-trigger');
        if (btn) btn.click();
    }, 50);

    setTimeout(function() {
        if (!undoBtn.isConnected) return;
        undoBtn.disabled = false;
        undoBtn.textContent = undoBtn.dataset.originalLabel || 'Undo split';
    }, 8000);
}

document.addEventListener('click', function(e) {
    var undoBtn = e.target.closest('.undo-split-btn');
    if (!undoBtn) return;
    submitUndoSplit(undoBtn);
});