This commit is contained in:
CakeCN
2025-11-18 22:42:29 +08:00
parent ede89cef53
commit 5e6e040753
2 changed files with 18 additions and 7 deletions

View File

@@ -43,13 +43,22 @@ class Backboard:
f"- File tree: {self.file_tree}{endl}") f"- File tree: {self.file_tree}{endl}")
# f"- Activated file content (current editing 10 lines): {endl}" # f"- Activated file content (current editing 10 lines): {endl}"
def add_history(self, realtime_action): def add_history(self, realtime_action):
if(realtime_action['type']=='config'):return # 检查必要的键是否存在避免KeyError
if len(self.history)!=0: if realtime_action.get('type') == 'config':
if (self.history[-1]['type']=='fileEdit'): return
if(self.history[-1]['filePath'] == realtime_action['filePath']): 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'] self.history[-1]['content'] = realtime_action['content']
return return
self.history.append(realtime_action) self.history.append(realtime_action)
# 限制历史记录的数量
if len(self.history) > 500: # 假设最多保留500条记录
self.history.pop(0) # 移除最旧的记录
def get_deltatime_mmss(self, start_time, end_time): def get_deltatime_mmss(self, start_time, end_time):

View File

@@ -148,12 +148,14 @@
}); });
// 防抖处理非粘贴的编辑操作 // 防抖处理非粘贴的编辑操作
const content = changes.text; // 确保始终使用完整的编辑器内容而非仅变更部分
const fullContent = editor.getValue();
debounceSendToServer({ debounceSendToServer({
type: 'fileEdit', type: 'fileEdit',
filePath: filePath, filePath: filePath,
content: content, content: fullContent,
config: code_like_config, config: code_like_config,
timestamp: new Date().getTime() // 添加时间戳以便追踪
}, 5000 }, 5000
); );
// saveFile // saveFile