Fix: 修复在线版python_pyodide板卡本地文件管理下文件编辑后无法保存
This commit is contained in:
@@ -22,6 +22,7 @@ class WebAccessFSExt extends WebAccessFS {
|
||||
|
||||
export default class FileSystemFS extends FS {
|
||||
#fs_ = null;
|
||||
#encoder_ = new TextEncoder();
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@@ -68,7 +69,8 @@ export default class FileSystemFS extends FS {
|
||||
}
|
||||
|
||||
async writeFile(path, data) {
|
||||
return this.#fs_.writeFile(path, data, 'utf8');
|
||||
const encodedArray = this.#encoder_.encode(data);
|
||||
return this.#fs_.writeFile(path, encodedArray);
|
||||
}
|
||||
|
||||
async isFile(path) {
|
||||
|
||||
@@ -330,10 +330,13 @@ export default class StatusBarFileSystem extends PageBase {
|
||||
this.#fileTree_.showProgress();
|
||||
const id = this.#fileTree_.getSelectedNodeId();
|
||||
const fs = this.#fileTree_.getFS();
|
||||
const [error,] = await fs.writeFile(id, this.#editor_.getValue());
|
||||
this.#fileTree_.hideProgress();
|
||||
if (!error) {
|
||||
try {
|
||||
await fs.writeFile(id, this.#editor_.getValue());
|
||||
this.setStatus(false);
|
||||
} catch (error) {
|
||||
Debug.error(error);
|
||||
} finally {
|
||||
this.#fileTree_.hideProgress();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user