Skip to content

Comments

fix preview line to be visible on multiple undo#3791

Open
krVatsal wants to merge 1 commit intoGraphiteEditor:masterfrom
krVatsal:make-preview-line-follow-the-anchor
Open

fix preview line to be visible on multiple undo#3791
krVatsal wants to merge 1 commit intoGraphiteEditor:masterfrom
krVatsal:make-preview-line-follow-the-anchor

Conversation

@krVatsal
Copy link
Contributor

Fixes #3790

@gemini-code-assist
Copy link

Summary of Changes

Hello @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

  • Pen Tool State Retention: Modified the Pen tool's anchor placement logic to ensure the Finite State Machine (FSM) retains its current state instead of resetting to Ready when place_anchor returns None.
  • Undo Preview Fix: Implemented a fix for the Pen tool's preview line to remain visible and correctly positioned after multiple undo operations by synchronizing preview state variables (next_point, next_handle_start, handle_end) and triggering a PointerMove message.
Changelog
  • editor/src/messages/tool/tool_messages/pen_tool.rs
    • Changed place_anchor's unwrap_or fallback to self to maintain the current FSM state.
    • Added logic within the Undo message handler to decrement point_index and synchronize next_point, next_handle_start, and handle_end based on the new point_index.
    • Introduced a PointerMove message dispatch after an undo to immediately update the preview line's position to follow the cursor.
Activity
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 2186 to 2210
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

Choose a reason for hiding this comment

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

high

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

Copy link

@dhruvjamwal dhruvjamwal left a comment

Choose a reason for hiding this comment

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

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 {

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pen tool preview line disappearing during repeated undo

2 participants