From 407b15e22ca8298b7760fb190eaeac49a0493921 Mon Sep 17 00:00:00 2001 From: telesoho Date: Wed, 1 Mar 2023 10:35:59 +0800 Subject: [PATCH 1/2] add defaultText parameter for ${selectedText} --- README.md | 2 +- src/predefine.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e87d72c..8c9cdad 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Smartly paste for Markdown. - `${fileExtname}` - the current opened file's extension - `${fileDirname}` - the current opened file's directory name - `${datetime}` - the current date & time formatted by `"yyyyMMDDHHmmss"`, You can customize the format by format string. exp: `${datetime|yyyy-MM-DD_HH-mm-ss}` - - `${selectedText}` - the current selected text. If selected text contain illegal characters `\/:*?""<>|\r\n` it will return "". + - `${selectedText}` - the current selected text. If selected text contain illegal characters `\/:*?""<>|\r\n` it will return "". You can also set the default text, exp: `${selectedText|default text}`, If selected text contain illegal characters or selected text is empty it will return the default text. - `MarkdownPaste.path` diff --git a/src/predefine.ts b/src/predefine.ts index 6fc8c0b..fe6b319 100644 --- a/src/predefine.ts +++ b/src/predefine.ts @@ -95,11 +95,12 @@ class Predefine { /** * Get current selected text. + * @param defaultText * @returns * string: selected text - * "" : if selected text contain illegal characters + * defaultText : if selected text contain illegal characters or empty */ - public selectedText(): string { + public selectedText(defaultText: string = ""): string { const selection = vscode.window.activeTextEditor.selection; const selectText = vscode.window.activeTextEditor.document.getText(selection); @@ -108,8 +109,11 @@ class Predefine { vscode.window.showInformationMessage( "The selected text contains illegal characters that cannot be used as a file name!" ); - return ""; + return defaultText; + } else if (selectText.trim() == "") { + return defaultText; } + return selectText; } } From cb48fb5092f1ff6f92f80b686f1787609f4acc3f Mon Sep 17 00:00:00 2001 From: telesoho Date: Wed, 1 Mar 2023 10:39:12 +0800 Subject: [PATCH 2/2] bump version --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6daef45..81b7569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 0.21.1 (March 1, 2023) + +- fix: add default text for ${selectedText} + ## 0.21.0 (February 28, 2023) - feat: add ${selectedText} predefine diff --git a/package.json b/package.json index 182fc09..b938612 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-markdown-paste-image", "displayName": "Markdown Paste", "description": "A smartly paste for markdown.", - "version": "0.21.0", + "version": "0.21.1", "publisher": "telesoho", "author": { "name": "telesoho",