Skip to content

Commit

Permalink
absorb: always update draggingHint
Browse files Browse the repository at this point in the history
Summary:
This is subtle. Consider the steps:
- Dragging from a valid rev (ex. 3) to an invalid rev (ex. 2).
  The "Diff chunk can only be ..." hint shows up as expected.
  Current `selectedRev` still points to the valid one (3).
- Drag back to the valid rev 3.
  The old logic only updates the hint when `rev !== selectedRev`. So it will
  skip updating, and the hint stays. However, the hint show disapper because
  the current hovering rev is valid.

This diff fixes the issue by always updating the hint on drag.

Reviewed By: muirdm

Differential Revision: D67993253

fbshipit-source-id: 9ea768a0199f26cac359ce63a67ff8d8dabb0468
  • Loading branch information
quark-zju authored and facebook-github-bot committed Jan 10, 2025
1 parent 6c434e0 commit 4c783ee
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions addons/isl/src/stackEdit/ui/AbsorbStackEditPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ function SingleAbsorbEdit(props: {edit: AbsorbEdit; inDraggingOverlay?: boolean}
// Visual update.
onDragRef.current?.(x, y, isDragging);
// State update.
let newDraggingHint: string | null = null;
if (isDragging) {
// The 'stack' in the closure might be outdated. Read the latest.
const stack = readAtom(stackEditStack);
Expand All @@ -359,24 +360,20 @@ function SingleAbsorbEdit(props: {edit: AbsorbEdit; inDraggingOverlay?: boolean}
let newStack = stack;
try {
newStack = stack.setAbsorbEditDestination(fileStackIndex, absorbEditId, rev);
writeAtom(draggingHint, null);
// `handleDrag` won't be updated with "refreshed" `stackEdit`.
// So `push` can work like `replaceTopOperation` while dragging.
stackEdit.push(newStack, {name: 'absorbMove', commit});
} catch {
writeAtom(
draggingHint,
t(
'Diff chunk can only be applied to commits that modify the file and has the context lines introduced earlier.',
),
newDraggingHint = t(
'Diff chunk can only be applied to a commit that modifies the file and has matching context lines.',
);
}
}
} else {
// Ensure the hint is cleared when not dragging.
// Otherwise the hint div might have unwanted side effects on interaction.
writeAtom(draggingHint, null);
}
// Ensure the hint is cleared when:
// 1) not dragging. (important because the hint div interferes user interaction even if it's invisible)
// 2) dragging back from an invalid rev to the current (valid) rev.
writeAtom(draggingHint, newDraggingHint);
writeAtom(draggingAbsorbEdit, isDragging ? edit : null);
};

Expand Down

0 comments on commit 4c783ee

Please sign in to comment.