feat: 更新视图状态管理逻辑,增强跳转功能以支持恢复视图状态并保持缩放比例
This commit is contained in:
parent
01b6ad2051
commit
94dccba404
@ -187,7 +187,7 @@ export function useViewState() {
|
||||
|
||||
// 2. 如果有中心点坐标,创建临时点位并跳转
|
||||
if (viewState.centerX !== 0 || viewState.centerY !== 0) {
|
||||
await jumpToPosition(editor, viewState.centerX, viewState.centerY);
|
||||
await jumpToPosition(editor, viewState.centerX, viewState.centerY, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -204,16 +204,17 @@ export function useViewState() {
|
||||
* @param editor 编辑器服务实例
|
||||
* @param x X坐标
|
||||
* @param y Y坐标
|
||||
* @param isRestoring 是否为恢复视图状态,true时保持当前缩放比例
|
||||
*/
|
||||
const jumpToPosition = async (editor: EditorService, x: number, y: number): Promise<void> => {
|
||||
const jumpToPosition = async (editor: EditorService, x: number, y: number, isRestoring = false): Promise<void> => {
|
||||
try {
|
||||
// 检查是否已存在临时点
|
||||
const existingTempPoints = editor
|
||||
.find('point')
|
||||
.filter((point) => point.id && point.id.includes('view-center-point'));
|
||||
|
||||
// 如果没有临时点,调整缩放比例到8%
|
||||
if (existingTempPoints.length === 0) {
|
||||
// 如果不是恢复状态且没有临时点,调整缩放比例到8%
|
||||
if (!isRestoring && existingTempPoints.length === 0) {
|
||||
editor.scale(0.08);
|
||||
}
|
||||
|
||||
@ -305,17 +306,22 @@ export function useViewState() {
|
||||
const hasExistingState = hasViewState(sceneId, groupId);
|
||||
|
||||
if (!hasExistingState) {
|
||||
// 先让编辑器居中显示,这样可以获得一个合适的默认视图状态
|
||||
// 首次进入:先居中显示获取中心点坐标
|
||||
editor.centerView();
|
||||
|
||||
// 等待一小段时间让centerView完成
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
// 保存当前状态作为默认状态
|
||||
// 获取当前视图状态(主要是为了获取中心点坐标)
|
||||
const currentState = getCurrentViewState(editor);
|
||||
|
||||
// 缩放到8%并跳转到中心点(首次进入的默认行为)
|
||||
await jumpToPosition(editor, currentState.centerX, currentState.centerY, false);
|
||||
|
||||
// 保存当前状态(包含8%缩放和中心点坐标)
|
||||
await saveViewState(editor, sceneId, groupId);
|
||||
|
||||
// 然后恢复这个刚保存的状态(主要是为了触发定位逻辑)
|
||||
return await restoreViewState(editor, sceneId, groupId);
|
||||
return true;
|
||||
} else {
|
||||
// 直接恢复已有状态
|
||||
return await restoreViewState(editor, sceneId, groupId);
|
||||
|
Loading…
x
Reference in New Issue
Block a user