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:
parent
ad36fc72f4
commit
8b0f408f34
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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: ""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user