undoLastOperation method

void undoLastOperation()

回退:撤销最后一次应用的操作

Implementation

void undoLastOperation() {
  final snapshot = _historyManager.popSnapshot();
  if (snapshot == null) {
    return;
  }

  // 恢复状态
  _image = snapshot.image;
  _currentRotationAngle = snapshot.rotationAngle;
  // 注意:不直接恢复 _scale,因为它是根据图片尺寸和画布尺寸动态计算的
  // 恢复图片后需要重新计算 _scale

  // 恢复文本图层(委托给 TextLayerManager)
  _textLayerManager.restoreLayers(snapshot.textLayers);

  // 清除选择状态
  _cropRect = null;
  _backupCropRect = null;
  _activeTool = EditToolsMenu.none;

  // 恢复图片后,重新计算缩放以适应画布
  // 这是必要的,因为图片尺寸可能已经改变了(裁剪或旋转后)
  if (_canvasSize != null) {
    _initializeImageScale();
  }
  notifyListeners();
}