Skip to content

Commit

Permalink
Some more tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Jan 4, 2025
1 parent 8b1227e commit 9fe70c3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/main/java/appeng/client/guidebook/Guide.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.minecraft.util.profiling.InactiveProfiler;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -747,4 +748,12 @@ private void registerReloadListener(IEventBus modEventBus) {
new ReloadListener(ResourceLocation.fromNamespaceAndPath(defaultNamespace, folder)));
});
}

public void reloadIfNoPages() {
if (pages == null || pages.isEmpty()) {
var reloader = new ReloadListener(ResourceLocation.fromNamespaceAndPath(defaultNamespace, folder));
pages = reloader.prepare(Minecraft.getInstance().getResourceManager(), InactiveProfiler.INSTANCE);
reloader.apply(pages, Minecraft.getInstance().getResourceManager(), InactiveProfiler.INSTANCE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ private void compileFlowContent(LytFlowParent layoutParent, MdAstAnyContent cont
.replace("\\n", "\n")
.replace("\\", " ")
);
text.modifyStyle(style -> style.whiteSpace(WhiteSpaceMode.PRE));
layoutChild = text;
} else if (content instanceof MdAstInlineCode astCode) {
var text = new LytFlowText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private void iterateRuns(CharSequence text, ResolvedTextStyle style, char lastCh
var fontScale = style.fontScale();
var lineBuffer = new StringBuilder();

boolean lastCharWasWhitespace = Character.isWhitespace(lastChar);
boolean lastCharWasWhitespace = Character.isWhitespace(lastChar) && lastChar != '\n';

for (var i = 0; i < text.length(); i++) {
char ch = text.charAt(i);
Expand Down Expand Up @@ -239,7 +239,7 @@ private void iterateRuns(CharSequence text, ResolvedTextStyle style, char lastCh
// }
}

if (Character.isWhitespace(codePoint)) {
if (Character.isWhitespace(codePoint) && codePoint != '\n') {
// Skip if the last one was a space already
if (lastCharWasWhitespace && style.whiteSpace().isCollapseWhitespace()) {
continue; // White space collapsing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private class Row {
private final NavigationNode node;
private final LytParagraph paragraph = new LytParagraph();
public final LytFlowSpan span;
private boolean expanded;
private boolean expanded = true;
private final Row parent;
private boolean hasChildren;
public int top;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/appeng/core/AppEngClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public HitResult getCurrentMouseOver() {
@Override
public void openGuideAtPreviousPage(ResourceLocation initialPage) {
try {
guide.reloadIfNoPages();
var screen = GuideScreen.openAtPreviousPage(guide, PageAnchor.page(initialPage),
GlobalInMemoryHistory.INSTANCE);

Expand All @@ -159,6 +160,7 @@ public void openGuideAtPreviousPage(ResourceLocation initialPage) {
@Override
public void openGuideAtAnchor(PageAnchor anchor) {
try {
guide.reloadIfNoPages();
var screen = GuideScreen.openNew(guide, anchor, GlobalInMemoryHistory.INSTANCE);

openGuideScreen(screen);
Expand Down

0 comments on commit 9fe70c3

Please sign in to comment.