From 489ce51ef90823c12d5a0dbc4f1748995cfa7453 Mon Sep 17 00:00:00 2001 From: cweijan Date: Tue, 5 Mar 2024 14:54:46 +0800 Subject: [PATCH] Support edit in vscode for csv. --- package.json | 2 +- resource/excel/index.js | 9 +++++++-- resource/vditor/icon/vscode.svg | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index c3a9760..fe39f2f 100755 --- a/package.json +++ b/package.json @@ -381,7 +381,7 @@ "priority": "option", "selector": [ { - "filenamePattern": "*.class" + "filenamePattern": "file:/**/*.class" } ] } diff --git a/resource/excel/index.js b/resource/excel/index.js index 935abb6..a0f866d 100644 --- a/resource/excel/index.js +++ b/resource/excel/index.js @@ -33,7 +33,7 @@ function loadSheet(buffer, ext) { const ab = new Uint8Array(buffer).buffer const wb = ext.toLowerCase() == ".csv" ? XLSX.read(new TextDecoder("utf-8").decode(ab), { type: "string", raw: true }) : XLSX.read(ab, { type: "array" }); var { sheets, maxLength, maxCols } = convert(wb); - sheetIns = sheetIns|| x_spreadsheet("#xspreadsheet", { + sheetIns = sheetIns || x_spreadsheet("#xspreadsheet", { row: { len: maxLength + 50, height: 30, @@ -46,6 +46,12 @@ function loadSheet(buffer, ext) { } }) sheetIns.loadData(sheets); + const child = document.querySelector('.x-spreadsheet-toolbar-btns>div:nth-child(3)>.x-spreadsheet-icon'); + child.innerHTML = '' + child.onclick = e => { + handler.emit("editInVSCode", true) + e.stopPropagation(); + } })(); } @@ -54,7 +60,6 @@ vscodeEvent.emit("init") vscodeEvent.on("open", ({ path, ext }) => { extName = ext.replace('.', ''); fetch(path).then(response => response.arrayBuffer()).then(res => { loadSheet(res, ext) }) - console.log(path) }).on("saveDone", () => { notie.alert({ type: 1, text: 'Save Success!' }) }) diff --git a/resource/vditor/icon/vscode.svg b/resource/vditor/icon/vscode.svg index 67aee17..cd1eac6 100644 --- a/resource/vditor/icon/vscode.svg +++ b/resource/vditor/icon/vscode.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file