From 8b0f408f341c683ab5e43a1024d7ef8578ccaf9d Mon Sep 17 00:00:00 2001 From: miruka Date: Tue, 23 Jun 2020 06:17:52 -0400 Subject: [PATCH] Fix text field/area leaking arrow presses Prevent leaking arrow presses to parent elements when the carret is at the beginning or end of the text. --- src/gui/Base/HTextArea.qml | 6 ++++++ src/gui/Base/HTextField.qml | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gui/Base/HTextArea.qml b/src/gui/Base/HTextArea.qml index dfa1057a..6b0c83a5 100644 --- a/src/gui/Base/HTextArea.qml +++ b/src/gui/Base/HTextArea.qml @@ -83,11 +83,17 @@ TextArea { onTextChanged: window.saveState(this) + // Prevent alt/super+any key from typing text Keys.onPressed: if ( event.modifiers & Qt.AltModifier || event.modifiers & Qt.MetaModifier ) event.accepted = true + // Prevent leaking arrow presses to parent elements when the carret is at + // the beginning or end of the text + Keys.onLeftPressed: event.accepted = cursorPosition === 0 + Keys.onRightPressed: event.accepted = cursorPosition === length + KeyNavigation.priority: KeyNavigation.BeforeItem KeyNavigation.tab: focusItemOnTab diff --git a/src/gui/Base/HTextField.qml b/src/gui/Base/HTextField.qml index 8f1859c1..b07a3c47 100644 --- a/src/gui/Base/HTextField.qml +++ b/src/gui/Base/HTextField.qml @@ -58,10 +58,16 @@ TextField { onActiveFocusChanged: text = activeFocus || changed ? text : Qt.binding(() => defaultText) + // Prevent alt/super+any key from typing text Keys.onPressed: if ( event.modifiers & Qt.AltModifier || event.modifiers & Qt.MetaModifier - ) event.accepted = true // XXX Still needed? + ) event.accepted = true + + // Prevent leaking arrow presses to parent elements when the carret is at + // the beginning or end of the text + Keys.onLeftPressed: event.accepted = cursorPosition === 0 + Keys.onRightPressed: event.accepted = cursorPosition === length property string saveName: ""