Skip to content

Commit c3be451

Browse files
committed
editor.rs: pan with 'P' and move with arrow keys if selection is empty
Closes #36
1 parent 4f3ad3a commit c3be451

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/editor/tools/panning.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,13 @@ impl PanningToolInner {
11031103
let rotate_action = gio::SimpleAction::new(PanningTool::ROTATE_ACTION, None);
11041104
rotate_action.connect_activate(|_, _| {});
11051105
view.action_group.add_action(&rotate_action);
1106+
let pan_action = gio::SimpleAction::new(PanningTool::PAN_ACTION, None);
1107+
pan_action.connect_activate(glib::clone!(@weak view, @weak obj => move |_, _| {
1108+
obj.imp().mode.set(Mode::Pan);
1109+
obj.set_property::<bool>(PanningTool::ACTIVE, true);
1110+
view.viewport.set_cursor("crosshair");
1111+
}));
1112+
view.action_group.add_action(&pan_action);
11061113
let mut sh = view.shortcuts.borrow_mut();
11071114
sh.push(ShortcutAction::new(
11081115
"move".into(),
@@ -1131,6 +1138,15 @@ impl PanningToolInner {
11311138
}),
11321139
None,
11331140
));
1141+
sh.push(ShortcutAction::new(
1142+
"pan".into(),
1143+
Shortcut::empty().shift().char('P'),
1144+
Box::new(|group| {
1145+
group.activate_action(PanningTool::PAN_ACTION, None);
1146+
true
1147+
}),
1148+
None,
1149+
));
11341150
}
11351151
}
11361152

@@ -1150,6 +1166,7 @@ impl PanningTool {
11501166
pub const MOVE_ACTION: &str = "move.selection";
11511167
pub const SCALE_ACTION: &str = "scale.selection";
11521168
pub const ROTATE_ACTION: &str = "rotate.selection";
1169+
pub const PAN_ACTION: &str = "pan";
11531170

11541171
pub fn new() -> Self {
11551172
glib::Object::new(&[]).unwrap()
@@ -1411,7 +1428,16 @@ impl PanningTool {
14111428
m.translate(-step, 0.0);
14121429
}
14131430
}
1414-
view.state().borrow().transform_selection(m, true);
1431+
let state = view.state().borrow();
1432+
if state.get_selection_set().is_empty() {
1433+
let mut delta: Point = m * Point::from((0.0, 0.0));
1434+
delta.x *= -1.0;
1435+
view.viewport
1436+
.transformation
1437+
.move_camera_by_delta(ViewPoint(delta));
1438+
} else {
1439+
state.transform_selection(m, true);
1440+
}
14151441
view.queue_draw();
14161442
}
14171443

0 commit comments

Comments
 (0)