Skip to content

Commit f4cf8c6

Browse files
committed
🐛 Fix textarea with is incorrect when editing text node
1 parent 93fac9a commit f4cf8c6

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

app/src/core/service/Settings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const settingsSchema = z.object({
2828
limitCameraInCycleSpace: z.boolean().default(false),
2929
cameraCycleSpaceSizeX: z.number().min(1000).max(10000).int().default(1000),
3030
cameraCycleSpaceSizeY: z.number().min(1000).max(10000).int().default(1000),
31-
historySize: z.number().min(1).max(1000).default(20),
31+
historySize: z.number().min(1).max(5000).int().default(150),
3232
autoRefreshStageByMouseAction: z.boolean().default(true),
3333
isPauseRenderWhenManipulateOvertime: z.boolean().default(true),
3434
renderOverTimeWhenNoManipulateTime: z.number().min(1).max(10).int().default(5),

app/src/core/service/controlService/controller/concrete/utilsControl.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ export class ControllerUtils {
7070
const rectWorld = clickedNode.collisionBox.getRectangle();
7171
const rectView = this.project.renderer.transformWorld2View(rectWorld);
7272
ele.style.height = "auto";
73-
ele.style.height = `${rectView.height.toFixed(2)}px`;
73+
ele.style.height = `${rectView.height.toFixed(2) + 8}px`;
7474
// 自动改变宽度
7575
ele.style.width = "auto";
76-
ele.style.width = `${rectView.width.toFixed(2)}px`;
76+
ele.style.width = `${rectView.width.toFixed(2) + 8}px`;
7777
// 自动调整它的外层框的大小
7878
const fatherSections = this.project.sectionMethods.getFatherSectionsList(clickedNode);
7979
for (const section of fatherSections) {

app/src/core/stage/stageManager/StageHistoryManager.tsx

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Project, ProjectState, service } from "@/core/Project";
2+
import { Settings } from "@/core/service/Settings";
23
import { deserialize, serialize } from "@graphif/serializer";
34
import { Delta, diff, patch } from "jsondiffpatch";
45
import _ from "lodash";
@@ -21,10 +22,6 @@ export class HistoryManager {
2122
* 历史记录列表数组上的一个指针
2223
*/
2324
currentIndex = -1;
24-
/**
25-
* 数组最大长度
26-
*/
27-
historySize = 20;
2825
initialStage: Record<string, any>[] = [];
2926

3027
// 在软件启动时调用
@@ -43,16 +40,24 @@ export class HistoryManager {
4340
this.currentIndex++;
4441
const prev = serialize(this.get(this.currentIndex - 1));
4542
const current = serialize(this.project.stage);
46-
const patch = diff(prev, current);
47-
if (!patch) return;
48-
this.deltas.push(patch);
49-
// if (this.deltas.length > this.historySize) {
50-
// // 数组长度超过最大值时,合并第一个和第二个patch
51-
// const second = this.get(1);
52-
// const merged = diff(this.initialStage, second);
53-
// this.deltas.splice(0, 2, merged);
54-
// this.currentIndex--;
55-
// }
43+
const patch_ = diff(prev, current);
44+
if (!patch_) return;
45+
this.deltas.push(patch_);
46+
if (this.deltas.length > Settings.historySize) {
47+
// 当历史记录超过限制时,需要删除最旧的记录
48+
// 但是不能简单删除,因为get方法依赖于从initialStage开始应用所有delta
49+
// 所以我们需要将第一个delta合并到initialStage中,然后删除这个delta
50+
51+
// 步骤1:将第一个delta合并到initialStage中
52+
const firstDelta = _.cloneDeep(this.deltas[0]);
53+
this.initialStage = patch(_.cloneDeep(this.initialStage), firstDelta) as any;
54+
55+
// 步骤2:删除最旧的记录(第一个delta)
56+
this.deltas.shift();
57+
58+
// 步骤3:调整当前索引,因为删除了第一个元素,所有索引都向前移动了一位
59+
this.currentIndex--;
60+
}
5661
this.project.state = ProjectState.Unsaved;
5762
}
5863

@@ -83,6 +88,11 @@ export class HistoryManager {
8388
}
8489

8590
get(index: number) {
91+
// 处理边界情况:如果索引为负数,直接返回初始状态
92+
if (index < 0) {
93+
return deserialize(_.cloneDeep(this.initialStage), this.project);
94+
}
95+
8696
// 先获取从0到index(包含index)的所有patch
8797
const deltas = _.cloneDeep(this.deltas.slice(0, index + 1));
8898
// 从initialStage开始应用patch,得到在index时刻的舞台序列化数据

0 commit comments

Comments
 (0)