From e12d0c941d3da2684855973c138fcab85b2f79df Mon Sep 17 00:00:00 2001 From: tkaaad97 Date: Sat, 7 May 2022 13:36:18 +0900 Subject: [PATCH] Fix postMessage arguments to efficiently send binary data to webview --- custom-editor-sample/media/pawDraw.js | 6 ++---- custom-editor-sample/package.json | 4 ++-- custom-editor-sample/src/pawDrawEditor.ts | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/custom-editor-sample/media/pawDraw.js b/custom-editor-sample/media/pawDraw.js index 1977b119..11f4633e 100644 --- a/custom-editor-sample/media/pawDraw.js +++ b/custom-editor-sample/media/pawDraw.js @@ -240,16 +240,14 @@ return; } else { // Load the initial image into the canvas. - const data = new Uint8Array(body.value.data); - await editor.reset(data); + await editor.reset(body.value); return; } } case 'update': { - const data = body.content ? new Uint8Array(body.content.data) : undefined; const strokes = body.edits.map(edit => new Stroke(edit.color, edit.stroke)); - await editor.reset(data, strokes) + await editor.reset(body.content, strokes) return; } case 'getFileData': diff --git a/custom-editor-sample/package.json b/custom-editor-sample/package.json index 2070aa94..405da2f4 100644 --- a/custom-editor-sample/package.json +++ b/custom-editor-sample/package.json @@ -11,7 +11,7 @@ "url": "https://github.com/Microsoft/vscode-extension-samples" }, "engines": { - "vscode": "^1.52.0" + "vscode": "^1.65.0" }, "categories": [ "Other" @@ -59,7 +59,7 @@ }, "devDependencies": { "@types/node": "^12.12.0", - "@types/vscode": "^1.52.0", + "@types/vscode": "^1.65.0", "@typescript-eslint/eslint-plugin": "^5.19.0", "@typescript-eslint/parser": "^5.19.0", "eslint": "^8.13.0", diff --git a/custom-editor-sample/src/pawDrawEditor.ts b/custom-editor-sample/src/pawDrawEditor.ts index 37af307a..0f0ab9ef 100644 --- a/custom-editor-sample/src/pawDrawEditor.ts +++ b/custom-editor-sample/src/pawDrawEditor.ts @@ -34,7 +34,7 @@ class PawDrawDocument extends Disposable implements vscode.CustomDocument { if (uri.scheme === 'untitled') { return new Uint8Array(); } - return vscode.workspace.fs.readFile(uri); + return new Uint8Array(await vscode.workspace.fs.readFile(uri)); } private readonly _uri: vscode.Uri;