diff options
3 files changed, 25 insertions, 20 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/BetterSignEditing.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/BetterSignEditing.kt index eb482e0c2..22dfae308 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/BetterSignEditing.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/BetterSignEditing.kt @@ -6,20 +6,18 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.mixins.transformers.AccessorGuiEditSign import at.hannibal2.skyhanni.utils.ClipboardUtils import at.hannibal2.skyhanni.utils.KeyboardManager -import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils import kotlinx.coroutines.launch import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiScreen import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import org.lwjgl.input.Keyboard class BetterSignEditing { private var pasteLastClicked = false private var copyLastClicked = false - private var deleteWordLastClicked = false + private var deleteLastClicked = false @SubscribeEvent fun onTick(event: LorenzTickEvent) { @@ -33,18 +31,20 @@ class BetterSignEditing { } private fun checkDeleting(gui: GuiScreen?) { - val deleteWordClicked = Keyboard.KEY_BACK.isKeyHeld() && KeyboardManager.isModifierKeyDown() - if (!deleteWordLastClicked && deleteWordClicked && gui is AccessorGuiEditSign) { + val deleteClicked = KeyboardManager.isDeleteWordDown() || KeyboardManager.isDeleteLineDown() + if (!deleteLastClicked && deleteClicked && gui is AccessorGuiEditSign) { SkyHanniMod.coroutineScope.launch { - val newLine = if (KeyboardManager.isShiftKeyDown()) "" else { + val newLine = if (KeyboardManager.isDeleteLineDown()) "" + else if (KeyboardManager.isDeleteWordDown()) { val currentLine = gui.tileSign.signText[gui.editLine].unformattedText - val lastSpaceIndex = currentLine.lastIndexOf(' ') - if (lastSpaceIndex >= 0) currentLine.substring(0, lastSpaceIndex + 1) else "" - } + + val lastSpaceIndex = currentLine.trimEnd().lastIndexOf(' ') + if (lastSpaceIndex >= 0) currentLine.substring(0, lastSpaceIndex + 2) else "" + } else return@launch LorenzUtils.setTextIntoSign(newLine, gui.editLine) } } - deleteWordLastClicked = deleteWordClicked + deleteLastClicked = deleteClicked } private fun checkCopying(gui: GuiScreen?) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt index 79d6cc130..387a3e222 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt @@ -486,16 +486,12 @@ open class VisualWordGui : GuiScreen() { if (keyCode == Keyboard.KEY_BACK) { if (currentText.isNotEmpty()) { - currentText = if (KeyboardManager.isModifierKeyDown()) { - "" - } else if (KeyboardManager.isShiftKeyDown()) { - val lastSpaceIndex = currentText.lastIndexOf(' ') - if (lastSpaceIndex >= 0) { - currentText.substring(0, lastSpaceIndex) - } else { - "" - } - } else { + currentText = if (KeyboardManager.isDeleteLineDown()) "" + else if (KeyboardManager.isDeleteWordDown()) { + val lastSpaceIndex = currentText.trimEnd().removeSuffix(" ").lastIndexOf(' ') + if (lastSpaceIndex >= 0) currentText.substring(0, lastSpaceIndex + 1) else "" + } + else { currentText.substring(0, currentText.length - 1) } saveTextChanges() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt b/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt index 6dbd123b4..0c9c29ae9 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt @@ -22,7 +22,16 @@ object KeyboardManager { // A mac-only key, represents Windows key on windows (but different key code) private fun isCommandKeyDown() = Keyboard.KEY_LMETA.isKeyHeld() || Keyboard.KEY_RMETA.isKeyHeld() + + // Windows: Alt key Mac: Option key + private fun isMenuKeyDown() = Keyboard.KEY_LMENU.isKeyHeld() || Keyboard.KEY_RMENU.isKeyHeld() + private fun isControlKeyDown() = Keyboard.KEY_LCONTROL.isKeyHeld() || Keyboard.KEY_RCONTROL.isKeyHeld() + + fun isDeleteWordDown() = Keyboard.KEY_BACK.isKeyHeld() && if (SystemUtils.IS_OS_MAC) isMenuKeyDown() else isControlKeyDown() + + fun isDeleteLineDown() = Keyboard.KEY_BACK.isKeyHeld() && if (SystemUtils.IS_OS_MAC) isCommandKeyDown() else isControlKeyDown() && isShiftKeyDown() + fun isShiftKeyDown() = Keyboard.KEY_LSHIFT.isKeyHeld() || Keyboard.KEY_RSHIFT.isKeyHeld() fun isPastingKeysDown() = isModifierKeyDown() && Keyboard.KEY_V.isKeyHeld() |