Skip to content

Commit

Permalink
fix: preview showing when not supposed to
Browse files Browse the repository at this point in the history
  • Loading branch information
sylviameows committed Oct 29, 2024
1 parent dec84a3 commit 93c4dd2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,19 @@ public HighlightedExpression format(String input, String partial, IntegerRange r
VarItem varItem = VarItems.parse(item);
Component text;

boolean showPreview = false;

switch (varItem.getId()) {
case "num", "var", "txt" -> {
if (Config.getConfig().HighlightExpressions) text = highlightExpressions(input);
if (Config.getConfig().HighlightExpressions) text = highlightExpressions(input, true);
else text = Component.text(input);
}
case "comp" -> {
if (Config.getConfig().HighlightMiniMessage) text = highlighter.highlight(input);
else text = Component.text(input);

showPreview = true;

if (Config.getConfig().HighlightExpressions) text = highlightExpressions(text);
}
default -> {
Expand All @@ -119,7 +123,8 @@ public HighlightedExpression format(String input, String partial, IntegerRange r
}
}

Component preview = formatter.deserialize(input);
Component preview = Component.empty();
if (showPreview) preview = formatter.deserialize(input);

cachedHighlight = new HighlightedExpression(subSequence(componentToOrderedText(text), range), componentToOrderedText(preview));
return cachedHighlight;
Expand Down Expand Up @@ -161,7 +166,7 @@ private HighlightedExpression formatCommand(String input, CommandType command, i

if (Config.getConfig().HighlightExpressions) highlighted = highlightExpressions(highlighted);
} else {
if (Config.getConfig().HighlightExpressions) highlighted = highlightExpressions(input.substring(start,end));
if (Config.getConfig().HighlightExpressions) highlighted = highlightExpressions(input.substring(start,end), true);
else highlighted = Component.text(input.substring(start,end));
}

Expand All @@ -184,10 +189,12 @@ private HighlightedExpression formatCommand(String input, CommandType command, i
private Component highlightExpressions(Component component) {
String raw = formatter.serialize(component);

return highlightExpressions(raw);
return highlightExpressions(raw, false);
}

private Component highlightExpressions(String raw) {
private Component highlightExpressions(String input, boolean escapeTags) {
String raw = escapeTags ? formatter.escapeTags(input) : input;

StringBuilder sb = new StringBuilder(raw.length());

Pattern pattern = Pattern.compile("(%[a-zA-Z]+\\(?)|\\)|$");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.dev.highlighter.ExpressionHighlighter;
import dev.dfonline.codeclient.location.Dev;
import net.kyori.adventure.text.Component;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ChatInputSuggestor;
import net.minecraft.client.gui.widget.TextFieldWidget;
Expand Down Expand Up @@ -39,7 +40,9 @@ private void provideRenderText(String partial, int position, CallbackInfoReturna

if (expression == null) return;

preview = expression.preview();
if (preview != OrderedText.empty()) preview = expression.preview();
else preview = null;

cir.setReturnValue(expression.text());
});
}
Expand Down

0 comments on commit 93c4dd2

Please sign in to comment.