Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ changelog.txt

# Ignore Minecraft runtime logs
/logs

# ClientDevBridge session state (golden images are intentionally kept)
.clientdevbridge/*
!.clientdevbridge/golden/
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.cyclops.integratedscripting.client.gui.component.input;

import org.lwjgl.glfw.GLFW;

/**
* Platform conventions for moving the cursor in text editors.
* @author rubensworks
*/
public final class EditorKeys {

private EditorKeys() {
}

/**
* @return If the cursor should move or delete by word: Option on macOS, Ctrl elsewhere.
*/
public static boolean isWordModifier(int modifiers, boolean osx) {
return (modifiers & (osx ? GLFW.GLFW_MOD_ALT : GLFW.GLFW_MOD_CONTROL)) != 0;
}

/**
* @return If arrow keys should jump to the line or document start or end, which is Cmd on macOS.
*/
public static boolean isLineModifier(int modifiers, boolean osx) {
return osx && (modifiers & GLFW.GLFW_MOD_SUPER) != 0;
}

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public ContainerScreenTerminalScripting(ContainerTerminalScripting container, In

@Override
public void init() {
// This is called again when the screen is resized, which recreates all widgets
if (textArea != null) {
this.saveCursorPos();
}
pendingScriptRemovalDialog = null;

super.init();

fieldDisk = new WidgetArrowedListField<>(Minecraft.getInstance().font, leftPos + 30,
Expand Down Expand Up @@ -132,6 +138,13 @@ public int getTotalRows() {
buttonCreateFile = new ButtonText(this.leftPos + 19, this.topPos + 222, 56, 10, Component.translatable("gui.integratedscripting.create_file"), Component.literal("+"),
(button) -> getMenu().createNewFile(), true);
addRenderableWidget(buttonCreateFile);

// Restore the open script in the new editor
if (getMenu().getActiveScriptPath() != null) {
this.onActiveScriptSelected();
this.restoreCursorPos();
textArea.ensureCursorVisible();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public TerminalScriptingModifiedScriptPacket(int disk, Path path, String script)
super(ID);
this.disk = disk;
this.path = path.toString();
this.script = Arrays.stream(script.split("\n")).toList();
this.script = Arrays.stream(script.split("\n", -1)).toList();
}

public String getScript() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.cyclops.integratedscripting.client.gui.component.input;

import org.junit.Test;
import org.lwjgl.glfw.GLFW;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
* @author rubensworks
*/
public class EditorKeysTest {

@Test
public void testWordModifierMac() {
assertTrue(EditorKeys.isWordModifier(GLFW.GLFW_MOD_ALT, true));
assertTrue(EditorKeys.isWordModifier(GLFW.GLFW_MOD_ALT | GLFW.GLFW_MOD_SHIFT, true));
assertFalse(EditorKeys.isWordModifier(GLFW.GLFW_MOD_SUPER, true));
assertFalse(EditorKeys.isWordModifier(GLFW.GLFW_MOD_CONTROL, true));
assertFalse(EditorKeys.isWordModifier(0, true));
}

@Test
public void testWordModifierOthers() {
assertTrue(EditorKeys.isWordModifier(GLFW.GLFW_MOD_CONTROL, false));
assertTrue(EditorKeys.isWordModifier(GLFW.GLFW_MOD_CONTROL | GLFW.GLFW_MOD_SHIFT, false));
assertFalse(EditorKeys.isWordModifier(GLFW.GLFW_MOD_ALT, false));
assertFalse(EditorKeys.isWordModifier(0, false));
}

@Test
public void testLineModifier() {
assertTrue(EditorKeys.isLineModifier(GLFW.GLFW_MOD_SUPER, true));
assertTrue(EditorKeys.isLineModifier(GLFW.GLFW_MOD_SUPER | GLFW.GLFW_MOD_SHIFT, true));
assertFalse(EditorKeys.isLineModifier(GLFW.GLFW_MOD_ALT, true));
assertFalse(EditorKeys.isLineModifier(GLFW.GLFW_MOD_SUPER, false));
assertFalse(EditorKeys.isLineModifier(GLFW.GLFW_MOD_CONTROL, false));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.cyclops.integratedscripting.network.packet;

import org.junit.Test;

import java.nio.file.Path;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;

public class TerminalScriptingModifiedScriptPacketTest {

private static String roundTrip(String script) {
return new TerminalScriptingModifiedScriptPacket(0, Path.of("script0.js"), script).getScript();
}

@Test
public void testSingleLine() {
assertThat(roundTrip("const a = 1;"), equalTo("const a = 1;"));
}

@Test
public void testEmpty() {
assertThat(roundTrip(""), equalTo(""));
}

@Test
public void testTrailingNewlines() {
assertThat(roundTrip("const a = 1;\n\n"), equalTo("const a = 1;\n\n"));
}

@Test
public void testOnlyNewlines() {
assertThat(roundTrip("\n\n\n"), equalTo("\n\n\n"));
}

@Test
public void testLeadingAndInnerNewlines() {
assertThat(roundTrip("\na\n\nb"), equalTo("\na\n\nb"));
}

}
Loading