KristofferStrube / Blazor.SVGEditor

A basic SVG editor written in Blazor.
https://kristofferstrube.github.io/Blazor.SVGEditor/
MIT License
306 stars 51 forks source link

Bugfix : Deleting multiple selection with Delete button does not work and create console error #3

Closed pcarret closed 2 years ago

pcarret commented 2 years ago

Bugfix : in ShapeEditor::KeyUp

                if (eventArgs.Key == "Delete")
                {
                    SVGElement.SVG.Remove(SVGElement.SVG.SelectedElements);
                    SVGElement.SVG.SelectedElements.Clear();
                }

In SVG.razor.cs I commented SelectedElements.Clear(); So this will not work with contextual menu ( I do not use them anymore in my fork).

 public void Remove(ISVGElement SVGElement)
        {
            ElementsAsHtml.RemoveAt(Elements.IndexOf(SVGElement));
            Elements.Remove(SVGElement);
            //SelectedElements.Clear();
            UpdateInput();
            RerenderAll();
        }

        public void Remove(List<ISVGElement> elements)
        {
            foreach (var element in elements)
            {
                this.Remove(element);
            }
        }

Factorization canbe improved to avoid unnecessary code like

            UpdateInput();
            RerenderAll();
KristofferStrube commented 2 years ago

This would be a nice addition. Currently, none of the keyboard shortcuts incorporate the new multi-select feature so I see that it would be nice to generally add that.

I will have to look into whether or not

UpdateInput();
RerenderAll();

is unnecessary in this case.

KristofferStrube commented 2 years ago

I added the function to delete a multi-select. I also added some checks to my JS calls so that I don't try to get bounding boxes of elements that does not excist due to rerender.