Skip to content

Commit e7a2800

Browse files
authored
Fix Shape tool type dropdown not persisting selection and not excluding Line/Rectangle/Ellipse (#3731)
* fix Shape tool dropdown resetting to Polygon when switching tools * add sync for rectangle/ellipse and line * fix build issues
1 parent 9f9dd71 commit e7a2800

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

editor/src/messages/tool/tool_message_handler.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::common_functionality::shape_editor::ShapeState;
2-
use super::common_functionality::shapes::shape_utility::ShapeType::{self, Ellipse, Line, Rectangle};
2+
use super::common_functionality::shapes::shape_utility::ShapeType::{Ellipse, Line, Rectangle};
33
use super::utility_types::{ToolActionMessageContext, ToolFsmState, tool_message_to_tool_type};
44
use crate::application::generate_uuid;
55
use crate::messages::layout::utility_types::widget_prelude::*;
@@ -77,7 +77,8 @@ impl MessageHandler<ToolMessage, ToolMessageContext<'_>> for ToolMessageHandler
7777
self.tool_state.tool_data.active_tool_type = ToolType::Shape;
7878
}
7979
responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Shape });
80-
responses.add(ShapeToolMessage::SetShape { shape: ShapeType::Polygon });
80+
// Sync current_shape with the dropdown selection (options.shape_type)
81+
responses.add(ShapeToolMessage::SyncShapeWithOptions);
8182
responses.add(ShapeToolMessage::HideShapeTypeWidget { hide: false })
8283
}
8384
ToolMessage::ActivateToolBrush => responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Brush }),

editor/src/messages/tool/tool_messages/shape_tool.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub enum ShapeToolMessage {
105105
PointerOutsideViewport { modifier: ShapeToolModifierKey },
106106
UpdateOptions { options: ShapeOptionsUpdate },
107107
SetShape { shape: ShapeType },
108+
SyncShapeWithOptions,
108109

109110
IncreaseSides,
110111
DecreaseSides,
@@ -180,30 +181,12 @@ fn create_shape_option_widget(shape_type: ShapeType) -> WidgetInstance {
180181
}
181182
.into()
182183
}),
183-
MenuListEntry::new("Rectangle").label("Rectangle").on_commit(move |_| {
184-
ShapeToolMessage::UpdateOptions {
185-
options: ShapeOptionsUpdate::ShapeType(ShapeType::Rectangle),
186-
}
187-
.into()
188-
}),
189-
MenuListEntry::new("Ellipse").label("Ellipse").on_commit(move |_| {
190-
ShapeToolMessage::UpdateOptions {
191-
options: ShapeOptionsUpdate::ShapeType(ShapeType::Ellipse),
192-
}
193-
.into()
194-
}),
195184
MenuListEntry::new("Arrow").label("Arrow").on_commit(move |_| {
196185
ShapeToolMessage::UpdateOptions {
197186
options: ShapeOptionsUpdate::ShapeType(ShapeType::Arrow),
198187
}
199188
.into()
200189
}),
201-
MenuListEntry::new("Line").label("Line").on_commit(move |_| {
202-
ShapeToolMessage::UpdateOptions {
203-
options: ShapeOptionsUpdate::ShapeType(ShapeType::Line),
204-
}
205-
.into()
206-
}),
207190
]];
208191
DropdownInput::new(entries).selected_index(Some(shape_type as u32)).widget_instance()
209192
}
@@ -1183,15 +1166,16 @@ impl Fsm for ShapeToolFsmState {
11831166
responses.add(DocumentMessage::AbortTransaction);
11841167
tool_data.data.cleanup(responses);
11851168
tool_data.current_shape = shape;
1186-
responses.add(ShapeToolMessage::UpdateOptions {
1187-
options: ShapeOptionsUpdate::ShapeType(shape),
1188-
});
1189-
1190-
responses.add(ShapeToolMessage::UpdateOptions {
1191-
options: ShapeOptionsUpdate::ShapeType(shape),
1192-
});
1169+
// Update hints for the new shape (without updating options.shape_type)
1170+
update_dynamic_hints(&ShapeToolFsmState::Ready(shape), responses, tool_data);
11931171
ShapeToolFsmState::Ready(shape)
11941172
}
1173+
(_, ShapeToolMessage::SyncShapeWithOptions) => {
1174+
// Sync current_shape with the dropdown selection when returning from alias tools
1175+
tool_data.current_shape = tool_options.shape_type;
1176+
update_dynamic_hints(&ShapeToolFsmState::Ready(tool_options.shape_type), responses, tool_data);
1177+
ShapeToolFsmState::Ready(tool_options.shape_type)
1178+
}
11951179
(_, ShapeToolMessage::HideShapeTypeWidget { hide }) => {
11961180
tool_data.hide_shape_option_widget = hide;
11971181
responses.add(ToolMessage::RefreshToolOptions);

0 commit comments

Comments
 (0)