Repository: ManimCommunity/manim
File: manim/mobject/text/text_mobject.py (Python)

Code before:
        self, default_args: dict[str, str]
    ) -> Sequence[TextSetting]:
        settings = []
        args = copy.copy(default_args)
        if self.gradient:
            colors = color_gradient(self.gradient, len(self.text))
            for i in range(len(self.text)):
                args["color"] = colors[i].to_hex()
                settings.append(TextSetting(i, i + 1, **args))

        for word, gradient in self.t2g.items():
            if isinstance(gradient, str) or len(gradient) == 1:
                color = gradient if isinstance(gradient, str) else gradient[0]
                gradient = (ManimColor(color), ManimColor(color))
            colors = (
                color_gradient(gradient, len(word))
                if len(gradient) != 1
                else len(word) * list(gradient)
            )
            for start, end in self._find_indexes(word, self.text):
                for i in range(start, end):
                    args["color"] = colors[i - start].to_hex()
                    settings.append(TextSetting(i, i + 1, **args))
        return settings

    def _text2settings(self, color: ParsableManimColor) -> Sequence[TextSetting]:
        """Converts the texts and styles to a setting for parsing."""
        t2xs: list[tuple[dict[str, str], str]] = [
            (self.t2f, "font"),
            (self.t2s, "slant"),
            (self.t2w, "weight"),
            (self.t2c, "color"),
        ]
        # setting_args requires values to be strings

        default_args: dict[str, Any] = {
            arg: getattr(self, arg) if arg != "color" else color for _, arg in t2xs
        }

        settings = self._get_settings_from_t2xs(t2xs, default_args)
        settings.extend(self._get_settings_from_gradient(default_args))

        # Handle overlaps

        settings.sort(key=lambda setting: setting.start)
        for index, setting in enumerate(settings):
            if index + 1 == len(settings):
                break

            next_setting = settings[index + 1]
            if setting.end > next_setting.start:

Review comment (suggestion):
```suggestion
    def _text2settings(self, color: ParsableManimColor) -> list[TextSetting]:
```

Code after:
        settings = []
        args = copy.copy(default_args)
        if self.gradient:
            colors: list[ManimColor] = color_gradient(self.gradient, len(self.text))
            for i in range(len(self.text)):
                args["color"] = colors[i].to_hex()
                settings.append(TextSetting(i, i + 1, **args))

        for word, gradient in self.t2g.items():
            colors = color_gradient(gradient, len(word))
            for start, end in self._find_indexes(word, self.text):
                for i in range(start, end):
                    args["color"] = colors[i - start].to_hex()
                    settings.append(TextSetting(i, i + 1, **args))
        return settings

    def _text2settings(self, color: ParsableManimColor) -> list[TextSetting]:
        """Converts the texts and styles to a setting for parsing."""
        t2xs: list[tuple[dict[str, str], str]] = [
            (self.t2f, "font"),
            (self.t2s, "slant"),
            (self.t2w, "weight"),
            (self.t2c, "color"),
        ]
        # setting_args requires values to be strings

        default_args: dict[str, Any] = {
            arg: getattr(self, arg) if arg != "color" else color for _, arg in t2xs
        }

        settings = self._get_settings_from_t2xs(t2xs, default_args)
        settings.extend(self._get_settings_from_gradient(default_args))

        # Handle overlaps

        settings.sort(key=lambda setting: setting.start)
        for index, setting in enumerate(settings):
            if index + 1 == len(settings):
                break

            next_setting = settings[index + 1]
            if setting.end > next_setting.start:
                new_setting = self._merge_settings(setting, next_setting, default_args)
                new_index = index + 1
                while (
                    new_index < len(settings)
                    and settings[new_index].start < new_setting.start
                ):
                    new_index += 1
                settings.insert(new_index, new_setting)