1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Cross-platform keyboard modifier helpers.
//!
//! Terminal emulators face a fundamental conflict on non-macOS platforms: `Ctrl`
//! is the standard OS-level modifier *and* also generates POSIX control codes
//! inside a terminal (e.g. `Ctrl+C` = SIGINT, `Ctrl+W` = delete-word).
//!
//! par-term resolves this by using different "primary" modifiers per platform:
//!
//! | Platform | Primary modifier | Rationale |
//! |---|---|---|
//! | macOS | `Cmd` (`super_key`) | Separate from Ctrl; no terminal conflicts |
//! | Windows / Linux | `Ctrl` (`control_key`) | macOS `Cmd` key unavailable |
//!
//! When a shortcut needs `Cmd+X` on macOS and `Ctrl+Shift+X` on others (to avoid
//! clobbering Ctrl-only terminal bindings), callers should:
//! 1. Check `primary_modifier(mods)` for the first modifier.
//! 2. Check `primary_modifier_with_shift(mods)` when `Shift` must also be held.
//!
//! This avoids scattered `#[cfg(target_os = "macos")]` pairs at every call site.
use ModifiersState;
/// Returns `true` when **only** the platform's **primary** modifier key is held
/// (no Shift, no Alt, and no cross modifier), i.e.:
///
/// - macOS: `Cmd` pressed; `Shift`, `Alt`, and `Ctrl` not pressed
/// - Windows/Linux: `Ctrl` pressed; `Shift`, `Alt`, and `Super` not pressed
///
/// Use this for single-key shortcuts (`Cmd+T` on macOS / `Ctrl+T` elsewhere).
/// Excluding the cross modifier prevents e.g. `Ctrl+Cmd+T` from triggering a
/// hardcoded `Cmd+T` handler on macOS, which would otherwise shadow any
/// registered `Ctrl+Cmd+T` keybinding.
/// Returns `true` when the platform's **primary** modifier key and **Shift**
/// are held, and no other modifiers are held, i.e.:
///
/// - macOS: `Cmd+Shift`; `Alt` and `Ctrl` not pressed
/// - Windows/Linux: `Ctrl+Shift`; `Alt` and `Super` not pressed
///
/// Use this for shortcuts that require Shift to avoid conflicts
/// (`Cmd+Shift+]` on macOS / `Ctrl+Shift+]` elsewhere). Like
/// [`primary_modifier`], this excludes the cross modifier and Alt so that
/// combos such as `Ctrl+Cmd+Shift+]` do not shadow separate keybindings.