Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Shift+Down/Up Accessibility #24958

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/framework/shortcuts/view/editshortcutmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ void EditShortcutModel::inputKey(Qt::Key key, Qt::KeyboardModifiers modifiers)
return;
}

// remove shift-modifier for keys that don't need it: letters and special keys
if ((modifiers & Qt::ShiftModifier) && ((key < Qt::Key_A) || (key > Qt::Key_Z) || (key >= Qt::Key_Escape))) {
// Remove shift-modifier for non-letter keys, except a few special keys
if ((modifiers & Qt::ShiftModifier)
&& ((key < Qt::Key_A || key > Qt::Key_Z) && checkNotSpecialKey(key) && key > Qt::Key_Escape)) {
modifiers &= ~Qt::ShiftModifier;
}

Expand All @@ -110,6 +111,31 @@ void EditShortcutModel::inputKey(Qt::Key key, Qt::KeyboardModifiers modifiers)
emit newSequenceChanged();
}

bool EditShortcutModel::checkNotSpecialKey(Qt::Key key)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use affirmative names to avoid creating a double negative:

// BAD

if (!checkNotSpecialKey(key)) {
    // special
}

if (checkNotSpecialKey(key)) {
    // not special
}

Also, 'special' is a relative term. You should try to be precise:

// GOOD

if (isShiftAllowed(key)) {
    // allowed
}

if (!isShiftAllowed(key)) {
    // not allowed
}

You should put all the conditions in this function, not just the "specialness".

{
// Few special keys for which the Shift modifier should not be removed
switch (key) {
case Qt::Key_Up:
case Qt::Key_Down:
case Qt::Key_Left:
case Qt::Key_Right:
case Qt::Key_Insert:
case Qt::Key_Delete:
case Qt::Key_Home:
case Qt::Key_End:
case Qt::Key_PageUp:
case Qt::Key_PageDown:
case Qt::Key_Space:
case Qt::Key_Escape:
case Qt::Key_F1: case Qt::Key_F2: case Qt::Key_F3: case Qt::Key_F4:
case Qt::Key_F5: case Qt::Key_F6: case Qt::Key_F7: case Qt::Key_F8:
case Qt::Key_F9: case Qt::Key_F10: case Qt::Key_F11: case Qt::Key_F12:
return false;
default:
return true;
}
}

void EditShortcutModel::checkNewSequenceForConflicts()
{
m_conflictShortcut.clear();
Expand Down
1 change: 1 addition & 0 deletions src/framework/shortcuts/view/editshortcutmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class EditShortcutModel : public QObject, public Injectable
QString originSequenceInNativeFormat() const;
QString newSequenceInNativeFormat() const;
QString conflictWarning() const;
bool checkNotSpecialKey(Qt::Key key);

Q_INVOKABLE void load(const QVariant& shortcut, const QVariantList& allShortcuts);
Q_INVOKABLE void inputKey(Qt::Key key, Qt::KeyboardModifiers modifiers);
Expand Down