svgdotjs / svg.select.js

An extension of svg.js which allows to select an element

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove brakes the select process

froid24 opened this issue · comments

Hello guys,

Here's my problem:
I have a tool using svg.js (2.7.1) with panzoom (1.2.3), draggable (2.2.1), select (2.1.2), resize (1.4.3), draw (2.0.4).

When I add a shape, it is made draggable. When I click a shape, it is selected and made resizable.

When I select a shape and then REMOVE it (myEl.remove();), all is well, but afterwards no other shapes can be selected. The following error is given when trying to select another shape:

Uncaught TypeError: Cannot read property 'group' of null
at t.init (svg.select.min.js:1)
at e.selectize (svg.select.min.js:1)
at deselectShape (index.php:111)
at selectShape (index.php:99)
at e. (index.php:73)

Can anyone please help?
Thanks.

Deselect the shape before removing? :D

I thought of that, but that's not it...

selectedShape.resize('stop');
selectedShape.selectize(false, {deepSelect:true});
selectedShape.remove();

Still getting the same error message next time I try to select one of the remaining shapes.
It definitely has something to do with the select operation, because if I draw the shapes and then just remove one without selecting any shape first, it works (I can further select other shapes). But once I select a shape and remove THAT specific shape, it breaks (if I remove a shape that was not selectized yet and remove it, it continues to work ok).

Any ideas or a quickfix? Thanks!

I am pretty sure this plugin isnt the error here. Please debug the code on your end (dont use minified code!). I could be wrong ofc but with what I have on information it should work as it is.

From looking at the stacktrace it looks like your old shape is again selected and deselected even though its already removed?

Arrrrghhh... you are right...
That last remark helped me find the error in my code (wrong way to empty a shape pointer).

Many thanks for the help, @Fuzzyma !

Sometimes I think I am a wizard :D