From 90d8ca4c5e019ba815695d1d9162cf0377ae1c27 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Thu, 22 Feb 2024 08:40:36 +0100 Subject: [PATCH 1/2] Do not suppress TypeScript's possible null value warning to avoid a crash of the plugin while destroying the editor rendered inside an iframe element. --- packages/ckeditor5-minimap/src/minimap.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/ckeditor5-minimap/src/minimap.ts b/packages/ckeditor5-minimap/src/minimap.ts index 52afeb2c6e5..911011595f8 100644 --- a/packages/ckeditor5-minimap/src/minimap.ts +++ b/packages/ckeditor5-minimap/src/minimap.ts @@ -205,7 +205,11 @@ export default class Minimap extends Plugin { // The intersection helps to change the tracker height when there is a lot of padding around the root. // Note: It is **essential** that the height is set first because the progress depends on the correct tracker height. - minimapView.setPositionTrackerHeight( scrollableRootAncestorRect.getIntersection( editingRootRect )!.height ); - minimapView.setScrollProgress( scrollProgress ); + const intersection = scrollableRootAncestorRect.getIntersection( editingRootRect ); + + if ( intersection ) { + minimapView.setPositionTrackerHeight( intersection.height ); + minimapView.setScrollProgress( scrollProgress ); + } } } From 6c925dec0bb505f240d7e04d48c31a22c5a3c24b Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Thu, 22 Feb 2024 10:24:43 +0100 Subject: [PATCH 2/2] Do not synchronize the minimap scroll if an editor is not ready. --- packages/ckeditor5-minimap/src/minimap.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/ckeditor5-minimap/src/minimap.ts b/packages/ckeditor5-minimap/src/minimap.ts index 911011595f8..a4eb3d342a4 100644 --- a/packages/ckeditor5-minimap/src/minimap.ts +++ b/packages/ckeditor5-minimap/src/minimap.ts @@ -65,6 +65,8 @@ export default class Minimap extends Plugin { * @inheritDoc */ public override destroy(): void { + super.destroy(); + this._minimapView!.destroy(); this._minimapView!.element!.remove(); } @@ -91,6 +93,10 @@ export default class Minimap extends Plugin { this._initializeMinimapView(); this.listenTo( editor.editing.view, 'render', () => { + if ( editor.state !== 'ready' ) { + return; + } + this._syncMinimapToEditingRootScrollPosition(); } ); @@ -205,11 +211,7 @@ export default class Minimap extends Plugin { // The intersection helps to change the tracker height when there is a lot of padding around the root. // Note: It is **essential** that the height is set first because the progress depends on the correct tracker height. - const intersection = scrollableRootAncestorRect.getIntersection( editingRootRect ); - - if ( intersection ) { - minimapView.setPositionTrackerHeight( intersection.height ); - minimapView.setScrollProgress( scrollProgress ); - } + minimapView.setPositionTrackerHeight( scrollableRootAncestorRect.getIntersection( editingRootRect )!.height ); + minimapView.setScrollProgress( scrollProgress ); } }