@lvce-editor/editor-worker 16.5.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.
@@ -1299,9 +1299,6 @@ const {
1299
1299
  invoke: invoke$b,
1300
1300
  set: set$a
1301
1301
  } = create$9(rpcId$1);
1302
- const openUrl = async url => {
1303
- return invoke$b('Open.openUrl', url);
1304
- };
1305
1302
 
1306
1303
  const {
1307
1304
  set: set$9
@@ -5533,12 +5530,15 @@ const setPosition$1 = position => {
5533
5530
 
5534
5531
  const openExternal = async (url, platform) => {
5535
5532
  // @ts-ignore
5536
- await openUrl(url);
5533
+ await invoke$b('Open.openUrl', url, platform);
5537
5534
  };
5538
5535
 
5539
5536
  // TODO first change cursor position, then run go to definition
5540
5537
  // cursor should appear at mousedown position immediately
5541
5538
  const handleSingleClickWithAlt = async (editor, position) => {
5539
+ const {
5540
+ platform
5541
+ } = editor;
5542
5542
  const {
5543
5543
  columnIndex,
5544
5544
  rowIndex
@@ -5549,7 +5549,7 @@ const handleSingleClickWithAlt = async (editor, position) => {
5549
5549
  const url = getUrlAtOffset(editor, offset);
5550
5550
  if (url) {
5551
5551
  // Open the link
5552
- await openExternal(url);
5552
+ await openExternal(url, platform);
5553
5553
  return editor;
5554
5554
  }
5555
5555
 
@@ -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
- // @ts-ignore
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
- await invoke$c('FileSystem.writeFile', uri, content);
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "16.5.0",
3
+ "version": "16.7.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"