fix:墨迹出现在不对应的PPT文档上

This commit is contained in:
2025-08-23 19:16:19 +08:00
parent 44278d68b4
commit 15082c2c52
2 changed files with 32 additions and 3 deletions
+21 -3
View File
@@ -55,6 +55,13 @@ namespace Ink_Canvas.Helpers
{
try
{
// 完全清理之前的墨迹状态
ClearAllStrokes();
// 重置墨迹锁定状态
_inkLockUntil = DateTime.MinValue;
_lockedSlideIndex = -1;
// 生成演示文稿唯一标识符
_currentPresentationId = GeneratePresentationId(presentation);
@@ -152,17 +159,28 @@ namespace Ink_Canvas.Helpers
{
try
{
// 如果有当前墨迹,先保存
// 如果有当前墨迹,先保存到正确的页面
if (currentStrokes != null && currentStrokes.Count > 0)
{
SaveCurrentSlideStrokes(_lockedSlideIndex > 0 ? _lockedSlideIndex : slideIndex, currentStrokes);
// 确定要保存的页面索引
int saveToSlideIndex = _lockedSlideIndex > 0 ? _lockedSlideIndex : slideIndex;
// 确保页面索引有效
if (saveToSlideIndex > 0 && saveToSlideIndex < _memoryStreams.Length)
{
SaveCurrentSlideStrokes(saveToSlideIndex, currentStrokes);
LogHelper.WriteLogToFile($"已保存第{saveToSlideIndex}页墨迹,墨迹数量: {currentStrokes.Count}", LogHelper.LogType.Trace);
}
}
// 设置墨迹锁定
LockInkForSlide(slideIndex);
// 加载新页面的墨迹
return LoadSlideStrokes(slideIndex);
var newStrokes = LoadSlideStrokes(slideIndex);
LogHelper.WriteLogToFile($"已切换到第{slideIndex}页,加载墨迹数量: {newStrokes.Count}", LogHelper.LogType.Trace);
return newStrokes;
}
catch (Exception ex)
{
+11
View File
@@ -200,6 +200,15 @@ namespace Ink_Canvas
{
Application.Current.Dispatcher.InvokeAsync(() =>
{
// 在初始化墨迹管理器之前,先清理画布上的所有墨迹
ClearStrokes(true);
// 清理备份历史记录,防止旧演示文稿的墨迹影响新演示文稿
if (TimeMachineHistories != null && TimeMachineHistories.Length > 0)
{
TimeMachineHistories[0] = null;
}
// 初始化墨迹管理器
_pptInkManager?.InitializePresentation(pres);
@@ -219,6 +228,8 @@ namespace Ink_Canvas
}
_pptUIManager?.UpdateConnectionStatus(true);
LogHelper.WriteLogToFile($"已打开新演示文稿: {pres.Name},墨迹状态已清理", LogHelper.LogType.Event);
});
}
catch (Exception ex)