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
//! 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 the platform's **primary** modifier key is held and
/// **Shift** is NOT held, i.e.:
///
/// - macOS: `Cmd` pressed, `Shift` not pressed
/// - Windows/Linux: `Ctrl` pressed, `Shift` not pressed
///
/// Use this for single-key shortcuts (`Cmd+T` on macOS / `Ctrl+T` elsewhere)
/// when the shortcut explicitly avoids Shift.
/// Returns `true` when the platform's **primary** modifier key is held and
/// **Shift is also held**, i.e.:
///
/// - macOS: `Cmd+Shift`
/// - Windows/Linux: `Ctrl+Shift`
///
/// Use this for shortcuts that require Shift to avoid conflicts
/// (`Cmd+Shift+]` on macOS / `Ctrl+Shift+]` elsewhere).