Skip to content

Commit 2f79dd1

Browse files
committed
fix: Prevent losing preserved state on initialization
Add an `isInitial` flag to differentiate between initial and user-triggered tool selection. This prevents unnecessary actions during default tool assignment or preserved tool restoration. Updates ensure proper handling of state transitions with minimal side effects.
1 parent cbe9322 commit 2f79dd1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

web/libs/editor/src/mixins/Tool.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ const ToolMixin = types
7373
},
7474
}))
7575
.actions((self) => ({
76-
setSelected(selected) {
76+
setSelected(selected, isInitial) {
7777
self.selected = selected;
7878
self.afterUpdateSelected();
7979

80-
if (selected && self.obj) {
80+
if (!isInitial && selected && self.obj) {
8181
const storeName = `selected-tool:${self.obj.name}`;
8282

8383
if (self.shouldPreserveSelectedState) {

web/libs/editor/src/tools/Manager.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ class ToolsManager {
7373
if (this.preservedTool && tool.shouldPreserveSelectedState) {
7474
if (tool.fullName === this.preservedTool && tool.setSelected) {
7575
this.unselectAll();
76-
this.selectTool(tool, true);
76+
this.selectTool(tool, true, true);
7777
return;
7878
}
7979
}
8080

8181
if (this._default_tool && !this.hasSelected) {
82-
this.selectTool(this._default_tool, true);
82+
this.selectTool(this._default_tool, true, true);
8383
}
8484
}
8585

@@ -97,7 +97,7 @@ class ToolsManager {
9797
}
9898
}
9999

100-
selectTool(tool, selected) {
100+
selectTool(tool, selected, isInitial = false) {
101101
const currentTool = this.findSelectedTool();
102102
const newSelection = tool?.group;
103103

@@ -122,7 +122,7 @@ class ToolsManager {
122122

123123
if (selected) {
124124
this.unselectAll();
125-
tool.setSelected?.(true);
125+
tool.setSelected?.(true, isInitial);
126126
} else {
127127
const drawingTool = this.findDrawingTool();
128128

0 commit comments

Comments
 (0)