Prevented throwing errors unnecessarily in editor plus menu and link toolbar

closes sentry Admin-423

- there may be times when the mousemove event handler fires when the document is not in a ready state resulting in an attempt to get a document position that doesn't exist
- should fix `Could not find parent section from element node` errors
This commit is contained in:
Kevin Ansfield 2022-12-14 10:00:25 +00:00
parent c3487fea41
commit b402b1643e
2 changed files with 16 additions and 9 deletions

View File

@ -131,14 +131,20 @@ export default class KoenigLinkToolbar extends Component {
return;
}
let editor = this.editor;
let x = this._targetRect.x + this._targetRect.width / 2;
let y = this._targetRect.y + this._targetRect.height / 2;
let position = editor.positionAtPoint(x, y);
let linkMarkup = position.marker && position.marker.markups.findBy('tagName', 'a');
if (linkMarkup) {
let linkRange = position.toRange().expandByMarker(marker => !!marker.markups.includes(linkMarkup));
return linkRange;
const editor = this.editor;
const x = this._targetRect.x + this._targetRect.width / 2;
const y = this._targetRect.y + this._targetRect.height / 2;
try {
const position = editor.positionAtPoint(x, y);
const linkMarkup = position.marker && position.marker.markups.findBy('tagName', 'a');
if (linkMarkup) {
const linkRange = position.toRange().expandByMarker(marker => !!marker.markups.includes(linkMarkup));
return linkRange;
}
} catch (e) {
// don't throw because this isn't fatal
console.error(e); // eslint-disable-line
}
}

View File

@ -293,7 +293,8 @@ export default class KoenigPlusMenu extends Component {
// from positionAtPoint(x,y) whilst dragging a selection
// TypeError: Failed to execute 'compareDocumentPosition' on 'Node': parameter 1 is not of type 'Node'.
if (e instanceof TypeError === false) {
throw e;
// don't throw because this isn't fatal
console.error(e); // eslint-disable-line
}
}