0

First steps with PaperJS. I realized this sketch and this video to describe the issue. As you can see in the video, drawing, for example, three items, and moving over them to select one and pressing the "d" key on keybord, it is possible to remove just the last added and selected item, but not the previous ones. If you start from the first or second item of the three added, the alert is not even triggered.

The wanted beaviour would be instead to select the event.item.selected (moving on it with the mouse) and remove just the selected one by clicking the "d" key on keyboard.

Thank you for your help

Riccardo Volpe
  • 1,471
  • 1
  • 16
  • 30

1 Answers1

0

Your issue is that after removing the first path, your path variable no longer points to nothing. So the next time you hit the delete key, you no longer know the selected path. What you should do instead is storing the currently selected path into another variable and use it instead.

Here's a corrected sketch based on your code, demonstrating this.

sasensi
  • 4,610
  • 10
  • 35
  • Hello @sasensi, sorry to be late in my reply. Your code is great and solved the issue, but I checked it the first time from my mobile smartphone, noting the impossibility to select it by using `onMouseMove` and the difficulty of clicking the `D` key on a smartphone to delete the path... And so my delay in the reply. Anyway, another issue, another question. I will share here the link of the new one, if you want to check it out, thank you! – Riccardo Volpe Nov 03 '21 at 18:37
  • Hello @sasensi, here the link for the new question, if you desire to have a look to it: https://stackoverflow.com/q/69831030/2149425 Thank you – Riccardo Volpe Nov 03 '21 at 19:59