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.
This commit is contained in:
miruka 2020-06-23 06:17:52 -04:00
parent ad36fc72f4
commit 8b0f408f34
2 changed files with 13 additions and 1 deletions

View File

@ -83,11 +83,17 @@ TextArea {
onTextChanged: window.saveState(this) onTextChanged: window.saveState(this)
// Prevent alt/super+any key from typing text
Keys.onPressed: if ( Keys.onPressed: if (
event.modifiers & Qt.AltModifier || event.modifiers & Qt.AltModifier ||
event.modifiers & Qt.MetaModifier event.modifiers & Qt.MetaModifier
) event.accepted = true ) 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.priority: KeyNavigation.BeforeItem
KeyNavigation.tab: focusItemOnTab KeyNavigation.tab: focusItemOnTab

View File

@ -58,10 +58,16 @@ TextField {
onActiveFocusChanged: onActiveFocusChanged:
text = activeFocus || changed ? text : Qt.binding(() => defaultText) text = activeFocus || changed ? text : Qt.binding(() => defaultText)
// Prevent alt/super+any key from typing text
Keys.onPressed: if ( Keys.onPressed: if (
event.modifiers & Qt.AltModifier || event.modifiers & Qt.AltModifier ||
event.modifiers & Qt.MetaModifier 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: "" property string saveName: ""