You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by da...@apache.org on 2023/03/21 11:37:25 UTC

[daffodil-vscode] branch main updated: fix save over original file (fixes #501)

This is an automated email from the ASF dual-hosted git repository.

davin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-vscode.git


The following commit(s) were added to refs/heads/main by this push:
     new cdbef1e  fix save over original file (fixes #501)
cdbef1e is described below

commit cdbef1ee6b4a5bcc0842801af4d09a296e15fc59
Author: Davin Shearer <22...@users.noreply.github.com>
AuthorDate: Mon Mar 20 10:46:15 2023 -0400

    fix save over original file (fixes #501)
---
 src/omega_edit/dataEditWebView.ts | 72 +++++++++------------------------------
 1 file changed, 17 insertions(+), 55 deletions(-)

diff --git a/src/omega_edit/dataEditWebView.ts b/src/omega_edit/dataEditWebView.ts
index d60adf0..b99e1ba 100644
--- a/src/omega_edit/dataEditWebView.ts
+++ b/src/omega_edit/dataEditWebView.ts
@@ -15,7 +15,14 @@
  * limitations under the License.
  */
 
+import * as omegaEditChange from 'omega-edit/change'
+import { getServerHeartbeat, IServerHeartbeat } from 'omega-edit/server'
+import * as omegaEditSession from 'omega-edit/session'
+import { CountKind } from 'omega-edit/session'
+import * as omegaEditViewport from 'omega-edit/viewport'
 import * as vscode from 'vscode'
+import { EditorMessage, MessageCommand } from '../svelte/src/utilities/message'
+import { serverPort } from './client'
 import { SvelteWebviewInitializer } from './svelteWebviewInitializer'
 import {
   dataToEncodedStr,
@@ -27,13 +34,6 @@ import {
   setViewportDataForPanel,
   viewportSubscribe,
 } from './utils'
-import { EditorMessage, MessageCommand } from '../svelte/src/utilities/message'
-import * as omegaEditSession from 'omega-edit/session'
-import { CountKind } from 'omega-edit/session'
-import * as omegaEditViewport from 'omega-edit/viewport'
-import * as omegaEditChange from 'omega-edit/change'
-import { getServerHeartbeat, IServerHeartbeat } from 'omega-edit/server'
-import { serverPort } from './client'
 
 const VIEWPORT_CAPACITY_MAX = 1000000 // Maximum viewport size in Ωedit is 1048576 (1024 * 1024)
 const HEARTBEAT_INTERVAL_MS = 1000 // 1 second (1000 ms)
@@ -211,36 +211,6 @@ export class DataEditWebView implements vscode.Disposable {
       })
   }
 
-  private async saveSession(sessionId: string, overwrite: boolean) {
-    let filePath = await vscode.window.showInputBox({
-      placeHolder: 'Save session as:',
-    })
-    if (filePath) {
-      let rootPath = vscode.workspace.workspaceFolders
-        ? vscode.workspace.workspaceFolders[0].uri.fsPath
-        : ''
-      if (rootPath !== '' && !filePath.includes(rootPath)) {
-        filePath = `${rootPath}/${filePath}`
-      }
-
-      await omegaEditSession
-        .saveSession(sessionId, filePath, overwrite)
-        .then(() => {
-          vscode.window.showInformationMessage(`Session saved to ${filePath}`)
-        })
-
-      // the session has been cleared after saving if overwrite is true and the change transaction count is 0
-      // this happens if the file is saved to the same location as the original file
-      await omegaEditChange
-        .getChangeTransactionCount(sessionId)
-        .then((count) => {
-          if (count === 0) {
-            vscode.window.showInformationMessage('Session cleared')
-          }
-        })
-    }
-  }
-
   // handle messages from the webview
   private async messageReceiver(message: EditorMessage) {
     switch (message.command) {
@@ -334,25 +304,17 @@ export class DataEditWebView implements vscode.Disposable {
           })
           .then(async (uri) => {
             if (uri && uri.fsPath) {
-              if (uri.path === this.fileToEdit) {
-                await this.saveSession(this.omegaSessionId, true).catch(() => {
-                  vscode.window.showErrorMessage('Failed to save')
+              await omegaEditSession
+                .saveSession(this.omegaSessionId, uri.path, true)
+                .then(async (fp) => {
+                  vscode.window.showInformationMessage(`Saved to file: ${fp}`)
+                  if (fp === this.fileToEdit) {
+                    await this.sendChangesInfo()
+                  }
+                })
+                .catch(() => {
+                  vscode.window.showErrorMessage(`Failed to save: ${uri.path}`)
                 })
-                await this.sendChangesInfo()
-              } else {
-                await omegaEditSession
-                  .saveSession(this.omegaSessionId, uri.path, true)
-                  .then(async () => {
-                    vscode.window.showInformationMessage(
-                      `Saved to file: ${uri.path}`
-                    )
-                  })
-                  .catch(() => {
-                    vscode.window.showErrorMessage(
-                      `Failed to save: ${uri.path}`
-                    )
-                  })
-              }
             }
           })
         break