Skip to content

Commit aee1a5d

Browse files
committed
Fix inability to draw a new contour when a non-endpoint selected
Closes #337 (GitHub).
1 parent c6c24d2 commit aee1a5d

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/editor/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@ impl Editor {
183183
self.modifying
184184
}
185185

186+
/// Use when you thought you were going to make a bona fide modification but an edge case
187+
/// prevents you from making any valid modification.
188+
pub fn cancel_modification(&mut self) {
189+
if !self.modifying {
190+
panic!("Canceled a modification that was not in progress!")
191+
}
192+
193+
self.modifying = false;
194+
self.undo();
195+
self.history.redo_stack.pop(); // Removes the "Undo" item added by above call.
196+
}
197+
186198
/// This function merges contour gracefully. This should be used over merging them yourself as it will automatically
187199
/// deal with contour operations. This can only be called during a modification
188200
pub fn merge_contours(&mut self, start_idx: usize, end_idx: usize) {

src/tools/pen.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ impl Pen {
113113
}
114114
}
115115
// If we've got the end of a contour selected we'll continue drawing that contour.
116-
else if let Some(contour_idx) = v.contour_idx {
116+
else if let (Some(contour_idx), Some(point_idx)) = (v.contour_idx, v.point_idx) {
117117
let mouse_pos = mouse_info.position;
118118
let contour_len = get_contour_len!(v.get_active_layer_ref(), contour_idx);
119119

120-
if v.point_idx.unwrap() == contour_len - 1 {
120+
if point_idx == contour_len - 1 {
121121
v.point_idx = {
122122
let layer = v.get_active_layer_mut();
123123
get_contour!(layer, contour_idx).push(Point::from_x_y_type(
@@ -129,7 +129,7 @@ impl Pen {
129129
layer.outline[contour_idx].operation.insert_op(&contour, contour_len);
130130
Some(get_contour_len!(layer, contour_idx) - 1)
131131
};
132-
} else if v.point_idx.unwrap() == 0 {
132+
} else if point_idx == 0 {
133133
{
134134
let layer = v.get_active_layer_mut();
135135
let point_type = get_point!(layer, contour_idx, 0).ptype;
@@ -146,6 +146,12 @@ impl Pen {
146146
layer.outline[contour_idx].operation.insert_op(&contour, 0);
147147
};
148148
v.end_modification();
149+
} else { // force a deselect and redo the event. Cf. GitHub issue №337.
150+
v.cancel_modification();
151+
v.contour_idx = None;
152+
v.point_idx = None;
153+
v.selected.clear();
154+
return self.mouse_pressed(v, i, mouse_info);
149155
}
150156
} else {
151157
// Lastly if we get here we create a new contour.
@@ -169,7 +175,7 @@ impl Pen {
169175
}
170176

171177
// No matter how you move the point we want you to be able to manipulate it so we push the MoveHandle
172-
// vehavior onto the editor's behavior stack.
178+
// behavior onto the editor's behavior stack.
173179
v.push_behavior(Box::new(MoveHandle::new(WhichHandle::A, mouse_info, true)));
174180
}
175181

0 commit comments

Comments
 (0)