Skip to content

Commit 7e981c1

Browse files
committed
增加窗口上传,v1.0
1 parent 3225c04 commit 7e981c1

File tree

5 files changed

+57
-26
lines changed

5 files changed

+57
-26
lines changed

README.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
# qiniu-upload-image
22

3-
一个 VS Code 插件, Markdown 时可以快捷上传本地图片获取七牛图床外链。
3+
一个 VS Code 插件,编写 Markdown 时可以快捷上传本地图片获取七牛图床外链。
44

55
## Features
66

7-
![priview](https://raw.githubusercontent.com/yscoder/vscode-qiniu-upload-image/master/features/preview.gif)
7+
![priview](https://raw.githubusercontent.com/yscoder/vscode-qiniu-upload-image/master/features/demo.gif)
88

9-
> Tips: 只有在编辑 Markdown 时插件才可使用,启动快捷键 `Ctrl+Q`
9+
> Tips: 只有在编辑 Markdown 时插件才可使用。
10+
11+
## Usage
12+
13+
1. 粘贴图片路径上传:`SHIFT + P`
14+
2. 直接选择图片上传:`SHIFT + O`
15+
16+
> 功能2 需要升级 vscode 到 v1.17+
1017
1118
## Install
1219

extension.js

+38-20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@ const { window, commands, workspace } = require('vscode')
22
const path = require('path')
33
const qnUpload = require('./lib/upload')
44

5+
const upload = (config, fsPath) => {
6+
if(!fsPath) return
7+
8+
const editor = window.activeTextEditor
9+
const mdFilePath = editor.document.fileName
10+
const mdFileName = path.basename(mdFilePath, path.extname(mdFilePath))
11+
12+
return qnUpload(config, fsPath, mdFileName).then(({ name, url }) => {
13+
console.log('Upload success!')
14+
15+
const img = `![${name}](${url})`
16+
17+
editor.edit(textEditorEdit => {
18+
textEditorEdit.insert(editor.selection.active, img)
19+
})
20+
})
21+
}
22+
23+
const error = err => {
24+
window.showErrorMessage(err)
25+
}
26+
527
// this method is called when your extension is activated
628
exports.activate = context => {
729

@@ -11,36 +33,32 @@ exports.activate = context => {
1133

1234
if (!config.enable) return
1335

14-
const disposable = commands.registerCommand('extension.qiniu.upload', () => {
36+
const inputUpload = commands.registerCommand('extension.qiniu.upload', () => {
1537

16-
const editor = window.activeTextEditor
17-
const mdFilePath = editor.document.fileName
18-
const mdFileName = path.basename(mdFilePath, path.extname(mdFilePath))
19-
20-
if (!editor) {
38+
if (!window.activeTextEditor) {
2139
window.showErrorMessage('没有打开编辑窗口')
2240
return
2341
}
2442

2543
window.showInputBox({
2644
placeHolder: '输入一个本地图片地址'
27-
}).then(path => qnUpload(config, path, mdFileName)
28-
, err => {
29-
window.showErrorMessage(err)
45+
})
46+
.then(fsPath => upload(config, fsPath), error)
47+
})
48+
49+
const selectUpload = commands.registerCommand('extension.qiniu.select', () => {
50+
window.showOpenDialog({
51+
filters: { 'Images': ['png', 'jpg', 'gif', 'bmp'] }
52+
}).then(result => {
53+
if (result) {
54+
const { fsPath } = result[0]
55+
return upload(config, fsPath)
3056
}
31-
).then(({ name, url }) => {
32-
console.log('Upload success!')
33-
34-
const img = `![${name}](${url})`
35-
editor.edit(textEditorEdit => {
36-
textEditorEdit.insert(editor.selection.active, img)
37-
})
38-
}, err => {
39-
window.showErrorMessage(err)
40-
})
57+
}, error)
4158
})
4259

43-
context.subscriptions.push(disposable)
60+
context.subscriptions.push(inputUpload)
61+
context.subscriptions.push(selectUpload)
4462
}
4563

4664
// this method is called when your extension is deactivated

features/preview.gif

-350 KB
Binary file not shown.

package.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "qiniu-upload-image",
33
"displayName": "qiniu-upload-image",
44
"description": "Picture upload generate markdown link format.",
5-
"version": "0.1.1",
5+
"version": "1.0.0",
66
"publisher": "imys",
77
"engines": {
88
"vscode": "^1.0.0"
@@ -18,8 +18,14 @@
1818
"keybindings": [
1919
{
2020
"command": "extension.qiniu.upload",
21-
"key": "ctrl+q",
22-
"mac": "ctrl+q",
21+
"key": "shift+p",
22+
"mac": "shift+p",
23+
"when": "editorTextFocus && editorLangId == 'markdown'"
24+
},
25+
{
26+
"command": "extension.qiniu.select",
27+
"key": "shift+o",
28+
"mac": "shift+o",
2329
"when": "editorTextFocus && editorLangId == 'markdown'"
2430
}
2531
],

qiniu-upload-image-0.1.1.vsix

-652 KB
Binary file not shown.

0 commit comments

Comments
 (0)