Unverified Commit bc0bac94 authored by Chris Curry's avatar Chris Curry Committed by GitHub

refactor: enhance hyperlink handling in markdown shortcuts (#4238)

parent 82b5c8ab
...@@ -19,6 +19,14 @@ export const hyperlinkHighlightedText = (editor: EditorRefActions, url?: string) ...@@ -19,6 +19,14 @@ export const hyperlinkHighlightedText = (editor: EditorRefActions, url?: string)
const cursorPosition = editor.getCursorPosition(); const cursorPosition = editor.getCursorPosition();
const selectedContent = editor.getSelectedContent(); const selectedContent = editor.getSelectedContent();
const blankURL = "url"; const blankURL = "url";
// If the selected content looks like a URL and no URL is provided,
// create a link with empty text and the URL
const urlRegex = /^(https?:\/\/[^\s]+)$/;
if (!url && urlRegex.test(selectedContent.trim())) {
editor.insertText(`[](${selectedContent})`);
editor.setCursorPosition(cursorPosition + 1, cursorPosition + 1);
} else {
url = url ?? blankURL; url = url ?? blankURL;
editor.insertText(`[${selectedContent}](${url})`); editor.insertText(`[${selectedContent}](${url})`);
...@@ -27,6 +35,7 @@ export const hyperlinkHighlightedText = (editor: EditorRefActions, url?: string) ...@@ -27,6 +35,7 @@ export const hyperlinkHighlightedText = (editor: EditorRefActions, url?: string)
const newCursorStart = cursorPosition + selectedContent.length + 3; const newCursorStart = cursorPosition + selectedContent.length + 3;
editor.setCursorPosition(newCursorStart, newCursorStart + url.length); editor.setCursorPosition(newCursorStart, newCursorStart + url.length);
} }
}
}; };
const styleHighlightedText = (editor: EditorRefActions, delimiter: string) => { const styleHighlightedText = (editor: EditorRefActions, delimiter: string) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment