Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions editor/src/messages/tool/tool_messages/pen_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,7 @@ impl Fsm for PenToolFsmState {
};
let state = tool_data
.place_anchor(SnapData::new(document, input, viewport), transform, input.mouse.position, responses)
.unwrap_or(PenToolFsmState::Ready);
.unwrap_or(self);

// Auto-panning
let messages = [
Expand Down Expand Up @@ -2185,9 +2185,35 @@ impl Fsm for PenToolFsmState {
(PenToolFsmState::DraggingHandle(..) | PenToolFsmState::PlacingAnchor, PenToolMessage::Undo) => {
if tool_data.point_index > 0 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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
}

tool_data.point_index -= 1;
tool_data
.place_anchor(SnapData::new(document, input, viewport), transform, input.mouse.position, responses)
.unwrap_or(PenToolFsmState::PlacingAnchor)

if tool_data.point_index > 0 {
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
}
} else {
responses.add(PenToolMessage::Abort);
self
Expand Down
Loading