From 79f34e9bb0a45939a57b833d4e4066a034f608e5 Mon Sep 17 00:00:00 2001 From: Jarrio Date: Thu, 28 Aug 2025 11:27:07 +0100 Subject: [PATCH] Move cursor to beginning or end of the line --- runtime/src/ceramic/EditText.hx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/runtime/src/ceramic/EditText.hx b/runtime/src/ceramic/EditText.hx index 57337c3cc..74ff64158 100644 --- a/runtime/src/ceramic/EditText.hx +++ b/runtime/src/ceramic/EditText.hx @@ -601,6 +601,38 @@ class EditText extends Entity implements Component implements TextInputDelegate emitUpdate(newText); }); + keyBindings.bind([KEY(KeyCode.HOME)], function() { + // Home key + if (screen.focusedVisual != entity) + return; + + var current = textInputLineForIndex(selectText.selectionStart); + var pos = textInputIndexForPosInLine(current, 0); + + selectText.selectionStart = pos; + selectText.selectionEnd = pos; + }); + + keyBindings.bind([KEY(KeyCode.END)], function() { + // End key + if (screen.focusedVisual != entity) + return; + + var current = textInputLineForIndex(selectText.selectionStart); + var total = textInputNumberOfLines(); + + var pos = 0; + if (current == total - 1) { + pos = entity.content.length; + } else { + var nextLineStartIndex = textInputIndexForPosInLine(current + 1, 0); + pos = nextLineStartIndex - 1; + } + + selectText.selectionStart = pos; + selectText.selectionEnd = pos; + }); + onDestroy(keyBindings, function(_) { keyBindings.destroy(); keyBindings = null;