adventure icon indicating copy to clipboard operation
adventure copied to clipboard

Ability to find and replace across component and its children

Open LOOHP opened this issue 4 years ago • 0 comments

Currently, if you do this:

Component component = Component.text()
    .append(Component.text("Hello! I like ")
    .append(Component.text("App").color(NamedTextColor.AQUA))
    .append(Component.text("les").color(NamedTextColor.YELLOW)).asComponent();
component = component.replaceText(TextReplacementConfig.builder().match("Apples").replacement(Component.text("Bananas").color(NamedTextColor.YELLOW)).build());
System.out.println(GsonComponentSerializer.gson().serialize(component));

This would be the output

{"extra":[{"text":"Hello! I like "},{"color":"aqua","text":"App"},{"color":"yellow","text":"les"}],"text":""}

This is working as intended, tho it makes find and replacing text with different colors/style not possible with api as they must be span across multiple components.

It would be useful if the above code could produce a result like this:

{"extra":[{"text":"Hello! I like "},{"color":"yellow","text":"Bananas"}],"text":""}

LOOHP avatar Jun 04 '21 11:06 LOOHP