mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
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:
parent
c3487fea41
commit
b402b1643e
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user