Skip to content

Commit

Permalink
viliusle#288 - fixed undo on rotated objects
Browse files Browse the repository at this point in the history
  • Loading branch information
viliusle committed Dec 23, 2022
1 parent 59f80c1 commit 92975b2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/js/core/base-selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Base_selection_class {
this.is_touch = false;
// True if dragging from inside canvas area
this.is_drag = false;
this.current_angle = null;

this.events();
}
Expand Down Expand Up @@ -402,6 +403,7 @@ class Base_selection_class {
width: settings.data.width,
height: settings.data.height,
};
this.current_angle = null;
}
if (event_type == 'mousemove' && this.mouse_lock == 'selected_object_actions' && this.is_drag) {

Expand Down Expand Up @@ -439,7 +441,9 @@ class Base_selection_class {
var dy = mouse.y - (y + h / 2);
var angle = Math.atan2(dy, dx) / Math.PI * 180 + original_angle;

settings.data.rotate = angle;
//settings.data.rotate = angle;
this.current_angle = angle;

config.need_render = true;
}
else if (e.buttons == 1 || typeof e.buttons == "undefined") {
Expand Down
26 changes: 26 additions & 0 deletions src/js/tools/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Select_tool_class extends Base_tools_class {
this.moving = false;
this.resizing = false;
this.snap_line_info = {x: null, y: null};
this.rotate_initial = null;

var sel_config = {
enable_background: false,
Expand Down Expand Up @@ -139,6 +140,8 @@ class Select_tool_class extends Base_tools_class {
if (mouse.click_valid == false)
return;

this.rotate_initial = config.layer.rotate;

if (this.Base_selection.mouse_lock != null) {
this.resizing = true;
this.Base_selection.find_settings().keep_ratio = config.layer.type === 'image';
Expand Down Expand Up @@ -169,6 +172,13 @@ class Select_tool_class extends Base_tools_class {
return;
}
if (this.resizing) {

//also handle rotation
let rotate = this.Base_selection.current_angle
if(config.layer.rotate != rotate && rotate !== null){
config.layer.rotate = rotate;
}

return;
}
else if (this.moving) {
Expand Down Expand Up @@ -201,6 +211,8 @@ class Select_tool_class extends Base_tools_class {
let y = config.layer.y;
let width = config.layer.width;
let height = config.layer.height;

//reset values
config.layer.x = this.mousedown_dimensions.x;
config.layer.y = this.mousedown_dimensions.y;
config.layer.width = this.mousedown_dimensions.width;
Expand All @@ -217,6 +229,20 @@ class Select_tool_class extends Base_tools_class {
])
);
}

//also handle rotation
let rotate = this.Base_selection.current_angle;
if(this.rotate_initial != rotate && rotate !== null){
//save state
config.layer.rotate = this.rotate_initial;
app.State.do_action(
new app.Actions.Bundle_action('resize_layer', 'Resize Layer', [
new app.Actions.Update_layer_action(config.layer.id, {
rotate
})
])
);
}
}
else if (this.moving) {
var new_x = Math.round(mouse.x - mouse.click_x + this.mousedown_dimensions.x);
Expand Down

0 comments on commit 92975b2

Please sign in to comment.