Skip to content

Commit 27d5ec8

Browse files
committed
Merge pull request scratchfoundation#166 from nathan/duplicate-comment-offset
Fixed duplicated comments being offset from cursor
2 parents d8f4724 + 6b6c202 commit 27d5ec8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/scratch/ScratchComment.as

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,17 @@ public class ScratchComment extends Sprite {
178178

179179
public function menu(evt:MouseEvent):Menu {
180180
var m:Menu = new Menu();
181-
m.addItem('duplicate', duplicateComment);
181+
var startX:Number = stage.mouseX;
182+
var startY:Number = stage.mouseY;
183+
m.addItem('duplicate', function():void {
184+
duplicateComment(stage.mouseX - startX, stage.mouseY - startY);
185+
});
182186
m.addItem('delete', deleteComment);
183187
return m;
184188
}
185189

186190
public function handleTool(tool:String, evt:MouseEvent):void {
187-
if (tool == 'copy') duplicateComment();
191+
if (tool == 'copy') duplicateComment(10, 5);
188192
if (tool == 'cut') deleteComment();
189193
}
190194

@@ -194,11 +198,11 @@ public class ScratchComment extends Sprite {
194198
Scratch.app.scriptsPane.saveScripts();
195199
}
196200

197-
public function duplicateComment():void {
201+
public function duplicateComment(deltaX:Number, deltaY:Number):void {
198202
if (!parent) return;
199203
var dup:ScratchComment = new ScratchComment(contents.text, isOpen);
200-
dup.x = x + 10;
201-
dup.y = y + 10;
204+
dup.x = x + deltaX;
205+
dup.y = y + deltaY;
202206
parent.addChild(dup);
203207
Scratch.app.gh.grabOnMouseUp(dup);
204208
}

0 commit comments

Comments
 (0)