Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: duplicate offset taking into account snap #1283

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/rnote-engine/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,10 @@ impl Engine {
}

pub fn duplicate_selection(&mut self) -> WidgetFlags {
let new_selected = self.store.duplicate_selection();
let new_selected = self.store.duplicate_selection(
self.document.background.pattern_size,
self.document.snap_positions,
);
self.store.update_geometry_for_strokes(&new_selected);
self.current_pen_update_state()
| self.doc_resize_autoexpand()
Expand Down
5 changes: 4 additions & 1 deletion crates/rnote-engine/src/pens/selector/penevents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,10 @@ impl Selector {
KeyboardKey::Unicode('d') => {
//Duplicate selection
if modifier_keys.contains(&ModifierKey::KeyboardCtrl) {
let duplicated = engine_view.store.duplicate_selection();
let duplicated = engine_view.store.duplicate_selection(
engine_view.document.background.pattern_size,
engine_view.document.snap_positions,
);
engine_view.store.update_geometry_for_strokes(&duplicated);
engine_view.store.regenerate_rendering_for_strokes_threaded(
engine_view.tasks_tx.clone(),
Expand Down
16 changes: 13 additions & 3 deletions crates/rnote-engine/src/store/selection_comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ impl StrokeStore {
/// Duplicate the selected keys.
///
/// The returned, duplicated strokes then need to update their geometry and rendering.
pub(crate) fn duplicate_selection(&mut self) -> Vec<StrokeKey> {
pub(crate) fn duplicate_selection(
&mut self,
pattern_size: na::Vector2<f64>,
snap_mode: bool,
) -> Vec<StrokeKey> {
let old_selected = self.selection_keys_as_rendered();
self.set_selected_keys(&old_selected, false);

Expand Down Expand Up @@ -126,8 +130,14 @@ impl StrokeStore {
.collect::<Vec<StrokeKey>>();

// Offsetting the new selected stroke to make the duplication apparent
self.translate_strokes(&new_selected, Stroke::IMPORT_OFFSET_DEFAULT);
self.translate_strokes_images(&new_selected, Stroke::IMPORT_OFFSET_DEFAULT);
// check if snap position is activated or not here
let offset = if snap_mode {
pattern_size
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It often is the case that the selection is not snapped to the grid even when snap_positions is active.
It would be better if the logic does not simply use the grid's size as offset but actively snap the duplicated selection
to the grid when it is active (maybe "default offset" + nearest grid edge?).

} else {
Stroke::IMPORT_OFFSET_DEFAULT
};
self.translate_strokes(&new_selected, offset);
self.translate_strokes_images(&new_selected, offset);

new_selected
}
Expand Down