@lvce-editor/editor-worker 16.6.0 → 16.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/editorWorkerMain.js +43 -6
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -6949,24 +6949,61 @@ const handleError = async error => {
|
|
|
6949
6949
|
}
|
|
6950
6950
|
};
|
|
6951
6951
|
|
|
6952
|
-
// @ts-ignore
|
|
6953
|
-
// @ts-ignore
|
|
6954
|
-
// @ts-ignore
|
|
6955
|
-
|
|
6956
6952
|
// @ts-ignore
|
|
6957
6953
|
const getNewEditor = async editor => {
|
|
6958
6954
|
return editor;
|
|
6959
6955
|
};
|
|
6960
6956
|
|
|
6961
|
-
|
|
6957
|
+
const isUntitledFile = uri => {
|
|
6958
|
+
return uri.startsWith('untitled:');
|
|
6959
|
+
};
|
|
6960
|
+
|
|
6961
|
+
const saveNormalFile = async (uri, content) => {
|
|
6962
|
+
await invoke$c('FileSystem.writeFile', uri, content);
|
|
6963
|
+
};
|
|
6964
|
+
|
|
6965
|
+
const showFilePicker = async platform => {
|
|
6966
|
+
const dialogTitle = 'Save File'; // TODO use i18n string
|
|
6967
|
+
const {
|
|
6968
|
+
canceled,
|
|
6969
|
+
filePath
|
|
6970
|
+
} = await invoke$b('Open.showSaveDialog', dialogTitle, [], platform);
|
|
6971
|
+
if (canceled) {
|
|
6972
|
+
return '';
|
|
6973
|
+
}
|
|
6974
|
+
return filePath;
|
|
6975
|
+
};
|
|
6976
|
+
|
|
6977
|
+
const saveUntitledFile = async (uri, content, platform) => {
|
|
6978
|
+
const filePath = await showFilePicker(platform);
|
|
6979
|
+
if (!filePath) {
|
|
6980
|
+
return;
|
|
6981
|
+
}
|
|
6982
|
+
await invoke$c('FileSystem.writeFile', filePath, content);
|
|
6983
|
+
await invoke$c('Layout.handleWorkspaceRefresh');
|
|
6984
|
+
return filePath;
|
|
6985
|
+
};
|
|
6986
|
+
|
|
6962
6987
|
const save = async editor => {
|
|
6963
6988
|
try {
|
|
6964
6989
|
const {
|
|
6990
|
+
platform,
|
|
6965
6991
|
uri
|
|
6966
6992
|
} = editor;
|
|
6967
6993
|
const newEditor = await getNewEditor(editor);
|
|
6968
6994
|
const content = getText$1(newEditor);
|
|
6969
|
-
|
|
6995
|
+
if (isUntitledFile(uri)) {
|
|
6996
|
+
const pickedFilePath = await saveUntitledFile(uri, content, platform);
|
|
6997
|
+
if (pickedFilePath) {
|
|
6998
|
+
return {
|
|
6999
|
+
...newEditor,
|
|
7000
|
+
uri: pickedFilePath
|
|
7001
|
+
};
|
|
7002
|
+
}
|
|
7003
|
+
return newEditor;
|
|
7004
|
+
} else {
|
|
7005
|
+
await saveNormalFile(uri, content);
|
|
7006
|
+
}
|
|
6970
7007
|
return newEditor;
|
|
6971
7008
|
} catch (error) {
|
|
6972
7009
|
// @ts-ignore
|