diff --git a/src/ui/tools/booleans-tool.cpp b/src/ui/tools/booleans-tool.cpp index cbf543dba9ab221089003699d9b3099340d4379b..0b2d8b0a4eeb1c716cbbd8cddab6c749eb04974e 100644 --- a/src/ui/tools/booleans-tool.cpp +++ b/src/ui/tools/booleans-tool.cpp @@ -40,6 +40,7 @@ InteractiveBooleansTool::InteractiveBooleansTool(SPDesktop *desktop) to_commit = false; update_status(); if (auto selection = desktop->getSelection()) { + _items_to_manage = selection->items_vector(); // Store the original items before the selection context is lost desktop->setWaitingCursor(); boolean_builder = std::make_unique(selection); desktop->clearWaitingCursor(); @@ -68,16 +69,16 @@ InteractiveBooleansTool::~InteractiveBooleansTool() */ void InteractiveBooleansTool::hide_selected_objects(bool hide) { - if (auto selection = _desktop->getSelection()) { - for (auto item : selection->items()) { - // We don't hide any image or group that contains an image - // FUTURE: There is a corner case where regular shapes are inside a group - // alongside an image, they should be hidden, but that's much more convoluted. - if (hide && boolean_builder && boolean_builder->contains_image(item)) - continue; - if (auto ditem = item->get_arenaitem(_desktop->dkey)) { - ditem->setOpacity(hide ? 0.0 : SP_SCALE24_TO_FLOAT(item->style->opacity.value)); - } + // Use the stored _items_to_manage list instead of _desktop->getSelection(). + // This is crucial because the selection may have already changed by the time a cleanup/cancel function (like shape_cancel) is called. + for (auto item : _items_to_manage) { + // We don't hide any image or group that contains an image + // FUTURE: There is a corner case where regular shapes are inside a group + // alongside an image, they should be hidden, but that's much more convoluted. + if (hide && boolean_builder && boolean_builder->contains_image(item)) + continue; + if (auto ditem = item->get_arenaitem(_desktop->dkey)) { + ditem->setOpacity(hide ? 0.0 : SP_SCALE24_TO_FLOAT(item->style->opacity.value)); } } } diff --git a/src/ui/tools/booleans-tool.h b/src/ui/tools/booleans-tool.h index fc9da3ef8ce8cc40d1be3731fc73b27c430d81ea..81fb90d85e71b3489b52b32cfb83c2a7565216c8 100644 --- a/src/ui/tools/booleans-tool.h +++ b/src/ui/tools/booleans-tool.h @@ -14,8 +14,10 @@ #define INKSCAPE_UI_TOOLS_BOOLEANS_TOOL_H #include "ui/tools/tool-base.h" +#include class SPDesktop; +class SPItem; namespace Inkscape { class BooleanBuilder; @@ -64,6 +66,8 @@ private: bool to_commit = false; std::optional last_cursor_position; + + std::vector _items_to_manage; // Stores the original items on tool activation. }; } // namespace Tools