Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.9.0
-
Fedora 42, also on self-built 6.9.0 (using kde-builder)
Description
Consider the following snippet:
import QtQuick import QtQuick.Layouts // import org.kde.kcmutils // import org.kde.kirigami as Kirigami Rectangle { width: 400 height: 400 Shortcut { sequences: [StandardKey.MoveToPreviousPage] onActivated: console.log("I'm a shortcut on PgUp and I was activated.") } Shortcut { sequences: [StandardKey.SelectAll] onActivated: console.log("I'm a shortcut on Ctrl+A and I was activated.") } ColumnLayout { anchors.fill: parent TextEdit { Layout.maximumWidth: parent.width Keys.onShortcutOverride: event => event.accepted = false; // doesn't help wrapMode: TextEdit.Wrap readOnly: true text: "I'm a non-editable TextEdit and I swallow all shortcuts when I have activeFocus." } TextEdit { Layout.maximumWidth: parent.width text: "I'm an editable TextEdit and when I have activeFocus I only swallow shortcuts as defined in QInputControl::isCommonTextEditShortcut()." } TextEdit { Layout.maximumWidth: parent.width wrapMode: TextEdit.Wrap Keys.onShortcutOverride: event => event.accepted = true; // works text: "I'm an editable TextEdit and I swallow all shortcuts when I have activeFocus because I'm configured to do so." } } } // code placeholder
When the second TextEdit is clicked, the first defined Shortcut still gets activated when PgUp is pressed, but the second one is not, as TextEdit handles that shortcut by itself (as one of the common . This seems reasonable.
When the third TextEdit is clicked, neither defined Shortcut works. This is as expected.
But when the first TextEdit is clicked, neither Shortcut works (not even if a custom Keys.onShortcutOverride is set). This seems wrong; a read-only TextEdit having focus should not automatically stop all Shortcuts from triggering.
The problem is that QQuickTextControl's processEvent does not ignore the event if the TextEditable flag is not set, and it is default accepted and requires the handler to explicitly reject it.
A simple solution would be to just accept or reject based on QInputControl::isCommonTextEditShortcut whether the TextEdit is editable or not, or to ignore if it's one of the editing shortcuts defined there (paste, cut, redo. undo) and otherwise use the result of that function, as the other ones make sense in principle for moving the cursor, selecting, or copying in a read-only TextEdit).
I can prepare a patch if you think that is a good approach.
This issue was reported downstream at https://bugs.kde.org/show_bug.cgi?id=497132. Discover uses TextEdits (via Kirigami.SelectableLabel) to display selectable blocks of text, and Shortcuts for Page-wide PgUp/PgDn functionality, which breaks if the user clicks the text.