Koenig - Fixed errors when dragging selection

refs https://github.com/TryGhost/Ghost/issues/9623
- catches and ignores `editor.positionAtPoint` TypeError due to not having a correct node value whilst dragging with a selection
- fixes error thrown from the triple-click handling which expected a value to always be present
This commit is contained in:
Kevin Ansfield 2018-05-17 13:56:37 +01:00
parent cdee31b2fd
commit 5a3acaa967
2 changed files with 14 additions and 5 deletions

View File

@ -566,7 +566,7 @@ export default Component.extend({
// do not include the tail section if it's offset is 0
// fixes triple-click unexpectedly selecting two sections for section-level formatting
// https://github.com/bustle/mobiledoc-kit/issues/597
if (direction === 1 && !isCollapsed && tail.offset === 0) {
if (direction === 1 && !isCollapsed && tail.offset === 0 && tail.section.prev) {
let finalSection = tail.section.prev;
let newRange = new MobiledocRange(head, finalSection.tailPosition());

View File

@ -214,10 +214,19 @@ export default Component.extend({
// grab a range from the editor position under the pointer. We can
// rely on the same show/hide behaviour of our cursor implementation
let position = editor.positionAtPoint(pageX, pageY);
if (position) {
let pointerRange = position.toRange();
this._showOrHideButton(pointerRange);
try {
let position = editor.positionAtPoint(pageX, pageY);
if (position) {
let pointerRange = position.toRange();
this._showOrHideButton(pointerRange);
}
} catch (e) {
// mobiledoc-kit can generate the following harmless error
// 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;
}
}
// if the button is hidden due to the pointer not being over a blank