@lvce-editor/editor-worker 16.6.0 → 16.8.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 +44 -6
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -6949,24 +6949,62 @@ 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
|
+
await invoke$c('Main.handleUriChange', uri, filePath);
|
|
6985
|
+
return filePath;
|
|
6986
|
+
};
|
|
6987
|
+
|
|
6962
6988
|
const save = async editor => {
|
|
6963
6989
|
try {
|
|
6964
6990
|
const {
|
|
6991
|
+
platform,
|
|
6965
6992
|
uri
|
|
6966
6993
|
} = editor;
|
|
6967
6994
|
const newEditor = await getNewEditor(editor);
|
|
6968
6995
|
const content = getText$1(newEditor);
|
|
6969
|
-
|
|
6996
|
+
if (isUntitledFile(uri)) {
|
|
6997
|
+
const pickedFilePath = await saveUntitledFile(uri, content, platform);
|
|
6998
|
+
if (pickedFilePath) {
|
|
6999
|
+
return {
|
|
7000
|
+
...newEditor,
|
|
7001
|
+
uri: pickedFilePath
|
|
7002
|
+
};
|
|
7003
|
+
}
|
|
7004
|
+
return newEditor;
|
|
7005
|
+
} else {
|
|
7006
|
+
await saveNormalFile(uri, content);
|
|
7007
|
+
}
|
|
6970
7008
|
return newEditor;
|
|
6971
7009
|
} catch (error) {
|
|
6972
7010
|
// @ts-ignore
|