fix preview line to be visible on multiple undo#3791
fix preview line to be visible on multiple undo#3791krVatsal wants to merge 1 commit intoGraphiteEditor:masterfrom
Conversation
Summary of ChangesHello @krVatsal, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a bug in the Pen tool where the preview line would become invisible or incorrectly positioned after performing multiple undo actions. The changes ensure that the tool's internal state correctly reflects the current drawing context after an undo, specifically by retaining the FSM state during anchor placement and explicitly updating the bezier curve preview's origin and handles. This provides a more consistent and predictable user experience when using the Pen tool with undo functionality. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request improves the Pen tool's preview visibility during undo operations by ensuring the internal state is correctly synchronized. However, the updated undo logic introduces a regression where the tool no longer aborts when undoing the first anchor point. This should be corrected to maintain consistent behavior when canceling a path creation.
| if tool_data.point_index > 0 { | ||
| tool_data.point_index -= 1; | ||
| tool_data | ||
| .place_anchor(SnapData::new(document, input, viewport), transform, input.mouse.position, responses) | ||
| .unwrap_or(PenToolFsmState::PlacingAnchor) | ||
| } | ||
|
|
||
| // Sync preview state so the bezier curve preview originates from the current anchor. | ||
| // Setting handle_end to Some ensures the bezier preview renders and place_anchor | ||
| // keeps handle_end/next_handle_start in sync with the mouse on subsequent moves. | ||
| if let Some(current) = tool_data.latest_points.get(tool_data.point_index) { | ||
| tool_data.next_point = current.pos; | ||
| tool_data.next_handle_start = current.pos; | ||
| tool_data.handle_end = Some(current.pos); | ||
|
|
||
| // Trigger a PointerMove so the preview immediately follows the cursor | ||
| // instead of sitting at the anchor until the user moves the mouse. | ||
| responses.add(PenToolMessage::PointerMove { | ||
| snap_angle: Key::Shift, | ||
| break_handle: Key::Alt, | ||
| lock_angle: Key::Control, | ||
| colinear: Key::KeyC, | ||
| move_anchor_with_handles: Key::Space, | ||
| }); | ||
| PenToolFsmState::PlacingAnchor | ||
| } else { | ||
| responses.add(PenToolMessage::Abort); | ||
| self |
There was a problem hiding this comment.
The updated undo logic introduces a regression where the tool fails to abort when undoing the first anchor point.
In the previous implementation, if point_index was 0, the tool would send a PenToolMessage::Abort and return. In the new code, if point_index is 0, it is not decremented, but the code still proceeds to fetch the point at index 0 and return PenToolFsmState::PlacingAnchor. This prevents the user from canceling the tool interaction by undoing the initial point.
if tool_data.point_index > 0 {
tool_data.point_index -= 1;
// Sync preview state so the bezier curve preview originates from the current anchor.
// Setting handle_end to Some ensures the bezier preview renders and place_anchor
// keeps handle_end/next_handle_start in sync with the mouse on subsequent moves.
if let Some(current) = tool_data.latest_points.get(tool_data.point_index) {
tool_data.next_point = current.pos;
tool_data.next_handle_start = current.pos;
tool_data.handle_end = Some(current.pos);
// Trigger a PointerMove so the preview immediately follows the cursor
// instead of sitting at the anchor until the user moves the mouse.
responses.add(PenToolMessage::PointerMove {
snap_angle: Key::Shift,
break_handle: Key::Alt,
lock_angle: Key::Control,
colinear: Key::KeyC,
move_anchor_with_handles: Key::Space,
});
PenToolFsmState::PlacingAnchor
} else {
responses.add(PenToolMessage::Abort);
self
}
} else {
responses.add(PenToolMessage::Abort);
self
dhruvjamwal
left a comment
There was a problem hiding this comment.
I just reviewed the regression on PR #3791 regarding the Pen tool undo logic. Please update for further changes.
| @@ -2185,9 +2185,26 @@ impl Fsm for PenToolFsmState { | |||
| (PenToolFsmState::DraggingHandle(..) | PenToolFsmState::PlacingAnchor, PenToolMessage::Undo) => { | |||
| if tool_data.point_index > 0 { | |||
There was a problem hiding this comment.
"This fixes the regression caught by the bot by ensuring the tool aborts if the index is 0."
````suggestion`
if tool_data.point_index > 0 {
tool_data.point_index -= 1;
if tool_data.point_index > 0 {
tool_data
.place_anchor(SnapData::new(document, input, viewport), transform, input.mouse.position, responses)
.unwrap_or(PenToolFsmState::PlacingAnchor);
}
if let Some(current) = tool_data.latest_points.get(tool_data.point_index) {
tool_data.next_point = current.pos;
tool_data.next_handle_start = current.pos;
tool_data.handle_end = Some(current.pos);
responses.add(PenToolMessage::PointerMove {
snap_angle: Key::Shift,
break_handle: Key::Alt,
lock_angle: Key::Control,
colinear: Key::KeyC,
move_anchor_with_handles: Key::Space,
});
PenToolFsmState::PlacingAnchor
} else {
responses.add(PenToolMessage::Abort);
self
}
} else {
responses.add(PenToolMessage::Abort);
self
}
Fixes #3790