Skip to content

Commit

Permalink
Change link to selection => copy link to selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
nsthorat committed Feb 13, 2024
1 parent 086bc97 commit d7de671
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,19 @@
if (editor.getAction(idLinkSelection) == null) {
editor.addAction({
id: idLinkSelection,
label: '🔗 Link to selection',
label: '🔗 Copy link to selection',
contextMenuGroupId: 'navigation_links',
// We use ctrl/cmd + K to create a link, which is standard for hyperlinks.
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyK],
run: () => {
if (datasetViewStore == null || path == null || field == null || editor == null) return;
if (
datasetViewStore == null ||
path == null ||
field == null ||
editor == null ||
model == null
)
return;
const selection = editor.getSelection();
if (selection == null) return;
Expand All @@ -621,6 +628,12 @@
startCol: selection.startColumn,
endCol: selection.endColumn
});
// Copy the URL to the clipboard after the store is updated.
navigator.clipboard.writeText(location.href).then(null, () => {
throw Error('Error copying URL to clipboard.');
});
editor.setSelection(selection);
}
});
Expand Down

0 comments on commit d7de671

Please # to comment.