From 27823e99000093dfa20d6747b68ac69f268f06bb Mon Sep 17 00:00:00 2001 From: Vasu Bhog Date: Fri, 9 Jul 2021 12:01:48 -0400 Subject: [PATCH] Fix CalloutDialog not opening after bad link (#16051) * fix null parentNode --- .../browser/cellViews/markdownToolbar.component.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sql/workbench/contrib/notebook/browser/cellViews/markdownToolbar.component.ts b/src/sql/workbench/contrib/notebook/browser/cellViews/markdownToolbar.component.ts index be40097db6..f2c873a7c5 100644 --- a/src/sql/workbench/contrib/notebook/browser/cellViews/markdownToolbar.component.ts +++ b/src/sql/workbench/contrib/notebook/browser/cellViews/markdownToolbar.component.ts @@ -351,8 +351,12 @@ export class MarkdownToolbarComponent extends AngularDisposable { private getCurrentLinkUrl(): string { if (this.cellModel.currentMode === CellEditModes.WYSIWYG) { - const parentNode = document.getSelection().anchorNode.parentNode as HTMLAnchorElement; - if (parentNode.protocol === 'file:') { + const anchorNode = document.getSelection().anchorNode; + if (!anchorNode) { + return ''; + } + const parentNode = anchorNode.parentNode as HTMLAnchorElement; + if (parentNode?.protocol === 'file:') { // Pathname starts with / per https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/pathname so trim it off return parentNode.pathname?.slice(1) || ''; } else {