@@ -203,6 +203,21 @@ export default {
203203 }
204204 return this .compoundPath ;
205205 },
206+ createUndoAction (actionName ) {
207+ if (this .compoundPath == null ) this .createCompoundPath ();
208+
209+ let copy = this .compoundPath .clone ();
210+ copy .visible = false ;
211+ this .pervious .push (copy);
212+
213+ let action = new UndoAction ({
214+ name: " Annotaiton " + this .annotation .id ,
215+ action: actionName,
216+ func: this .undoCompound ,
217+ args: {}
218+ });
219+ this .addUndo (action);
220+ },
206221 simplifyPath () {
207222 let flatten = 1 ;
208223 let simplify = this .simplify ;
@@ -235,43 +250,39 @@ export default {
235250 this .compoundPath .remove ();
236251 this .compoundPath = this .pervious .pop ();
237252 },
238- unite (compound ) {
253+ /**
254+ * Unites current annotation path with anyother path.
255+ * @param {paper.CompoundPath} compound compound to unite current annotation path with
256+ * @param {boolean} simplify simplify compound after unite
257+ * @param {undoable} undoable add an undo action
258+ */
259+ unite (compound , simplify = true , undoable = true ) {
239260 if (this .compoundPath == null ) this .createCompoundPath ();
240261
241262 let newCompound = this .compoundPath .unite (compound);
263+ if (undoable) this .createUndoAction (" Unite" );
242264
243- this .compoundPath .visible = false ;
244- this .pervious .push (this .compoundPath );
245-
246- let action = new UndoAction ({
247- name: " Annotaiton " + this .annotation .id ,
248- action: " United" ,
249- func: this .undoCompound ,
250- args: {}
251- });
252- this .addUndo (action);
253-
265+ this .compoundPath .remove ();
254266 this .compoundPath = newCompound;
255- this .simplifyPath ();
267+
268+ if (simplify) this .simplifyPath ();
256269 },
257- subtract (compound ) {
270+ /**
271+ * Subtract current annotation path with anyother path.
272+ * @param {paper.CompoundPath} compound compound to subtract current annotation path with
273+ * @param {boolean} simplify simplify compound after subtraction
274+ * @param {undoable} undoable add an undo action
275+ */
276+ subtract (compound , simplify = true , undoable = true ) {
258277 if (this .compoundPath == null ) this .createCompoundPath ();
259278
260279 let newCompound = this .compoundPath .subtract (compound);
280+ if (undoable) this .createUndoAction (" Subtract" );
261281
262- this .compoundPath .visible = false ;
263- this .pervious .push (this .compoundPath );
264-
265- let action = new UndoAction ({
266- name: " Annotaiton " + this .annotation .id ,
267- action: " Subtract" ,
268- func: this .undoCompound ,
269- args: {}
270- });
271- this .addUndo (action);
272-
282+ this .compoundPath .remove ();
273283 this .compoundPath = newCompound;
274- this .simplifyPath ();
284+
285+ if (simplify) this .simplifyPath ();
275286 },
276287 setColor () {
277288 if (this .compoundPath == null ) return ;
0 commit comments