summaryrefslogtreecommitdiffstats
path: root/src/keymap.h
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-03 14:08:59 +0200
committerDanilo M. <danix@danix.xyz>2026-08-04 12:53:17 +0200
commit8708139212e4f411509e0c11ed9c04de5cf33a22 (patch)
treef5d0404514ecc4daa7553b726a2c3047b5c690fb /src/keymap.h
parentf76d6c424ca9db357aefb07325a75f2315377c63 (diff)
downloadqtmaildir-8708139212e4f411509e0c11ed9c04de5cf33a22.tar.gz
qtmaildir-8708139212e4f411509e0c11ed9c04de5cf33a22.zip
fix: bind shortcuts users can actually press
Typing a capital emits Shift+<key>, but QKeySequence::fromString() folds the case of a bare letter away: "N" parsed to plain Key_N, a combination no keystroke produces. The N, F and G defaults (toggle_unread, flag and sync) therefore never fired, and neither would any hand-written capital in [keys]. normalizeSequence() rewrites a bare capital to Shift+<letter> and is shared by the defaults and the override pass. As a side effect "y" and "Y" become distinct keys rather than a collision that dropped one. Defaults move to modifier shortcuts throughout. A single letter cannot be a QAction shortcut without stealing that letter from every text field in the window, and the menus in the next commit need real accelerators. defaultBindings() is now the one source of truth for them.
Diffstat (limited to 'src/keymap.h')
-rw-r--r--src/keymap.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/keymap.h b/src/keymap.h
index 564eb10..1c7df5f 100644
--- a/src/keymap.h
+++ b/src/keymap.h
@@ -20,6 +20,8 @@
#include <QHash>
#include <QKeySequence>
+#include <QList>
+#include <QPair>
#include <QStringList>
class QSettings;
@@ -33,6 +35,11 @@ public:
/// anything not in this set, so a typo in the config cannot bind silently.
static QStringList knownActions();
+ /// The built-in bindings, in menu order: {sequence, action}. The single
+ /// source of truth for the defaults, so the menus, the shortcut reference
+ /// and loadDefaults() cannot disagree about them.
+ static QList<QPair<QString, QString>> defaultBindings();
+
void loadDefaults();
/// Reads the [keys] group. Invalid sequences and unknown action names are
@@ -42,6 +49,26 @@ public:
/// Empty string when nothing is bound.
QString actionFor(const QKeySequence &sequence) const;
+ /// The sequence currently bound to an action, empty if none. The reverse
+ /// of actionFor(): menus need a shortcut for an action they already know.
+ /// When several sequences are bound to one action, returns the shortest
+ /// text, so the menu shows a stable choice rather than a hash-order one.
+ QKeySequence sequenceFor(const QString &action) const;
+
+ /// The built-in sequence for an action, ignoring any user override.
+ static QKeySequence defaultSequenceFor(const QString &action);
+
+ /// Every action name carrying a built-in binding.
+ static QStringList defaultActions();
+
+ /// Normalizes a configured key string into the sequence a real keypress
+ /// produces. QKeySequence::fromString() discards the case of a bare
+ /// letter, so "N" parses to plain Key_N, which no keystroke ever emits:
+ /// typing a capital sends Shift+N. A bare uppercase letter is therefore
+ /// rewritten to Shift+<letter>. Returns an empty sequence for input
+ /// fromString() cannot parse.
+ static QKeySequence normalizeSequence(const QString &text);
+
QStringList warnings() const { return m_warnings; }
private: