Skip to content

Commit

Permalink
Merge pull request #108 from telesoho/add_default_selectedText
Browse files Browse the repository at this point in the history
Add default selected text
  • Loading branch information
telesoho authored Mar 1, 2023
2 parents c188ac9 + cb48fb5 commit 05932e6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions src/predefine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 05932e6

Please sign in to comment.