diff --git a/Html/backboardManager.py b/Html/backboardManager.py
index 4b535db..e5b2ab9 100644
--- a/Html/backboardManager.py
+++ b/Html/backboardManager.py
@@ -43,13 +43,22 @@ class Backboard:
f"- File tree: {self.file_tree}{endl}")
# f"- Activated file content (current editing 10 lines): {endl}"
def add_history(self, realtime_action):
- if(realtime_action['type']=='config'):return
- if len(self.history)!=0:
- if (self.history[-1]['type']=='fileEdit'):
- if(self.history[-1]['filePath'] == realtime_action['filePath']):
+ # 检查必要的键是否存在,避免KeyError
+ if realtime_action.get('type') == 'config':
+ return
+ if len(self.history) > 0 and realtime_action.get('type') == 'fileEdit':
+ # 安全地获取filePath,并进行比较
+ current_file_path = realtime_action.get('filePath')
+ # 检查最近的历史记录是否包含filePath
+ if current_file_path and self.history[-1].get('filePath') == current_file_path:
+ # 安全地更新content,只有当content存在时才更新
+ if 'content' in realtime_action:
self.history[-1]['content'] = realtime_action['content']
- return
+ return
self.history.append(realtime_action)
+ # 限制历史记录的数量
+ if len(self.history) > 500: # 假设最多保留500条记录
+ self.history.pop(0) # 移除最旧的记录
def get_deltatime_mmss(self, start_time, end_time):
diff --git a/code-server-like/templates/index.html b/code-server-like/templates/index.html
index a556124..5e7efe7 100644
--- a/code-server-like/templates/index.html
+++ b/code-server-like/templates/index.html
@@ -148,12 +148,14 @@
});
// 防抖处理非粘贴的编辑操作
- const content = changes.text;
+ // 确保始终使用完整的编辑器内容而非仅变更部分
+ const fullContent = editor.getValue();
debounceSendToServer({
type: 'fileEdit',
filePath: filePath,
- content: content,
+ content: fullContent,
config: code_like_config,
+ timestamp: new Date().getTime() // 添加时间戳以便追踪
}, 5000
);
// saveFile