Skip to content

Commit

Permalink
fix: working on logic from mushanshitiancai
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTowles committed Sep 24, 2022
1 parent 81d04de commit 71dc722
Show file tree
Hide file tree
Showing 9 changed files with 510 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ All the rules are enabled by default. To disable a specific rule, set the rule t

`// TODO GIF`

## VsCode Docs

- <https://code.visualstudio.com/api/references/activation-events>

## Credits

I wanted to make this plugin after issues with markdown image paste [mushan.vscode-paste-image](https://marketplace.visualstudio.com/items?itemName=mushan.vscode-paste-image). After looking for an alternative and finding out that it looked like there were half a [dozen copies](https://marketplace.visualstudio.com/search?term=image%20paste%20markdown&target=VSCode&category=Other&sortBy=Relevance) and most forks and longer maintained.
Expand Down
19 changes: 5 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,9 @@
"vscode": "^1.71.0"
},
"activationEvents": [
"onCommand:test1.helloWorld"
],

"contributes": {
"commands": [
{
"command": "test1.helloWorld",
"title": "Paste Image"
}
]
},
"TODO:activationEvents": [
"onCommand:extension.pasteImage"
],
"TODO:contributes": {
"contributes": {
"configuration": {
"type": "object",
"title": "Paste Image Configuration",
Expand Down Expand Up @@ -160,18 +148,21 @@
"@babel/parser": "^7.18.8",
"@babel/traverse": "^7.18.8",
"@babel/types": "^7.18.8",
"@types/node": "^18.0.3",
"@types/fs-extra": "^9.0.13",
"@types/node": "^18.7.19",
"@types/vscode": "^1.71.0",
"bumpp": "^8.2.1",
"eslint": "^8.19.0",
"esno": "^0.16.3",
"fast-glob": "^3.2.11",
"fs-extra": "^10.1.0",
"htmlparser2": "^7.2.0",
"node-html-parser": "^5.3.3",
"pnpm": "^7.5.1",
"rimraf": "^3.0.2",
"tsup": "^6.1.3",
"typescript": "^4.7.4",
"upath": "^2.0.1",
"vite": "^2.9.14",
"vitest": "^0.18.0",
"vsce": "^2.9.2"
Expand Down
3 changes: 3 additions & 0 deletions playground/test.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Test Markdown

Test file without an image
image.png
asdimage.png

47 changes: 45 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import vscode from 'vscode';
import { log } from './log';
import { Paster } from './paster';
// Selection, TextEditor } from 'vscode';
// import { TextEditorSelectionChangeKind, window, workspace, OutputChannel } from 'vscode';
// import type { AstRoot } from './types'
Expand Down Expand Up @@ -28,24 +30,27 @@ import vscode from 'vscode';
// }

export function activate(context: vscode.ExtensionContext) {
// console.log('Congratulations, your extension "test1" is now active!');
// let last = 0
// let prevEditor: TextEditor | undefined
// let prevSelection: Selection | undefined
// let timer: any

// const config = workspace.getConfiguration('pasteImage')

context.subscriptions.push(log.channel);
log.log('Congratulations, your extension "vscode-markdown-paste-image" is now active!');


let disposable = vscode.commands.registerCommand('test1.helloWorld', () => {
// const config = workspace.getConfiguration('pasteImage')

let disposable = vscode.commands.registerCommand('extension.pasteImage', () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
vscode.window.showInformationMessage('Markdown Image Paste test!');
// log.showInformationMessage('Markdown Image Paste test!');

try {
Paster.paste();
} catch (ex) {
log.showErrorMessage((ex as Error).message);
}
});


context.subscriptions.push(
// Logger.channel,
disposable,

// workspace.onDidChangeTextDocument((e) => {
Expand Down
36 changes: 36 additions & 0 deletions src/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { window } from 'vscode'

export const isDebug = process.env.NODE_ENV === 'development'

export const channel = window.createOutputChannel('Markdown Paste Image')

const padLeft = (nr: number, len = 2, chr = `0`) => `${nr}`.padStart(2, chr);

export const log = {
debug(...args: any[]) {
if (!isDebug)
return
// eslint-disable-next-line no-console
console.log(...args)
this.log(...args)
},

log(...args: any[]) {

var d = new Date();
const timestamp = `${d.getFullYear()}-${padLeft(d.getMonth()+1)}-${padLeft(d.getDate())} ${padLeft(d.getHours())}:${d.getMinutes()}:${padLeft(d.getSeconds())}`;
channel.appendLine(`[${timestamp}] ${args.map(i => String(i)).join(' ')}`)
},


showInformationMessage(message: string, ...items: string[]): Thenable<string | undefined> {
this.log(message);
return window.showInformationMessage(message, ...items);
},

showErrorMessage(message: string, ...items: string[]): Thenable<string | undefined> {
this.log(message);
return window.showErrorMessage(message, ...items);
},
channel: channel
}

0 comments on commit 71dc722

Please sign in to comment.