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/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/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", 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; } }