This commit is contained in:
bflatastic
2026-11-19 01:25:59 +07:00
48 changed files with 2445 additions and 88 deletions
+2
View File
@@ -157,6 +157,8 @@ pub const PREF_SPECS: &[PrefSpec] = &[
p!("scrubNumericFields", "General", "Options", "Scrub Numeric Fields by Dragging", bool),
p!("trackpadRotateView", "General", "Options", "Trackpad Gesture to Rotate View", bool),
p!("holdToolKeys", "General", "Options", "Hold a Tool Shortcut to Use the Tool Temporarily", bool),
p!("holdShortcuts", "General", "Options", "Hold Shortcuts", bool),
p!("keyHoldDelay", "General", "Options", "Hold Shortcut Delay", num(0.2, 1.0, "s")),
p!("boundingBoxWhileMovingAndDrawing", "General", "Options", "Show Bounding Box While Moving and Drawing", bool),
// Selection & Anchor Display
p!("selectionTolerance", "Selection & Anchor Display", "Selection", "Tolerance", num(1.0, 8.0, "px")),
+1 -1
View File
@@ -418,7 +418,7 @@ use history::history_budget_for;
pub use history::{History, HistoryEntry, NamedStep, default_history_budget};
pub(crate) use interaction::PreviewCopies;
pub use interaction::{Interaction, LastTransform, UndoGroup, UndoScope};
pub use prefs::{DrawMode, PluginBudget, Prefs};
pub use prefs::{DrawMode, KEY_HOLD_DELAY, KEY_HOLD_DELAY_RANGE, PluginBudget, Prefs};
pub use sanity::TOO_DEEP;
pub(crate) use sanity::{deselect_hidden, is_guide_path};
#[cfg(test)]
+24
View File
@@ -97,6 +97,13 @@ pub struct Prefs {
/// A single-key tool shortcut held down chooses its tool until the key is let go, and then the
/// tool active before comes back; a quick press chooses the tool for good.
pub hold_tool_keys: bool,
/// Hold shortcuts act (Edit › Keyboard Shortcuts › Hold Shortcuts, off by default): a key with a
/// hold shortcut runs it when held for [`Self::key_hold_delay`], and its own shortcut when let go
/// sooner. Off, every key runs on its press and the dialog shows no Hold column.
pub hold_shortcuts: bool,
/// Seconds a key with a hold shortcut must stay down before the hold shortcut runs (Hold
/// Shortcut Delay, 0.2 to 1.0). VectorCraft's own default, 0.35.
pub key_hold_delay: f64,
/// With View › Show Bounding Box on, the bounding box stays visible while a drag moves the
/// selection, and the shape tools that show it draw it around the shape being drawn. Off (the
/// default), it hides during a move and while a shape is drawn, except that a Selection tool
@@ -420,6 +427,21 @@ pub struct Prefs {
pub import_matches: Vec<cmd::importmatches::ImportMatch>,
}
/// The default Hold Shortcut Delay, in seconds (VectorCraft's own value).
pub const KEY_HOLD_DELAY: f64 = 0.35;
/// The range of the Hold Shortcut Delay, in seconds.
pub const KEY_HOLD_DELAY_RANGE: (f64, f64) = (0.2, 1.0);
impl Prefs {
/// The Hold Shortcut Delay in seconds, inside its range. A restored settings file is not
/// checked against the range, so a value outside it is brought inside, and one that is not a
/// number gives the default.
pub fn key_hold_delay(&self) -> f64 {
let (min, max) = KEY_HOLD_DELAY_RANGE;
if self.key_hold_delay.is_finite() { self.key_hold_delay.clamp(min, max) } else { KEY_HOLD_DELAY }
}
}
impl Default for Prefs {
fn default() -> Self {
let s = |v: &str| v.to_string();
@@ -451,6 +473,8 @@ impl Default for Prefs {
scrub_numeric_fields: true,
trackpad_rotate_view: true,
hold_tool_keys: true,
hold_shortcuts: false,
key_hold_delay: KEY_HOLD_DELAY,
bounding_box_while_moving_and_drawing: false,
paste_offset: 10.0,
selection_tolerance: 3.0,
+21
View File
@@ -176,3 +176,24 @@ fn a_file_over_the_limit_is_refused_before_it_is_parsed() {
assert!(s.execute("prefs.import", &json!({"path": missing.to_string_lossy()})).is_err());
assert_eq!(s.prefs.to_json().to_string(), before);
}
/// Hold Shortcuts is off by default. The Hold Shortcut Delay takes 0.2 to 1.0 s and refuses other
/// values; a value from a settings file outside the range is brought inside it.
#[test]
fn hold_shortcut_preferences() {
let mut s = Session::new();
assert!(!s.prefs.hold_shortcuts);
assert_eq!(s.prefs.key_hold_delay(), 0.35);
for ok in [0.2, 1.0] {
s.execute("prefs.set", &json!({"key": "keyHoldDelay", "value": ok})).unwrap();
assert_eq!(s.prefs.key_hold_delay(), ok);
}
for bad in [0.1, 1.5] {
assert!(is_bad_params(s.execute("prefs.set", &json!({"key": "keyHoldDelay", "value": bad}))), "{bad}");
}
s.execute("prefs.set", &json!({"key": "holdShortcuts", "value": true})).unwrap();
assert!(s.prefs.hold_shortcuts);
let restored: Prefs = serde_json::from_value(json!({"keyHoldDelay": 5.0})).unwrap();
assert_eq!(restored.key_hold_delay(), 1.0);
assert!(!restored.hold_shortcuts);
}