MCPcopy Create free account
hub / github.com/UNLINEARITY/Obsidian-CodeSpace / loadFileContent

Method loadFileContent

src/code_view.ts:1315–1354  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1313 }
1314
1315 async loadFileContent() {
1316 if (!this.file) return;
1317
1318 try {
1319 // 读取文件内容
1320 const content = await this.app.vault.read(this.file);
1321
1322 // 检查内容是否发生变化
1323 const currentContent = this.editorView.state.doc.toString();
1324 if (content === currentContent) {
1325 // 内容一致,不需要重新加载编辑器,从而保留光标位置
1326 // 但仍需更新缓存和状态
1327 this.data = content;
1328 this.isDirty = false;
1329 this.updateTitle();
1330 console.debug("Code Space: File content matches editor content, skipping reload to preserve cursor");
1331 return;
1332 }
1333
1334 // 更新编辑器内容
1335 this.editorView.dispatch({
1336 changes: {
1337 from: 0,
1338 to: this.editorView.state.doc.length,
1339 insert: content
1340 }
1341 });
1342
1343 // 更新缓存的文件内容
1344 this.data = content;
1345
1346 // 清除 dirty 状态(因为内容已经从磁盘重新加载)
1347 this.isDirty = false;
1348 this.updateTitle();
1349
1350 console.debug("Code Space: File content reloaded from disk");
1351 } catch (error) {
1352 console.error("Code Space: Failed to reload file content:", error);
1353 }
1354 }
1355
1356 async onClose(): Promise<void> {
1357 // 视图关闭前自动保存(如果内容已修改)

Callers 1

setupZoomHandlerMethod · 0.95

Calls 1

updateTitleMethod · 0.95

Tested by

no test coverage detected