Make a parsed spacer a value

So a frontend comparing snapshots of the tree sees an unchanged spacer
as unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-25 14:21:51 +00:00
parent 35d6427456
commit d83ba1145b
2 changed files with 11 additions and 14 deletions

View File

@@ -14,15 +14,12 @@ import java.util.regex.Pattern;
*/ */
public final class Spacers { public final class Spacers {
/** Result of parsing a spacer name. */ /**
public static final class Spacer { * A parsed spacer name.
public final char align; // 'l', 'c', 'r', or '*' (repeat/fill) *
public final String caption; * @param align 'l', 'c', 'r', or '*' (repeat the caption to fill)
*/
Spacer(char align, String caption) { public record Spacer(char align, String caption) {
this.align = align;
this.caption = caption;
}
} }
/** The tag's identifying part, which is what keeps two spacers' names apart. */ /** The tag's identifying part, which is what keeps two spacers' names apart. */
@@ -66,18 +63,18 @@ public final class Spacers {
/** Builds the visible label for a spacer at roughly the given character width. */ /** Builds the visible label for a spacer at roughly the given character width. */
public static String render(Spacer s, int width) { public static String render(Spacer s, int width) {
String caption = s.caption == null ? "" : s.caption; String caption = s.caption() == null ? "" : s.caption();
if (s.align == '*') { if (s.align() == '*') {
if (caption.isEmpty()) return ""; if (caption.isEmpty()) return "";
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
while (sb.length() < width) sb.append(caption); while (sb.length() < width) sb.append(caption);
return sb.substring(0, Math.max(caption.length(), Math.min(sb.length(), width))); return sb.substring(0, Math.max(caption.length(), Math.min(sb.length(), width)));
} }
if (s.align == 'c') { if (s.align() == 'c') {
int pad = Math.max(0, (width - caption.length()) / 2); int pad = Math.max(0, (width - caption.length()) / 2);
return " ".repeat(pad) + caption; return " ".repeat(pad) + caption;
} }
if (s.align == 'r') { if (s.align() == 'r') {
int pad = Math.max(0, width - caption.length()); int pad = Math.max(0, width - caption.length());
return " ".repeat(pad) + caption; return " ".repeat(pad) + caption;
} }

View File

@@ -108,7 +108,7 @@ final class ServerTreeSearch implements FindBar.Listener {
if (!searchChannels) return false; if (!searchChannels) return false;
Spacers.Spacer spacer = Spacers.parse(ch.name); Spacers.Spacer spacer = Spacers.parse(ch.name);
if (spacer == null) return query.matches(ch.name); if (spacer == null) return query.matches(ch.name);
return spacer.align != '*' && query.matches(spacer.caption); return spacer.align() != '*' && query.matches(spacer.caption());
} }
return false; return false;
} }