-
Notifications
You must be signed in to change notification settings - Fork 350
Communication: Add possibility to add hyperlink to selected text
#11627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 2 commits
97af4d6
44efba6
6bab3c2
ef72343
270a03c
fa39ad6
cbceecc
fc2eef6
63bb85b
d38957e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,20 +22,33 @@ export class UrlAction extends TextEditorAction { | |
|
|
||
| /** | ||
| * Executes the action in the current editor with the given arguments (url and text). | ||
| * @param args The text and url of the URL to insert. If one or both are not provided, the default text will be inserted. | ||
| * @param args The text and url of the URL to insert. If one or both are not provided, checks for selected text to wrap. | ||
| */ | ||
| executeInCurrentEditor(args?: UrlArguments): void { | ||
| super.executeInCurrentEditor(args); | ||
| } | ||
|
|
||
| /** | ||
| * Inserts, at the current selection, the markdown URL with the given text and url if they were provided, or the default text otherwise. | ||
| * Inserts, at the current selection, the markdown URL with the given text and url if they were provided. | ||
| * If no arguments are provided and there is selected text, wraps the selected text with [selectedText](https://). | ||
| * Otherwise, inserts the default text. | ||
| * @param editor The editor in which to insert the URL. | ||
| * @param args The text and url of the URL to insert. If one or both are not provided, the default text will be inserted. | ||
| * @param args The text and url of the URL to insert. If one or both are not provided, checks for selected text to wrap. | ||
| */ | ||
| run(editor: TextEditor, args?: UrlArguments): void { | ||
| if (!args?.text || !args?.url) { | ||
| this.replaceTextAtCurrentSelection(editor, UrlAction.DEFAULT_INSERT_TEXT); | ||
| // Check if there's selected text | ||
| const selectedText = this.getSelectedText(editor); | ||
| if (selectedText && selectedText.trim()) { | ||
| // Wrap selected text with link syntax | ||
| const selection = editor.getSelection(); | ||
| if (selection) { | ||
| this.replaceTextAtRange(editor, selection, `[${sanitizeStringForMarkdownEditor(selectedText)}](https://)`); | ||
| } | ||
| } else { | ||
| // No selection, insert default text | ||
| this.replaceTextAtCurrentSelection(editor, UrlAction.DEFAULT_INSERT_TEXT); | ||
| } | ||
|
||
| } else { | ||
| this.replaceTextAtCurrentSelection(editor, `[${sanitizeStringForMarkdownEditor(args.text)}](${args.url})`); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.