lua: Fix Sprite.selection when it is not empty but invisible

This commit is contained in:
David Capello 2018-11-21 13:10:21 -03:00
parent 7029e05dc4
commit 5fbba368f0

View File

@ -49,8 +49,22 @@ struct SelectionObj {
Mask* mask(lua_State* L) {
if (maskId)
return check_docobj(L, doc::get<Mask>(maskId));
else
return static_cast<Doc*>(sprite(L)->document())->mask();
else {
auto doc = static_cast<Doc*>(sprite(L)->document());
ASSERT(doc);
// The selection might be invisible but has something (e.g. when
// the user calls "Select > Deselect" option). In this case we
// want to show to the script an empty selection, so we'll clear
// the invisible selection so the script sees it empty.
//
// This breaks the "Select > Reselect" command, but it looks
// like the expected behavior for script authors.
if (!doc->isMaskVisible())
doc->mask()->clear();
return doc->mask();
}
}
Sprite* sprite(lua_State* L) {
if (spriteId)