mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 17:56:50 -06:00
Merge pull request #2146 from AyberkA0/add-anchor-plus
Shortcuts: + selects the Add Anchor Point tool (#2142)
This commit is contained in:
@@ -15,8 +15,15 @@ pub fn parse(s: &str) -> Option<KeyboardShortcut> {
|
||||
if s.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let (mods_part, key_part) =
|
||||
if let Some(stripped) = s.strip_suffix("++") { (stripped.trim_end_matches('+'), "+") } else { s.rsplit_once('+').unwrap_or(("", s)) };
|
||||
// A bare `+` (the Add Anchor Point tool's key) is the key itself, not a separator with
|
||||
// nothing on either side.
|
||||
let (mods_part, key_part) = if s == "+" {
|
||||
("", "+")
|
||||
} else if let Some(stripped) = s.strip_suffix("++") {
|
||||
(stripped.trim_end_matches('+'), "+")
|
||||
} else {
|
||||
s.rsplit_once('+').unwrap_or(("", s))
|
||||
};
|
||||
let mut m = Modifiers::NONE;
|
||||
for part in mods_part.split('+').filter(|p| !p.is_empty()) {
|
||||
match part {
|
||||
@@ -975,6 +982,23 @@ mod tests {
|
||||
assert!(zoom(&mut app) < before, "Cmd+- zooms out");
|
||||
}
|
||||
|
||||
/// `+` selects the Add Anchor Point tool, as `-` selects Delete Anchor Point (#2142): typed as
|
||||
/// Shift+`=` on a US layout, or by a layout's own `+` key or the numpad's.
|
||||
#[test]
|
||||
fn plus_selects_the_add_anchor_point_tool() {
|
||||
assert_eq!(parse("+"), parse("="), "a bare `+` is the `=` key");
|
||||
assert_eq!(crate::shortcut_editor::tool_for_key("+"), Some("addAnchor"));
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
for m in [Modifiers::SHIFT, Modifiers::NONE] {
|
||||
app.select_tool("selection");
|
||||
frame(&mut app, vec![egui::Event::ModifiersChanged(m), egui::Event::Text("+".into())]);
|
||||
assert_eq!(app.session.tool_id(), "addAnchor", "`+` with {m:?}");
|
||||
}
|
||||
frame(&mut app, vec![egui::Event::ModifiersChanged(Modifiers::NONE), egui::Event::Text("-".into())]);
|
||||
assert_eq!(app.session.tool_id(), "deleteAnchor");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn digit_keys_reach_a_dragging_tool_once_per_press() {
|
||||
use vectorcraft_tools::{PointerEvent, PointerKind};
|
||||
|
||||
Reference in New Issue
Block a user