In StringMobject.select_parts, default to using select_unisolated_substring if substring was not explicitly isolated

This commit is contained in:
Grant Sanderson
2022-12-28 13:39:13 -08:00
parent 05f02f5154
commit c7ba775845

View File

@ -36,7 +36,7 @@ class StringMobject(SVGMobject, ABC):
or a 2-tuple containing integers or None, or a collection of the above.
Note, substrings specified cannot *partly* overlap with each other.
Each instance of `StringMobject` generates 2 svg files.
Each instance of `StringMobject` may generate 2 svg files.
The additional one is generated with some color commands inserted,
so that each submobject of the original `SVGMobject` will be labelled
by the color of its paired submobject from the additional `SVGMobject`.
@ -546,15 +546,11 @@ class StringMobject(SVGMobject, ABC):
])
def select_parts(self, selector: Selector) -> VGroup:
indices_list = self.get_submob_indices_lists_by_selector(selector)
if indices_list:
return self.build_parts_from_indices_lists(indices_list)
elif isinstance(selector, str):
# Otherwise, try finding substrings which weren't specifically isolated
log.warning("Accessing unisolated substring, results may not be as expected")
specified_substrings = self.get_specified_substrings()
if isinstance(selector, str) and selector not in specified_substrings:
return self.select_unisolated_substring(selector)
else:
return VGroup()
indices_list = self.get_submob_indices_lists_by_selector(selector)
return self.build_parts_from_indices_lists(indices_list)
def __getitem__(self, value: int | slice | Selector) -> VMobject:
if isinstance(value, (int, slice)):